style: self-host preloaded fonts with font-display optional

Google Fonts loaded async with display=swap, so every first paint showed Georgia and Avenir Next and then visibly switched to the web fonts mid-read.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen 2026-10-25 23:08:54 +08:00
parent b23ca01edd
commit 90e0365d1e
No known key found for this signature in database
GPG key ID: B93DE4F003C33630
4 changed files with 29 additions and 11 deletions

Binary file not shown.

View file

@ -4,6 +4,23 @@
padding: 0;
}
/* optional, not swap: a font that misses first paint stays out for that page view instead of visibly switching mid-read. */
@font-face {
font-family: "Cormorant Garamond";
font-weight: 600;
font-display: optional;
src: url("/static/fonts/cormorant-garamond-600-latin.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
font-family: "Manrope";
font-weight: 400 800;
font-display: optional;
src: url("/static/fonts/manrope-latin.woff2") format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
:root {
color-scheme: light;
--font-display: "Cormorant Garamond", Georgia, serif;

View file

@ -27,19 +27,20 @@
<meta name="twitter:image" content="{{ social_image_url }}" />
<meta name="theme-color" content="#1c1410" />
<link rel="icon" href="/static/favicon.svg" type="image/svg+xml" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@600&family=Manrope:wght@400;600;700;800&display=swap"
rel="stylesheet"
media="print"
onload="this.media = 'all'"
rel="preload"
href="/static/fonts/cormorant-garamond-600-latin.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<link
rel="preload"
href="/static/fonts/manrope-latin.woff2"
as="font"
type="font/woff2"
crossorigin
/>
<noscript
><link
href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@600&family=Manrope:wght@400;600;700;800&display=swap"
rel="stylesheet"
/></noscript>
<link rel="stylesheet" href="/static/style.css" />
<script
async