Skip to content

Commit

Permalink
fixed #692
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarotero committed Dec 17, 2024
1 parent bad1bcd commit 249d314
Show file tree
Hide file tree
Showing 4 changed files with 261 additions and 2,519 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
- New plugin: `json_ld` for generating JSON-LD tags in the output [#453]
- New plugin: `purgecss` to remove unused CSS. [#693]
- New middleware `router`.
- `google_fonts`: Added `subset` option to filter character ranges. [#692]

### Changed
- `lighningcss`: Upload default browser versions:
Expand Down Expand Up @@ -640,6 +641,7 @@ Go to the `v1` branch to see the changelog of Lume 1.
[#685]: https://github.com/lumeland/lume/issues/685
[#686]: https://github.com/lumeland/lume/issues/686
[#689]: https://github.com/lumeland/lume/issues/689
[#692]: https://github.com/lumeland/lume/issues/692
[#693]: https://github.com/lumeland/lume/issues/693
[#704]: https://github.com/lumeland/lume/issues/704

Expand Down
9 changes: 7 additions & 2 deletions plugins/google_fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export interface Options {

/** A placeholder to replace with the generated CSS */
placeholder?: string;

/** The font subsets to download (latin, cyrillic, etc) */
subsets?: string[];
}

export const defaults: Options = {
Expand Down Expand Up @@ -42,7 +45,8 @@ export function googleFonts(userOptions: Options) {

for (const [name, url] of Object.entries(fonts)) {
const css = await readFile(getCssUrl(url));
const fontFaces = extractFontFaces(css, name);
const fontFaces = extractFontFaces(css, name)
.filter((fontFace) => options.subsets?.includes(fontFace.subset) ?? true);

await Promise.all(fontFaces.map(async (fontFace) => {
const content = await read(fontFace.src, true);
Expand Down Expand Up @@ -114,7 +118,8 @@ function extractFontFaces(css: string, name: string): FontFace[] {

function generateCss(fontFaces: FontFace[], fontsFolder: string): string {
return fontFaces.map((fontFace) => {
return `@font-face {
return `/* ${fontFace.subset} */
@font-face {
font-family: '${fontFace.family}';
font-style: ${fontFace.style};
font-weight: ${fontFace.weight};
Expand Down
Loading

0 comments on commit 249d314

Please sign in to comment.