Astro site: profile header, Flickr-style justified rows that keep each photo's aspect ratio, and a detail page per photo (date from EXIF or a YAML sidecar, optional location) that opens in a dialog from the grid. Originals are dropped from the build and CI fails if a published image still carries EXIF location or capture time. Tags release folio-<ver>.tgz and deploy it with ygg/static-server to ig.mtps.pl. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
// @ts-check
|
|
import { existsSync, readdirSync, readFileSync, rmSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { defineConfig } from 'astro/config';
|
|
|
|
/**
|
|
* Astro copies the original photos into _astro/ even though pages only use
|
|
* the resized versions. The originals still carry their EXIF (GPS, camera,
|
|
* exact time), so delete every image no page references.
|
|
* @returns {import('astro').AstroIntegration}
|
|
*/
|
|
const dropUnusedOriginals = () => ({
|
|
name: 'drop-unused-originals',
|
|
hooks: {
|
|
'astro:build:done': ({ dir, pages, logger }) => {
|
|
const root = fileURLToPath(dir);
|
|
if (!existsSync(`${root}_astro`)) return;
|
|
const html = pages
|
|
.map(({ pathname }) => {
|
|
const page = pathname === '' ? 'index' : pathname.replace(/\/$/, '');
|
|
return readFileSync(`${root}${page}.html`, 'utf8');
|
|
})
|
|
.join('\n');
|
|
for (const file of readdirSync(`${root}_astro`)) {
|
|
if (/\.(jpe?g|png|webp|avif)$/i.test(file) && !html.includes(`/_astro/${file}`)) {
|
|
rmSync(`${root}_astro/${file}`);
|
|
logger.info(`removed unreferenced ${file}`);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
});
|
|
|
|
export default defineConfig({
|
|
site: 'https://ig.mtps.pl',
|
|
// p/<slug>.html instead of p/<slug>/index.html: static-server's nginx
|
|
// serves $uri.html, so /p/<slug> works without a trailing-slash redirect
|
|
build: { format: 'file' },
|
|
trailingSlash: 'never',
|
|
integrations: [dropUnusedOriginals()],
|
|
});
|