Skip to content

Commit

Permalink
Add asset build process with sharp (#22)
Browse files Browse the repository at this point in the history
* Add asset build process with sharp
* Add .ico of all files
* Add .svg for square

Co-authored-by: Max Duval <hi@mxdvl.com>

---------

Co-authored-by: Max Duval <hi@mxdvl.com>
  • Loading branch information
Que-tin and mxdvl authored Nov 13, 2024
1 parent a85999b commit 6074415
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 0 deletions.
45 changes: 45 additions & 0 deletions assets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env -S deno run -A
// @ts-check

import sharp from "npm:sharp@0.33.5";

// Names of the SVGs to use for generation
const logoFileNames = ["css", "css.square", "css.dark", "css.light"];

// Start the generation process for each logo
for (const logoFileName of logoFileNames) {
// Extract the type of the logo, when the type is not provided it defaults to "primary"
const [logoName, logoType = "primary"] = logoFileName.split(".");

// Load the SVG file into sharp
const image = await sharp(`${logoFileName}.svg`);

// Specify and prepare the output folder
const outputFolder = `./${logoType}`;

// Remove the output folder if it exists
try {
await Deno.remove(outputFolder, { recursive: true });
} catch (error) {
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
}

await Deno.mkdir(outputFolder);

const formats = ["png", "webp", "avif"];

// Generate the different formats for the logo
for (const format of formats) {
const result = image.toFormat(format, {
lossless: true,
});

result.resize(1000, 1000).toFile(`${outputFolder}/${logoName}.${format}`);

if (format === "png") {
result.resize(32, 32).toFile(`${outputFolder}/${logoName}.ico`);
}
}
}
Binary file removed css.2x.png
Binary file not shown.
Binary file removed css.avif
Binary file not shown.
Binary file removed css.dark.2x.png
Binary file not shown.
Binary file removed css.dark.png
Binary file not shown.
Binary file removed css.ico
Binary file not shown.
Binary file removed css.light.2x.png
Binary file not shown.
Binary file removed css.light.png
Binary file not shown.
Binary file removed css.png
Binary file not shown.
Binary file removed css.square.jpg
Binary file not shown.
4 changes: 4 additions & 0 deletions css.square.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed css.webp
Binary file not shown.
Binary file added dark/css.avif
Binary file not shown.
Binary file added dark/css.ico
Binary file not shown.
Binary file added dark/css.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added dark/css.webp
Binary file not shown.
Binary file added light/css.avif
Binary file not shown.
Binary file added light/css.ico
Binary file not shown.
Binary file added light/css.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added light/css.webp
Binary file not shown.
Binary file added primary/css.avif
Binary file not shown.
Binary file added primary/css.ico
Binary file not shown.
Binary file added primary/css.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added primary/css.webp
Binary file not shown.
Binary file added square/css.avif
Binary file not shown.
Binary file added square/css.ico
Binary file not shown.
Binary file added square/css.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added square/css.webp
Binary file not shown.

0 comments on commit 6074415

Please sign in to comment.