Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions plugins/google_fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,24 @@ interface FontFace {
}

function extractFontFaces(css: string, name: string): FontFace[] {
const fontFaces = css.match(/\/\*[^*]+\*\/[\s]+@font-face {[^}]+}/g) || [];
const fontFaces = css.match(/(\/\*[^*]+\*\/)?[\s]+@font-face {[^}]+}/g) || [];

let unnamedSubsetId = 1;
return fontFaces.map((fontFace) => {
const subset = fontFace.match(/\/\* ([^*]+) \*\//)?.[1];
let subset = fontFace.match(/\/\* ([^*]+) \*\//)?.[1];
let family = fontFace.match(/font-family: '([^']+)'/)?.[1];
const style = fontFace.match(/font-style: ([^;]+);/)?.[1];
const weight = fontFace.match(/font-weight: ([^;]+);/)?.[1];
const stretch = fontFace.match(/font-stretch: ([^;]+);/)?.[1];
const src = fontFace.match(/src: url\('?([^']+)'?\)/)?.[1];
const range = fontFace.match(/unicode-range: ([^;]+);/)?.[1];

if (!family || !style || !weight || !src || !range || !subset) {
if (!subset) {
subset = `[${unnamedSubsetId}]`;
unnamedSubsetId++;
}

if (!family || !style || !weight || !src || !range) {
throw new Error("Invalid font-face");
}

Expand Down
Loading