Serve the customer-facing menus
Landing page, Section pages and archived sets rendered per request from the store, with the approved design: hand-written CSS, self-hosted Archivo, a copper pour line in the Section rail, an admin-only Thumbnail and a text page index. Media is keyed by Page id so URLs survive publishing, and a Draft's media needs a session. Includes the scrypt admin auth and the login throttle the media rule needs.
This commit is contained in:
1 parent
edea83228c
commit
9cb4021229
23 files changed
+2320
-6
No files matched your search
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
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 rm(dataDir, { recursive: true, force: true });
|
||||
await mkdir(dataDir, { recursive: true });
|
||||
|
||||
const store = new SetStore({
|
||||
dataDir,
|
||||
pipeline: createImagePipeline(),
|
||||
sections: config.sections.map((section) => section.slug),
|
||||
maxPagesPerSet: config.limits.maxPagesPerSet,
|
||||
});
|
||||
|
||||
for (const [index, entry] of plan.entries()) {
|
||||
const section = config.sections.find((candidate) => candidate.slug === 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}`);
|
||||
Reference in new issue
Block a user