Skip to content

Commit 6074415

Browse files
Que-tinmxdvl
andauthored
Add asset build process with sharp (#22)
* Add asset build process with sharp * Add .ico of all files * Add .svg for square Co-authored-by: Max Duval <[email protected]> --------- Co-authored-by: Max Duval <[email protected]>
1 parent a85999b commit 6074415

28 files changed

+49
-0
lines changed

assets.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env -S deno run -A
2+
// @ts-check
3+
4+
import sharp from "npm:[email protected]";
5+
6+
// Names of the SVGs to use for generation
7+
const logoFileNames = ["css", "css.square", "css.dark", "css.light"];
8+
9+
// Start the generation process for each logo
10+
for (const logoFileName of logoFileNames) {
11+
// Extract the type of the logo, when the type is not provided it defaults to "primary"
12+
const [logoName, logoType = "primary"] = logoFileName.split(".");
13+
14+
// Load the SVG file into sharp
15+
const image = await sharp(`${logoFileName}.svg`);
16+
17+
// Specify and prepare the output folder
18+
const outputFolder = `./${logoType}`;
19+
20+
// Remove the output folder if it exists
21+
try {
22+
await Deno.remove(outputFolder, { recursive: true });
23+
} catch (error) {
24+
if (!(error instanceof Deno.errors.NotFound)) {
25+
throw error;
26+
}
27+
}
28+
29+
await Deno.mkdir(outputFolder);
30+
31+
const formats = ["png", "webp", "avif"];
32+
33+
// Generate the different formats for the logo
34+
for (const format of formats) {
35+
const result = image.toFormat(format, {
36+
lossless: true,
37+
});
38+
39+
result.resize(1000, 1000).toFile(`${outputFolder}/${logoName}.${format}`);
40+
41+
if (format === "png") {
42+
result.resize(32, 32).toFile(`${outputFolder}/${logoName}.ico`);
43+
}
44+
}
45+
}

css.2x.png

-56.8 KB
Binary file not shown.

css.avif

-4.94 KB
Binary file not shown.

css.dark.2x.png

-50.3 KB
Binary file not shown.

css.dark.png

-22.3 KB
Binary file not shown.

css.ico

-4.19 KB
Binary file not shown.

css.light.2x.png

-49.7 KB
Binary file not shown.

css.light.png

-21.7 KB
Binary file not shown.

css.png

-25.5 KB
Binary file not shown.

css.square.jpg

-104 KB
Binary file not shown.

0 commit comments

Comments
 (0)