Skip to content

Commit

Permalink
improved google fonts plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Oct 27, 2024
1 parent 4767b68 commit 44021ad
Show file tree
Hide file tree
Showing 2 changed files with 4,536 additions and 5,894 deletions.
19 changes: 13 additions & 6 deletions plugins/google_fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ export function googleFonts(userOptions: Options) {
const options = { ...defaults, ...userOptions } as Required<Options>;

return (site: Site) => {
let cssCode = "";
const cssFile = posix.join("/", options.cssFile);

site.addEventListener("beforeBuild", async () => {
const fonts = typeof options.fonts === "string"
? { "": options.fonts }
: options.fonts;
let cssCode = "";
const cssFile = posix.join("/", options.cssFile);
const relativePath = posix.relative(
posix.dirname(cssFile),
posix.join(options.folder),
Expand All @@ -43,11 +44,17 @@ export function googleFonts(userOptions: Options) {

cssCode += generateCss(fontFaces, relativePath);
}
});

site.page({
content: cssCode,
url: cssFile,
});
site.addEventListener("afterRender", async () => {
// Output the CSS file
const output = await site.getOrCreatePage(cssFile);

if (output.content) {
output.content += `\n${cssCode}`;
} else {
output.content = cssCode;
}
});
};
}
Expand Down
Loading

0 comments on commit 44021ad

Please sign in to comment.