Categories were baked into config/<site>.site.json, so adding one meant a rebuild and a redeploy. They are now data: data/sections.json, seeded from the config the first time, and managed in the admin (add, rename, reorder, remove). A category's web address is fixed when it is created because that is what a QR code points at, and a category cannot be removed while it still holds menus. The landing and the top bar were the ugliest parts. The landing was a column of hairlines with tiny meta — a broadsheet, and the paper that makes this app worth looking at was nowhere on it. It is now a shelf: each category is a row whose right edge is a sliver of that menu's first page, bleeding off the screen, with the shelf edge in brass and the name in heavy tight Archivo. The bar was a row of teal pills that would not survive more categories: it now names the menu you are reading and opens a sheet listing the rest, each with its own paper sliver, and the current one is the only teal thing on screen. The sheet is a link to the landing page, so navigating still works without the script. Also fixes the category manager's own layout, which I shipped unstyled, and the markup contract the route tests described.
112 lines
5.0 KiB
TypeScript
112 lines
5.0 KiB
TypeScript
/**
|
|
* Seeds a local development Site: placeholder Pages that look enough like
|
|
* printed menus to design against. Destructive: it wipes the data directory
|
|
* under MENU_ROOT.
|
|
*
|
|
* npm run seed
|
|
*/
|
|
|
|
import { mkdir, readFile, rm } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import sharp from 'sharp';
|
|
import { parseSiteConfig } from '../src/config.ts';
|
|
import { createImagePipeline } from '../src/images/pipeline.ts';
|
|
import { SetStore } from '../src/storage/sets.ts';
|
|
import { SectionStore } from '../src/storage/sections.ts';
|
|
|
|
const root = path.resolve(process.env['MENU_ROOT'] ?? '.dev');
|
|
const configPath = path.resolve(
|
|
process.env['MENU_SITE_CONFIG'] ?? 'config/hopsngrains.site.json',
|
|
);
|
|
const dataDir = path.join(root, 'data');
|
|
|
|
const config = parseSiteConfig(JSON.parse(await readFile(configPath, 'utf8')));
|
|
|
|
function menuPage(title: string, section: string, page: number, total: number, seed: number): string {
|
|
const items = Array.from({ length: 7 }, (_, index) => {
|
|
const y = 420 + index * 130;
|
|
const width = 180 + ((seed * 37 + index * 53) % 220);
|
|
return `
|
|
<text x="120" y="${y}" font-family="Georgia, serif" font-size="34" fill="#1b1f22">${
|
|
['Wood-fired pizza', 'Smash burger', 'Tenderloin steak', 'Craft platter', 'Fish and chips', 'Risotto', 'Cheesecake'][index % 7]
|
|
}</text>
|
|
<text x="120" y="${y + 34}" font-family="Georgia, serif" font-size="24" fill="#6b7075">${
|
|
['thin crust, basil', 'double patty, cheddar', 'pepper sauce', 'for two', 'tartare', 'wild mushroom', 'berry coulis'][index % 7]
|
|
}</text>
|
|
<text x="1000" y="${y}" text-anchor="end" font-family="Georgia, serif" font-size="34" fill="#1b1f22">${
|
|
240 + ((seed * 91 + index * 71) % 620)
|
|
}</text>
|
|
<rect x="120" y="${y + 60}" width="${width}" height="2" fill="#cfc9bf" />`;
|
|
}).join('');
|
|
|
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="1240" height="1754" viewBox="0 0 1240 1754">
|
|
<rect width="1240" height="1754" fill="#f7f4ee" />
|
|
<rect x="0" y="0" width="1240" height="14" fill="#0088aa" />
|
|
<text x="120" y="180" font-family="Georgia, serif" font-size="72" fill="#1b1f22">${title}</text>
|
|
<text x="120" y="240" font-family="Helvetica, Arial, sans-serif" font-size="30" fill="#6b7075">${section} · page ${page} of ${total}</text>
|
|
<rect x="120" y="290" width="1000" height="1" fill="#b2703b" />
|
|
${items}
|
|
<text x="120" y="1650" font-family="Helvetica, Arial, sans-serif" font-size="24" fill="#6b7075">Placeholder page for design review</text>
|
|
<text x="1120" y="1650" text-anchor="end" font-family="Helvetica, Arial, sans-serif" font-size="24" fill="#b2703b">${page} / ${total}</text>
|
|
</svg>`;
|
|
}
|
|
|
|
async function pageImage(svg: string): Promise<Buffer> {
|
|
return sharp(Buffer.from(svg)).jpeg({ quality: 82 }).toBuffer();
|
|
}
|
|
|
|
const plan: { section: string; label: string; validUntil: string | null; pages: number }[] = [
|
|
{ section: 'food', label: 'Food Menu', validUntil: '2026-12-31', pages: 4 },
|
|
{ section: 'bar', label: 'Bar Menu', validUntil: '2026-06-26', pages: 3 },
|
|
{ section: 'wine', label: 'Wine List', validUntil: null, pages: 2 },
|
|
{ section: 'whats-on', label: "What's On", validUntil: null, pages: 2 },
|
|
];
|
|
|
|
await mkdir(dataDir, { recursive: true });
|
|
for (const dir of ['drafts', 'published', 'originals']) {
|
|
await rm(path.join(dataDir, dir), { recursive: true, force: true });
|
|
}
|
|
|
|
// Seeding replaces the menus, not the category list.
|
|
const sections = new SectionStore({ dataDir, seed: config.sections });
|
|
await sections.load();
|
|
|
|
const store = new SetStore({
|
|
dataDir,
|
|
pipeline: createImagePipeline(),
|
|
sections,
|
|
maxPagesPerSet: config.limits.maxPagesPerSet,
|
|
});
|
|
|
|
for (const [index, entry] of plan.entries()) {
|
|
const section = sections.bySlug(entry.section);
|
|
if (section === undefined) continue;
|
|
const set = await store.create(entry.section, { label: entry.label, validUntil: entry.validUntil });
|
|
for (let page = 1; page <= entry.pages; page += 1) {
|
|
const svg = menuPage(entry.label, section.label, page, entry.pages, index + page);
|
|
await store.addPage(set.id, {
|
|
data: await pageImage(svg),
|
|
originalName: `${entry.section}-${String(page).padStart(2, '0')}.jpg`,
|
|
});
|
|
}
|
|
const published = await store.publish(set.id);
|
|
console.log(`published ${published.section}/${published.slug} (${entry.pages} pages)`);
|
|
}
|
|
|
|
// One archived set, so the "Older menus" fold has something to show.
|
|
const previous = await store.create('bar', { label: 'Bar Menu, spring', validUntil: '2026-03-31' });
|
|
for (let page = 1; page <= 2; page += 1) {
|
|
await store.addPage(previous.id, {
|
|
data: await pageImage(menuPage('Bar Menu, spring', 'Bar', page, 2, page)),
|
|
originalName: `bar-spring-${page}.jpg`,
|
|
});
|
|
}
|
|
await store.publish(previous.id);
|
|
|
|
// Publishing the spring set archived the June one; put June back as Current so
|
|
// the archive is the older menu rather than the live one.
|
|
const june = (await store.list()).find((set) => set.section === 'bar' && set.slug === '2026-06-26');
|
|
if (june !== undefined) await store.restore(june.id);
|
|
|
|
console.log(`seeded ${dataDir}`);
|