docfast/scripts/build-html.cjs
OpenClaw aab6bf3bee
All checks were successful
Deploy to Production / Deploy to Server (push) Successful in 2m24s
feat: Pro limit 2,500/mo, website templating, cleanup
- Set Pro tier limit to 2,500 PDFs/month (was unlimited/5000)
- Added Pro limit enforcement in usage middleware
- Updated landing page, JSON-LD, and Stripe product description
- Created build-time HTML templating (partials for nav/footer/styles)
- Source files in public/src/, partials in public/partials/
- Build script: node scripts/build-html.cjs
- Deleted stale backup file
- Fixed index.html nav logo to use <a> tag for consistency
2026-02-16 18:46:59 +00:00

48 lines
1.5 KiB
JavaScript

#!/usr/bin/env node
/**
* DocFast HTML Build Script
* Replaces {{> partial_name}} in source files with partial contents.
* Source: public/src/*.html → Output: public/*.html
* Partials: public/partials/_*.html
*/
const fs = require('fs');
const path = require('path');
const srcDir = path.join(__dirname, '..', 'public', 'src');
const outDir = path.join(__dirname, '..', 'public');
const partialsDir = path.join(__dirname, '..', 'public', 'partials');
// Load all partials
const partials = {};
if (fs.existsSync(partialsDir)) {
for (const f of fs.readdirSync(partialsDir)) {
if (f.startsWith('_') && f.endsWith('.html')) {
const name = f.replace(/^_/, '').replace(/\.html$/, '');
partials[name] = fs.readFileSync(path.join(partialsDir, f), 'utf-8').trimEnd();
}
}
}
console.log(`Loaded partials: ${Object.keys(partials).join(', ')}`);
if (!fs.existsSync(srcDir)) {
console.error(`Source directory not found: ${srcDir}`);
process.exit(1);
}
// Process each source file
const files = fs.readdirSync(srcDir).filter(f => f.endsWith('.html'));
for (const file of files) {
let content = fs.readFileSync(path.join(srcDir, file), 'utf-8');
// Replace {{> partial_name}} with partial content
content = content.replace(/\{\{>\s*(\w+)\s*\}\}/g, (match, name) => {
if (partials[name]) return partials[name];
console.warn(` Warning: partial '${name}' not found in ${file}`);
return match;
});
const outPath = path.join(outDir, file);
fs.writeFileSync(outPath, content);
console.log(` Built: ${file}`);
}
console.log('Done.');