mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-05-18 14:34:23 +02:00
Merge 8c3dad15e03ac3fa7ec504874206f08720a6dd32 into dd6bd498db25344b2cccf56abfb656576a496d38
This commit is contained in:
commit
821e806d66
@ -15,11 +15,19 @@ interface Colors {
|
|||||||
darkMode: ColorScheme
|
darkMode: ColorScheme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface FontInfo {
|
||||||
|
/**
|
||||||
|
* e.g. "ital,wght@0,400;1,200"
|
||||||
|
*/
|
||||||
|
features: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface Theme {
|
export interface Theme {
|
||||||
|
fonts?: Record<string, FontInfo>
|
||||||
typography: {
|
typography: {
|
||||||
header: string
|
header: string | string[]
|
||||||
body: string
|
body: string | string[]
|
||||||
code: string
|
code: string | string[]
|
||||||
}
|
}
|
||||||
cdnCaching: boolean
|
cdnCaching: boolean
|
||||||
colors: Colors
|
colors: Colors
|
||||||
@ -32,9 +40,39 @@ const DEFAULT_SANS_SERIF =
|
|||||||
'-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif'
|
'-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif'
|
||||||
const DEFAULT_MONO = "ui-monospace, SFMono-Regular, SF Mono, Menlo, monospace"
|
const DEFAULT_MONO = "ui-monospace, SFMono-Regular, SF Mono, Menlo, monospace"
|
||||||
|
|
||||||
|
function makeFamilySection(theme: Theme, family: string | string[], defaultFeatures: string) {
|
||||||
|
const families = Array.isArray(family) ? family : [family]
|
||||||
|
return (
|
||||||
|
"family=" +
|
||||||
|
families
|
||||||
|
.map((f) => {
|
||||||
|
const features = theme.fonts?.[f]?.features ?? defaultFeatures
|
||||||
|
if (features === "") {
|
||||||
|
return `${f}:wght@400` // matches unplugin-fonts; should be a sane default
|
||||||
|
} else {
|
||||||
|
return `${f}:${features}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.join("&family=")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function googleFontHref(theme: Theme) {
|
export function googleFontHref(theme: Theme) {
|
||||||
const { code, header, body } = theme.typography
|
const { code, header, body } = theme.typography
|
||||||
return `https://fonts.googleapis.com/css2?family=${code}&family=${header}:wght@400;700&family=${body}:ital,wght@0,400;0,600;1,400;1,600&display=swap`
|
|
||||||
|
const codeSection = makeFamilySection(theme, code, "")
|
||||||
|
const headerSection = makeFamilySection(theme, header, "wght@400;700")
|
||||||
|
const bodySection = makeFamilySection(theme, body, "ital,wght@0,400;0,600;1,400;1,600")
|
||||||
|
|
||||||
|
return `https://fonts.googleapis.com/css2?${codeSection}&${headerSection}&${bodySection}&display=swap`
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderFonts(fonts: string | string[]) {
|
||||||
|
if (Array.isArray(fonts)) {
|
||||||
|
return fonts.map((s) => `"${s}"`).join(", ")
|
||||||
|
} else {
|
||||||
|
return `"${fonts}"`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function joinStyles(theme: Theme, ...stylesheet: string[]) {
|
export function joinStyles(theme: Theme, ...stylesheet: string[]) {
|
||||||
@ -52,9 +90,9 @@ ${stylesheet.join("\n\n")}
|
|||||||
--highlight: ${theme.colors.lightMode.highlight};
|
--highlight: ${theme.colors.lightMode.highlight};
|
||||||
--textHighlight: ${theme.colors.lightMode.textHighlight};
|
--textHighlight: ${theme.colors.lightMode.textHighlight};
|
||||||
|
|
||||||
--headerFont: "${theme.typography.header}", ${DEFAULT_SANS_SERIF};
|
--headerFont: ${renderFonts(theme.typography.header)}, ${DEFAULT_SANS_SERIF};
|
||||||
--bodyFont: "${theme.typography.body}", ${DEFAULT_SANS_SERIF};
|
--bodyFont: ${renderFonts(theme.typography.body)}, ${DEFAULT_SANS_SERIF};
|
||||||
--codeFont: "${theme.typography.code}", ${DEFAULT_MONO};
|
--codeFont: ${renderFonts(theme.typography.code)}, ${DEFAULT_MONO};
|
||||||
}
|
}
|
||||||
|
|
||||||
:root[saved-theme="dark"] {
|
:root[saved-theme="dark"] {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user