Repository navigation
Expand file tree
/
Copy pathbuild.mjs
More file actions
23 lines (22 loc) · 1.47 KB
/
Copy pathbuild.mjs
File metadata and controls
23 lines (22 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { createHash } from 'node:crypto';
import { cp, mkdir, readFile, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.dirname(fileURLToPath(import.meta.url));
const output = path.join(root, '_site');
await mkdir(path.join(output, 'assets', 'projects'), { recursive: true });
const css = await readFile(path.join(root, 'site.css'));
const cssName = `site.${createHash('sha256').update(css).digest('hex').slice(0, 12)}.css`;
await writeFile(path.join(output, 'assets', cssName), css);
// Keep the previous URL alive for visitors with older HTML cached during rollout.
await writeFile(path.join(output, 'site.css'), css);
for (const file of ['index.html', '404.html']) {
const html = await readFile(path.join(root, file), 'utf8');
await writeFile(path.join(output, file), html.replace(/href="\/site\.css(?:\?[^"]*)?"/g, `href="/assets/${cssName}"`));
}
// Explicit publish list: research images and attribution only, not development files.
for (const file of ['favicon.svg', '.nojekyll', 'assets/projects/ufish-concept.webp', 'assets/projects/uprobe-concept.webp', 'assets/projects/ufish-overview.png', 'assets/projects/uprobe-editor.jpg', 'assets/projects/SOURCES.txt', 'autofish-digital-twin/index.html']) {
await mkdir(path.dirname(path.join(output, file)), { recursive: true });
await cp(path.join(root, file), path.join(output, file));
}
console.log(`Website built in _site with cache-safe stylesheet ${cssName}`);