From c43c6a934659787caee89ca1a61e996988cad9a2 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 27 Jan 2026 21:10:17 +0200 Subject: Add dist directory generation and deploy target Build now creates dist/ with all static assets (html, css, js, data, images). Added 'just dist' target to rsync dist/ to remote server. Co-Authored-By: Claude Opus 4.5 --- .gitignore | 5 ++++ Justfile | 4 +++ build.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a589a13 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# Build output +dist/ + +# Node.js +node_modules/ diff --git a/Justfile b/Justfile index bfdc4f5..a98341a 100644 --- a/Justfile +++ b/Justfile @@ -18,3 +18,7 @@ open: # Stop the webserver stop: -pkill -f "serve.js" 2>/dev/null + +# Deploy dist directory to remote server +dist: + rsync -avz --delete dist/ f0:/data/nfs/k3svolumes/apache/scifi/ diff --git a/build.js b/build.js index 65c0851..af6ed4d 100644 --- a/build.js +++ b/build.js @@ -3,7 +3,7 @@ * Site Generator * * Reads markdown summaries from summaries/{id}.md and embeds them into - * data/books.json so the site works offline without a server. + * data/books.json, then creates a dist directory with all static assets. * * Usage: node build.js * @@ -13,8 +13,10 @@ const fs = require('fs'); const path = require('path'); -const SUMMARIES_DIR = path.join(__dirname, 'summaries'); -const BOOKS_JSON = path.join(__dirname, 'data', 'books.json'); +const ROOT_DIR = __dirname; +const SUMMARIES_DIR = path.join(ROOT_DIR, 'summaries'); +const BOOKS_JSON = path.join(ROOT_DIR, 'data', 'books.json'); +const DIST_DIR = path.join(ROOT_DIR, 'dist'); function readSummary(id) { const filePath = path.join(SUMMARIES_DIR, `${id}.md`); @@ -31,10 +33,32 @@ function readSummary(id) { return summaryLines || null; } -function build() { - console.log('Building site...\n'); +/** + * Recursively copies a directory from src to dest. + */ +function copyDir(src, dest) { + fs.mkdirSync(dest, { recursive: true }); + const entries = fs.readdirSync(src, { withFileTypes: true }); + + for (const entry of entries) { + const srcPath = path.join(src, entry.name); + const destPath = path.join(dest, entry.name); + + if (entry.isDirectory()) { + copyDir(srcPath, destPath); + } else { + fs.copyFileSync(srcPath, destPath); + } + } +} + +/** + * Embeds summaries from markdown files into books.json. + * Returns the updated books data. + */ +function embedSummaries() { + console.log('Embedding summaries...\n'); - // Read books.json const booksData = JSON.parse(fs.readFileSync(BOOKS_JSON, 'utf8')); let updated = 0; @@ -54,11 +78,9 @@ function build() { } } - // Write updated books.json fs.writeFileSync(BOOKS_JSON, JSON.stringify(booksData, null, 2)); - console.log('\n=== Build Complete ==='); - console.log(`Summaries embedded: ${updated}`); + console.log(`\nSummaries embedded: ${updated}`); console.log(`Missing summaries: ${missing.length}`); if (missing.length > 0) { @@ -69,7 +91,49 @@ function build() { }); } - console.log('\nSite is ready. Open index.html in a browser.'); + return booksData; +} + +/** + * Creates the dist directory with all static assets for distribution. + */ +function createDist() { + console.log('\n--- Creating dist directory ---\n'); + + // Remove existing dist directory + if (fs.existsSync(DIST_DIR)) { + fs.rmSync(DIST_DIR, { recursive: true }); + } + fs.mkdirSync(DIST_DIR); + + // Copy static files + fs.copyFileSync(path.join(ROOT_DIR, 'index.html'), path.join(DIST_DIR, 'index.html')); + console.log('✓ index.html'); + + // Copy directories + copyDir(path.join(ROOT_DIR, 'css'), path.join(DIST_DIR, 'css')); + console.log('✓ css/'); + + copyDir(path.join(ROOT_DIR, 'js'), path.join(DIST_DIR, 'js')); + console.log('✓ js/'); + + copyDir(path.join(ROOT_DIR, 'data'), path.join(DIST_DIR, 'data')); + console.log('✓ data/'); + + copyDir(path.join(ROOT_DIR, 'images'), path.join(DIST_DIR, 'images')); + console.log('✓ images/'); + + console.log('\nDist directory created at: dist/'); +} + +function build() { + console.log('=== Building Site ===\n'); + + embedSummaries(); + createDist(); + + console.log('\n=== Build Complete ==='); + console.log('Site is ready. Open dist/index.html in a browser.'); } build(); -- cgit v1.2.3