Skip to content

Commit 624d73d

Browse files
committed
Embed ArchivoNarrow font into the repo/image/app
Is this enough to get the mythical 100 PageSpeed Insights score?
1 parent a43aaaf commit 624d73d

9 files changed

+58
-5
lines changed
18.2 KB
Binary file not shown.

fonts/ArchivoNarrow-400_latin.woff2

17.6 KB
Binary file not shown.
18.1 KB
Binary file not shown.

fonts/ArchivoNarrow-700_latin.woff2

17.6 KB
Binary file not shown.

fonts/README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
I use Archivo for the website, and Arial for exported SVGs.
44

5-
These files aren't actually served or rendered.
5+
These TTFs aren't actually served or rendered.
66
graphviz uses them to measure text, for box sizing purposes.
77

8+
The WOFF2 files **are** served, to optimize pageload times.
9+
810
## Sources
911

10-
I'm sure there's more legit sources for these fonts...
12+
The WOFF2 files are from Google Fonts. They were grabbed from
13+
[this reference CSS file](https://fonts.googleapis.com/css2?family=Archivo+Narrow:wght@400;700&display=swap).
14+
15+
I'm sure there's more legit sources for these TTFs...
1116
I got these files from these URLs:
1217

1318
* https://github.com/Omnibus-Type/ArchivoNarrow/raw/master/fonts/ttf/ArchivoNarrow-Regular.ttf

lib/request-handling.ts

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ export async function servePublic(req: http.ServerRequest, path: string) {
4545
.catch(makeErrorResponse)
4646
.then(resp => req.respond(resp));
4747
}
48+
export async function serveFont(req: http.ServerRequest, path: string) {
49+
await file_server
50+
.serveFile(req, 'fonts/'+path)
51+
.catch(makeErrorResponse)
52+
.then(resp => req.respond(resp));
53+
}
4854

4955
export function makeErrorResponse(err: Error): http.Response {
5056
if (err.name === 'NotFound') {

partials/global.html

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<meta name="viewport" content="width=device-width, initial-scale=1">
2-
<link rel="preconnect" href="https://fonts.gstatic.com">
3-
<link href="https://fonts.googleapis.com/css2?family=Archivo+Narrow:wght@400;700&display=swap" rel="stylesheet">
42

53
<link rel="stylesheet" href="/global.css">
64
<link rel="icon" href="/icon-deps.png">

public/global.css

+38
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,41 @@ section h2 img {
108108
font-size: 1em;
109109
}
110110
}
111+
112+
/* original URL: https://fonts.googleapis.com/css2?family=Archivo+Narrow:wght@400;700&display=swap */
113+
@font-face {
114+
font-family: 'Archivo Narrow';
115+
font-style: normal;
116+
font-weight: 400;
117+
font-display: swap;
118+
/* latin-ext */
119+
src: url(/fonts/ArchivoNarrow-400_latin-ext.woff2) format('woff2');
120+
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
121+
}
122+
@font-face {
123+
font-family: 'Archivo Narrow';
124+
font-style: normal;
125+
font-weight: 400;
126+
font-display: swap;
127+
/* latin */
128+
src: url(/fonts/ArchivoNarrow-400_latin.woff2) format('woff2');
129+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
130+
}
131+
@font-face {
132+
font-family: 'Archivo Narrow';
133+
font-style: normal;
134+
font-weight: 700;
135+
font-display: swap;
136+
/* latin-ext */
137+
src: url(/fonts/ArchivoNarrow-700_latin-ext.woff2) format('woff2');
138+
unicode-range: U+0100-024F, U+0259, U+1E00-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF;
139+
}
140+
@font-face {
141+
font-family: 'Archivo Narrow';
142+
font-style: normal;
143+
font-weight: 700;
144+
font-display: swap;
145+
/* latin */
146+
src: url(/fonts/ArchivoNarrow-700_latin.woff2) format('woff2');
147+
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
148+
}

server.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env -S deno run --allow-read=. --allow-net=0.0.0.0 --allow-run=deno,dot --allow-env=PORT
22

33
import { http } from "./deps.ts";
4-
import { servePublic, serveTemplatedHtml } from './lib/request-handling.ts';
4+
import { serveFont, servePublic, serveTemplatedHtml } from './lib/request-handling.ts';
55

66
// The different HTTP surfaces we expose
77
import * as DependenciesOf from './feat/dependencies-of/api.ts';
@@ -59,6 +59,12 @@ async function handleReq(req: http.ServerRequest) {
5959
return;
6060
}
6161

62+
if (url.pathname.startsWith('/fonts/') &&
63+
url.pathname.endsWith('.woff2')) {
64+
await serveFont(req, url.pathname.slice(6));
65+
return;
66+
}
67+
6268
await req.respond({
6369
status: 404,
6470
body: '404 Not Found',

0 commit comments

Comments
 (0)