The Trans Directory
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(fonts): Fixed page title fonts not downloadable to local (#1898)

* Fixed url parser regex not working for Google Fonts subset API

* Prettier no

authored by

Stephen Tse and committed by
GitHub
8d5b13ee 4d07ac93

+11 -2
+11 -2
quartz/util/theme.ts
··· 107 107 extension: string 108 108 } 109 109 110 + const fontMimeMap: Record<string, string> = { 111 + truetype: "ttf", 112 + woff: "woff", 113 + woff2: "woff2", 114 + opentype: "otf", 115 + } 116 + 110 117 export async function processGoogleFonts( 111 118 stylesheet: string, 112 119 baseUrl: string, ··· 114 121 processedStylesheet: string 115 122 fontFiles: GoogleFontFile[] 116 123 }> { 117 - const fontSourceRegex = /url\((https:\/\/fonts.gstatic.com\/s\/[^)]+\.(woff2|ttf))\)/g 124 + const fontSourceRegex = 125 + /url\((https:\/\/fonts.gstatic.com\/.+(?:\/|(?:kit=))(.+?)[.&].+?)\)\sformat\('(\w+?)'\);/g 118 126 const fontFiles: GoogleFontFile[] = [] 119 127 let processedStylesheet = stylesheet 120 128 121 129 let match 122 130 while ((match = fontSourceRegex.exec(stylesheet)) !== null) { 123 131 const url = match[1] 124 - const [filename, extension] = url.split("/").pop()!.split(".") 132 + const filename = match[2] 133 + const extension = fontMimeMap[match[3].toLowerCase()] 125 134 const staticUrl = `https://${baseUrl}/static/fonts/${filename}.${extension}` 126 135 127 136 processedStylesheet = processedStylesheet.replace(url, staticUrl)