perf(assets): convert images to webp and check asset paths
Convert 26 PNG/JPG assets to WebP: max 1600 px, q80, diagrams lossless. src/assets shrinks from 8.3 MB to 4.2 MB. Use me.jpg for og:image and twitter:image; some crawlers skip WebP. Add scripts/check-assets.mjs to lint, so a wrong asset path fails lint, not only at runtime.
This commit is contained in:
1 parent
4e59770e53
commit
2abc7c31e2
62 files changed
+74
-33
No files matched your search
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env node
|
||||
// Verifies that every asset path in AssetsConstants.ts and index.html exists.
|
||||
// A wrong path builds fine and only 404s at runtime.
|
||||
|
||||
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
||||
import { join, dirname, extname } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const srcDir = join(dirname(fileURLToPath(import.meta.url)), '..', 'src');
|
||||
const EXTENSIONS = new Set(['.ts', '.html', '.scss', '.json']);
|
||||
|
||||
function* walk(dir) {
|
||||
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
||||
const path = join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
yield* walk(path);
|
||||
} else if (EXTENSIONS.has(extname(path)) && !path.endsWith('.spec.ts')) {
|
||||
yield path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const missing = [];
|
||||
for (const file of walk(srcDir)) {
|
||||
const content = readFileSync(file, 'utf8');
|
||||
for (const [, path] of content.matchAll(/\b(assets\/[\w./-]+)/g)) {
|
||||
if (!existsSync(join(srcDir, path))) {
|
||||
missing.push(`${file}: ${path}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error(`Missing assets:\n${missing.join('\n')}`);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('All referenced assets exist.');
|
||||
Reference in new issue
Block a user