add subsetting
This commit is contained in:
59
src/build.js
Normal file
59
src/build.js
Normal file
@ -0,0 +1,59 @@
|
||||
import { copyFile, mkdir, readFile, writeFile } from 'fs/promises'
|
||||
import subsetFont from 'subset-font'
|
||||
import { JSDOM } from 'jsdom'
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
let html = await readFile('src/index.html', 'utf8');
|
||||
const dom = new JSDOM(html);
|
||||
const doc = dom.window.document;
|
||||
|
||||
const fonts = {
|
||||
merriweather: {
|
||||
font: 'merriweather-v27-latin',
|
||||
weights: {
|
||||
900: () => doc.querySelector('h1').firstChild.textContent,
|
||||
300: '[role="doc-subtitle"]',
|
||||
400: 'h2'
|
||||
}
|
||||
},
|
||||
inter: {
|
||||
font: 'inter-v7-latin',
|
||||
weights: {
|
||||
400: '.box',
|
||||
700: '.box b'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await mkdir('dist/static', { recursive: true });
|
||||
|
||||
for (const [name, f] of Object.entries(fonts)) {
|
||||
for (const [weight, selector] of Object.entries(f.weights)) {
|
||||
const path = `assets/${f.font}-${weight}.woff2`;
|
||||
const words = typeof selector === 'string' ? Array.from(doc.querySelectorAll(selector)).map(x => x.textContent).join(' ') : selector();
|
||||
|
||||
const subset = await subsetFont(await readFile(path), words, { targetFormat: 'woff2' });
|
||||
const hash = makeHash(subset);
|
||||
|
||||
const outName = `static/${name}-${weight}.${hash}.woff2`;
|
||||
|
||||
html = html.replace(`FONT_${name}_${weight}`, outName);
|
||||
await writeFile('dist/' + outName, subset);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const laputa = await readFile('assets/laputa.webp');
|
||||
const outName = `static/laputa.${makeHash(laputa)}.webp`;
|
||||
await writeFile('dist/' + outName, laputa);
|
||||
html = html.replace('LAPUTA', outName);
|
||||
}
|
||||
|
||||
await writeFile('dist/index.html', html);
|
||||
await copyFile('src/favicon.ico', 'dist/favicon.ico');
|
||||
|
||||
function makeHash(input) {
|
||||
const hash = createHash('sha256');
|
||||
hash.update(input);
|
||||
return hash.digest('hex').substring(0, 8);
|
||||
}
|
BIN
src/favicon.ico
Normal file
BIN
src/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
224
src/index.html
Normal file
224
src/index.html
Normal file
@ -0,0 +1,224 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Adam Burgess</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
background-image: url(LAPUTA);
|
||||
/* todo: revist image-set */
|
||||
background-position-x: center;
|
||||
background-size: cover;
|
||||
|
||||
color: white;
|
||||
margin-top: 2em;
|
||||
|
||||
font-family: Inter, sans-serif;
|
||||
font-size: 14px;
|
||||
|
||||
text-shadow: 0px 2px 2px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
::selection {
|
||||
background-color: rgba(40, 122, 195, 0.65);
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
body, h1, h2, h3, p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1, h2, [role="doc-subtitle"], h3 {
|
||||
font-family: Merriweather, serif;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-family: sans-serif;
|
||||
font-weight: 400;
|
||||
font-size: 18px;
|
||||
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: 900;
|
||||
font-size: 96px;
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
[role="doc-subtitle"] {
|
||||
font-weight: 300;
|
||||
font-size: 36px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-weight: 400;
|
||||
font-size: 24px;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.box {
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
backdrop-filter: blur(6px);
|
||||
border-radius: 6px;
|
||||
|
||||
padding: 8px;
|
||||
|
||||
margin-left: -8px;
|
||||
margin-right: -8px;
|
||||
|
||||
margin-bottom: 8px;
|
||||
|
||||
max-width: 700px;
|
||||
|
||||
text-shadow: 0px 0px 2px black;
|
||||
}
|
||||
|
||||
footer {
|
||||
text-align: right;
|
||||
font-style: italic;
|
||||
max-width: 700px;
|
||||
|
||||
margin-left: -8px;
|
||||
margin-right: -8px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: white;
|
||||
}
|
||||
a:visited {
|
||||
color: #bbb;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, monospace;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: block;
|
||||
src: url(FONT_merriweather_400) format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
font-display: block;
|
||||
src: url(FONT_merriweather_300) format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Merriweather';
|
||||
font-style: normal;
|
||||
font-weight: 900;
|
||||
font-display: block;
|
||||
src: url(FONT_merriweather_900) format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Inter';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: block;
|
||||
src: url(FONT_inter_400) format('woff2');
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: 'Inter';
|
||||
font-style: normal;
|
||||
font-weight: bold;
|
||||
font-display: block;
|
||||
src: url(FONT_inter_700) format('woff2');
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>
|
||||
Adam Burgess
|
||||
<div role="doc-subtitle">Software Developer in Sydney</div>
|
||||
</h1>
|
||||
|
||||
<h2>Projects</h2>
|
||||
<div class="box">
|
||||
<h3><a href="https://github.com/adamburgess/linq#readme">https://github.com/adamburgess/linq</a> - <a href="https://www.npmjs.com/package/@adamburgess/linq">@adamburgess/linq</a> on npm</h3>
|
||||
<p>
|
||||
I use C#'s <code>IEnumerable</code> extensions quite a lot, and the javascript version, <code>linq.js</code>, is very large.<br/>
|
||||
My version is 1.25kb.
|
||||
</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<h3><a href="https://github.com/adamburgess/alpine-apk#readme">https://github.com/adamburgess/alpine-apk</a> - <a href="https://www.npmjs.com/package/alpine-apk">alpine-apk</a> on npm</h3>
|
||||
<p>
|
||||
Alpine Linux is a minimal linux distro, great for docker.<br/>
|
||||
I wanted to query its package manager, APK, from Node.
|
||||
</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<h3><a href="https://github.com/adamburgess/nr#readme">https://github.com/adamburgess/nr</a> - <a href="https://www.npmjs.com/package/@adamburgess/nr">@adamburgess/nr</a> on npm</h3>
|
||||
<p>
|
||||
NPM's package.json <code>scripts</code> is quite convenient for running things.<br/>
|
||||
Yet, <code>npm run X</code> and <code>yarn X</code> are fairly slow - 150ms+.<br/>
|
||||
nr is a simple bash script using jq to run scripts. 30ms. Much faster.
|
||||
</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<h3><a href="https://github.com/adamburgess/celeste-high-frame-rate#readme">https://github.com/adamburgess/​celeste-high-frame-rate</a></h3>
|
||||
<p>
|
||||
Celeste is a fun platformer, with a banger soundtrack.<br/>
|
||||
The developers lock the ingame framerate to 60 fps, which is in my opinion <b>painful</b>.<br/>
|
||||
This small patch overrides that limitation, and the game easily hits 240fps.
|
||||
</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<h3><a href="https://tarkov-time.adam.id.au">https://tarkov-time.adam.id.au</a> - source at <a href="https://github.com/adamburgess/tarkov-time">https://github.com/adamburgess/​tarkov-time</a></h3>
|
||||
<p>
|
||||
Escape from Tarkov has a day/night cycle.<br/>
|
||||
This site shows you the time, and how long it will be to a future time. Deployed on netlify.
|
||||
</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<h3><a href="https://crop.adam.id.au">https://crop.adam.id.au</a></h3>
|
||||
<p>
|
||||
A helper for <code>ffmpeg</code>'s <code>crop</code> filter.<br/>
|
||||
Drag and drop an image and select it to get a crop filter in the correct format.
|
||||
</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<h3><a href="https://bundlephobia.fly.adam.id.au/size/@adamburgess/linq">https://bundlephobia.fly.adam.id.au/size/​@adamburgess/​linq</a></h3>
|
||||
<p>
|
||||
bundlephobia.com uses webpack. I've found it gives slightly inaccurate results because of this.<br/>
|
||||
I also wanted to get the brotlified sizes for my packages.<br/>
|
||||
This builds the package with rollup. Deployed on fly.io.<br/>
|
||||
No UI as of yet, but it also generates <a href="https://bundlephobia.fly.adam.id.au/size/@adamburgess/linq?shield&brotli">shields</a> – see the readme of my linq package above for examples.
|
||||
</p>
|
||||
</div>
|
||||
<div class="box">
|
||||
<h3><a href="https://github.com/adamburgess/image-builder">https://github.com/adamburgess/​image-builder</a></h3>
|
||||
<p>
|
||||
I build a lot (all) of my projects with Docker, so I've made my own base images. <br/>
|
||||
Using Github Actions and a generated Makefile, they automatically update whenever a dependency changes – whether it be the docker image, an alpine package, a github/lab repo, or an npm package.
|
||||
</p>
|
||||
</div>
|
||||
<footer>
|
||||
Background: Studio Ghibli - Laputa
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user