From 8d5b13ee03533f72954037608001d5d8b3029d0f Mon Sep 17 00:00:00 2001
From: Stephen Tse <Stephen-X@users.noreply.github.com>
Date: Mon, 28 Apr 2025 21:58:06 +0000
Subject: [PATCH] fix(fonts): Fixed page title fonts not downloadable to local (#1898)
---
quartz/util/theme.ts | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/quartz/util/theme.ts b/quartz/util/theme.ts
index 4a06425..ff4453b 100644
--- a/quartz/util/theme.ts
+++ b/quartz/util/theme.ts
@@ -107,6 +107,13 @@
extension: string
}
+const fontMimeMap: Record<string, string> = {
+ truetype: "ttf",
+ woff: "woff",
+ woff2: "woff2",
+ opentype: "otf",
+}
+
export async function processGoogleFonts(
stylesheet: string,
baseUrl: string,
@@ -114,14 +121,16 @@
processedStylesheet: string
fontFiles: GoogleFontFile[]
}> {
- const fontSourceRegex = /url\((https:\/\/fonts.gstatic.com\/s\/[^)]+\.(woff2|ttf))\)/g
+ const fontSourceRegex =
+ /url\((https:\/\/fonts.gstatic.com\/.+(?:\/|(?:kit=))(.+?)[.&].+?)\)\sformat\('(\w+?)'\);/g
const fontFiles: GoogleFontFile[] = []
let processedStylesheet = stylesheet
let match
while ((match = fontSourceRegex.exec(stylesheet)) !== null) {
const url = match[1]
- const [filename, extension] = url.split("/").pop()!.split(".")
+ const filename = match[2]
+ const extension = fontMimeMap[match[3].toLowerCase()]
const staticUrl = `https://${baseUrl}/static/fonts/${filename}.${extension}`
processedStylesheet = processedStylesheet.replace(url, staticUrl)
--
Gitblit v1.10.0