92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Generate 80 QR code SVGs for table ordering (40 Backaplan + 40 Askim).
|
|
*
|
|
* Usage:
|
|
* node scripts/generate-table-qr-codes.mjs
|
|
*
|
|
* Output:
|
|
* public/images/booking/backaplan/qr-backaplan-001.svg ... qr-backaplan-040.svg
|
|
* public/images/booking/askim/qr-askim-001.svg ... qr-askim-040.svg
|
|
*
|
|
* Each QR points to:
|
|
* https://shahikitchen.se/orderfromtable?table=backaplan-001
|
|
* https://shahikitchen.se/orderfromtable?table=askim-001
|
|
* etc.
|
|
*/
|
|
|
|
import QRCode from 'qrcode';
|
|
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const ROOT = path.resolve(__dirname, '..');
|
|
|
|
const BASE_URL = 'https://shahikitchen.se/orderfromtable';
|
|
|
|
const BRANCHES = [
|
|
{ key: 'backaplan', label: 'Backaplan', dir: 'backaplan' },
|
|
{ key: 'askim', label: 'Askim', dir: 'askim' },
|
|
];
|
|
|
|
const MIN_TABLE = 1;
|
|
const MAX_TABLE = 40;
|
|
|
|
function pad3(n) {
|
|
return String(n).padStart(3, '0');
|
|
}
|
|
|
|
async function ensureDir(dir) {
|
|
await fs.mkdir(dir, { recursive: true });
|
|
}
|
|
|
|
async function generateOne(branchKey, tableNum, outputPath) {
|
|
const tableId = `${branchKey}-${pad3(tableNum)}`;
|
|
const url = `${BASE_URL}?table=${tableId}`;
|
|
|
|
const svg = await QRCode.toString(url, {
|
|
type: 'svg',
|
|
width: 320,
|
|
margin: 2,
|
|
errorCorrectionLevel: 'Q', // Good balance for physical use (tables, stands, possibly dirty)
|
|
color: {
|
|
dark: '#111111', // near-black for high contrast print
|
|
light: '#FFFFFF',
|
|
},
|
|
});
|
|
|
|
// Add a small metadata comment (harmless in SVG)
|
|
const svgWithMeta = svg.replace(
|
|
'<svg ',
|
|
`<!-- Shahi Kitchen Table QR: ${tableId} -->\n<svg `
|
|
);
|
|
|
|
await fs.writeFile(outputPath, svgWithMeta, 'utf8');
|
|
console.log(`✓ ${tableId} → ${path.relative(ROOT, outputPath)}`);
|
|
}
|
|
|
|
async function main() {
|
|
console.log('Generating Shahi Kitchen table QR codes (80 total)...\n');
|
|
|
|
for (const branch of BRANCHES) {
|
|
const outDir = path.join(ROOT, 'public', 'images', 'booking', branch.dir);
|
|
await ensureDir(outDir);
|
|
|
|
for (let i = MIN_TABLE; i <= MAX_TABLE; i++) {
|
|
const filename = `qr-${branch.key}-${pad3(i)}.svg`;
|
|
const fullPath = path.join(outDir, filename);
|
|
await generateOne(branch.key, i, fullPath);
|
|
}
|
|
console.log(''); // blank line between branches
|
|
}
|
|
|
|
console.log('All 80 QR codes generated successfully.');
|
|
console.log('They all target the single /orderfromtable page with ?table=... param.');
|
|
}
|
|
|
|
main().catch((err) => {
|
|
console.error('QR generation failed:', err);
|
|
process.exit(1);
|
|
});
|