-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <hi@mxdvl.com> --------- Co-authored-by: Max Duval <hi@mxdvl.com>
- Loading branch information
Showing
28 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.