Skip to content

Commit

Permalink
Automatic creation of Google font CSS and download of fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmensch committed Jul 24, 2024
1 parent 1e40c3e commit 7fa37a3
Show file tree
Hide file tree
Showing 8 changed files with 613 additions and 3 deletions.
21 changes: 19 additions & 2 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import md from "markdown-it";
import mdFN from "markdown-it-footnote";
import * as sass from "sass";
import path from "node:path";
import { promises as fs } from "node:fs";

import { eleventyImageTransformPlugin } from "@11ty/eleventy-img";
import { InputPathToUrlTransformPlugin } from "@11ty/eleventy";
Expand All @@ -13,6 +14,7 @@ import purgeCssPlugin from "eleventy-plugin-purgecss";

import helpers from "./src/_data/helpers.js";
import siteConfig from "./src/_data/site.js";
import fonts from "./src/_data/fonts.js";

export default async function (eleventyConfig) {
/* 11ty Plugins */
Expand Down Expand Up @@ -80,8 +82,6 @@ export default async function (eleventyConfig) {
/**********************/
eleventyConfig.addPassthroughCopy({
"src/assets/css": "assets/css",
"src/assets/files": "assets/files",
"src/assets/fonts": "assets/fonts",
"src/404.html": "404.html",
});

Expand Down Expand Up @@ -202,6 +202,23 @@ export default async function (eleventyConfig) {
// Where type is one of: words, sentences, paragraphs
eleventyConfig.addFilter("loremIpsum", helpers.loremIpsum);

/* Build event handlers */
/************************/

eleventyConfig.on("eleventy.after",
async () => {
const fontBuffers = await fonts.files();

for (const { fontBuffer, fileName } of fontBuffers) {
const outputPath = path.join('_site', fonts.buildFontPath, fileName);
const outputDir = path.dirname(outputPath);

await fs.mkdir(outputDir, { recursive: true });
await fs.writeFile(outputPath, fontBuffer);
}
}
);

return {
// Set directories to watch
dir: {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
_site/
.cache
.DS_Store
Loading

0 comments on commit 7fa37a3

Please sign in to comment.