MC/website/scripts/build-prophecy.mjs

20 lines
9.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {readFileSync,writeFileSync,readdirSync} from 'node:fs';
const web=new URL('../web/',import.meta.url),posts=JSON.parse(readFileSync(new URL('prophecy-data.json',web),'utf8'));
const extended=new URL('../content/prophecy/',import.meta.url),graphicData=JSON.parse(readFileSync(new URL('prophecy-graphics.json',web),'utf8'));
for(const post of posts){const essay=readFileSync(new URL(post.id+'.md',extended),'utf8').replace(/\r\n/g,'\n');const sections=essay.split(/^# /m).slice(1).map(block=>{const [heading,...lines]=block.trim().split('\n');return {heading,paragraphs:lines.join('\n').trim().split(/\n\s*\n/).filter(Boolean)}});post.sections.push(...sections);post.words=post.sections.flatMap(x=>x.paragraphs).join(' ').split(/\s+/).length;if(post.words<3000)throw Error(post.id+' has only '+post.words+' words');post.minutes=Math.ceil(post.words/200)}
const escape=s=>s.replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));
const links=[['index.html','Home','menu-6'],['manual.html','Manual/wiki','menu-5'],['prophecy.html','The Prophecy','item-28'],['exchange.html','Xchange','menu-0'],['forums.html','Forums','menu-4'],['discord.html','Discord','menu-3'],['tickets.html','Support tickets','menu-9']];
function top(file){return '<nav aria-label="Main navigation">'+links.map(([href,label,icon])=>'<a href="'+href+'"'+((href===file||(href==='prophecy.html'&&file.startsWith('prophecy-')))?' aria-current="page"':'')+'><img src="assets/'+icon+'.webp" alt="" width="28" height="28"><span>'+label+'</span></a>').join('')+'</nav>'}
for(const file of readdirSync(web).filter(f=>f.endsWith('.html'))){let s=readFileSync(new URL(file,web),'utf8');s=s.replace(/<nav aria-label="Main navigation">[\s\S]*?<\/nav>/,top(file));writeFileSync(new URL(file,web),s)}
const base=readFileSync(new URL('index.html',web),'utf8'),header=base.match(/<header>[\s\S]*?<\/header>/)[0],menu=base.match(/<nav id="realm-menu"[\s\S]*?<\/nav>/)[0],footer=base.match(/<footer>[\s\S]*?<\/footer>/)[0];
const postUrl=p=>'prophecy-'+p.id+'.html';
function page(file,title,description,body,extra=''){return '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="description" content="'+escape(description)+'"><title>'+escape(title)+' — Project Dune</title><link rel="icon" href="assets/favicon.svg">'+['styles','pages','minecraft','lore','prophecy'].map(x=>'<link rel="stylesheet" href="'+x+'.css">').join('')+'<script src="pages.js" defer></script>'+extra+'</head><body><a class="skip" href="#prophecy-content">Skip to content</a>'+header.replace(/<nav aria-label="Main navigation">[\s\S]*?<\/nav>/,top(file))+'<main><section class="page-intro intro-prophecy"><p class="eyebrow">PROJECT DUNE / THE PROPHECY</p><h1>'+escape(title)+'</h1><p>'+escape(description)+'</p></section>'+menu+'<div id="prophecy-content">'+body+'</div></main>'+footer+'<div class="toast" role="status" aria-live="polite"></div></body></html>'}
function graphic(post,type){const g=graphicData[post.id];let body,title;if(type==='timeline'){title='Story route: events and changing conditions';body='<ol class="graphic-timeline">'+g.timeline.map(([name,note],i)=>'<li><b>'+String(i+1).padStart(2,'0')+'</b><strong>'+escape(name)+'</strong><span>'+escape(note)+'</span></li>').join('')+'</ol>'}else if(type==='map'){title='Relationship map: pressures around the central figure';body='<div class="graphic-center">'+escape(g.center)+'</div><div class="graphic-influences">'+g.influences.map(([name,note])=>'<div><strong>'+escape(name)+'</strong><span>'+escape(note)+'</span></div>').join('')+'</div>'}else{title='Comparison board: keep these questions separate';body='<div class="graphic-comparison">'+g.comparison.map(([name,note,question])=>'<div><strong>'+escape(name)+'</strong><p>'+escape(note)+'</p><span>'+escape(question)+'</span></div>').join('')+'</div>'}return '<figure class="prophecy-graphic"><figcaption>'+title+'</figcaption>'+body+'<p>Interpretive visual aid. The story route shows relative sequence, not a dated chronology; the relationship map organises the essay’s questions rather than simulating character behaviour.</p></figure>'}
function contents(post){return '<nav class="prophecy-toc" aria-label="Article contents"><h3>In this '+post.minutes+'-minute essay</h3>'+post.sections.map((x,i)=>'<a href="#section-'+(i+1)+'">'+String(i+1).padStart(2,'0')+' / '+escape(x.heading)+'</a>').join('')+'</nav><p class="reading-note">'+post.words.toLocaleString('en-US')+' words · Estimated at 200 words per minute. Individual reading speed varies; diagrams and reflection exercises may take longer.</p>'}
const cards=posts.map(p=>'<article class="prophecy-card" data-book="'+escape(p.book)+'" data-search="'+escape((p.title+' '+p.book+' '+p.excerpt).toLowerCase())+'"><a class="prophecy-card-art" href="'+postUrl(p)+'"><img src="assets/'+p.art+'.webp" alt="Thematic concept illustration for '+escape(p.title)+'" loading="lazy"><span>CHRONICLE '+p.chapter+'</span></a><div class="prophecy-card-copy"><p class="prophecy-book">'+escape(p.book)+' · '+p.minutes+' min read · Book spoilers</p><h2><a href="'+postUrl(p)+'">'+escape(p.title)+'</a></h2><p>'+escape(p.excerpt)+'</p><small>Project Dune Journal · 13 October 2026</small><a class="prophecy-read" href="'+postUrl(p)+'">Read the chronicle →</a></div></article>').join('');
const intro='<section class="prophecy-library"><div class="prophecy-introduction"><img src="assets/faction-atreides.svg" alt="Stylised Atreides hawk emblem"><div><p class="eyebrow">PAUL ATREIDES / A READING JOURNAL</p><h2>From heir to legend. From legend to warning.</h2><p>Six long-form reading essays follow Paul through Frank Herbert’s <em>Dune</em>, <em>Dune Messiah</em> and <em>Children of Dune</em>. Each essay offers at least 15 minutes of reading and three visual aids. Plot context is sourced; the sections labelled “Reading the theme” are our interpretation. This is book commentary, separate from Project Dune’s game mechanics.</p><p class="prophecy-warning">Spoiler notice: the collection covers Paul’s entire arc in the first three novels. Each article identifies its book scope before you reveal the text. Read in chronicle order, or select the book you have finished.</p></div></div><div class="prophecy-filters"><label>Book<select id="prophecy-book"><option value="all">All three books</option><option>Dune</option><option>Dune Messiah</option><option>Children of Dune</option></select></label><label>Find a chronicle<input id="prophecy-search" type="search" placeholder="Paul, prophecy, prescience…"></label><p id="prophecy-count" role="status">6 chronicles</p></div><div class="prophecy-grid">'+cards+'</div><p id="prophecy-empty" hidden>No chronicles match that search.</p><aside class="prophecy-reading-order"><h3>The book path</h3><p><strong>Dune (1965)</strong> → <strong>Dune Messiah (1969)</strong> → <strong>Children of Dune (1976)</strong></p><p>These posts focus on Frank Herbert’s novels rather than film adaptations. Illustrations evoke the setting and are not canonical character portraits. The articles are original commentary, not copied passages from the books.</p><a href="https://dunenovels.com/chronological-order-of-dune-books/" target="_blank" rel="noopener">Official wider-series reading order ↗</a></aside></section>';
writeFileSync(new URL('prophecy.html',web),page('prophecy.html','The Prophecy','Paul Atreides through the Dune books: power, belief and the price of knowing the future.',intro,'<script src="prophecy.js" defer></script>'));
for(const [i,p] of posts.entries()){
const body='<article class="prophecy-article"><a class="prophecy-back" href="prophecy.html">← All chronicles</a><p class="prophecy-book">CHRONICLE '+p.chapter+' / '+escape(p.book)+'</p><h2>'+escape(p.title)+'</h2><p class="prophecy-meta">Project Dune Journal · <time datetime="2026-10-13">13 October 2026</time> · '+p.minutes+' min read · Original book commentary</p><figure class="prophecy-article-art"><img src="assets/'+p.art+'.webp" alt="Thematic Dune concept artwork" loading="lazy"><figcaption>Thematic concept artwork; not a canonical portrait of Paul.</figcaption></figure><div class="prophecy-scope"><strong>Spoiler scope: '+escape(p.spoilers)+'</strong><p>The article contains plot details from the named books. Its interpretation is labelled separately from the story context.</p></div><details class="prophecy-reveal"><summary>Read the article — '+escape(p.book)+' spoilers</summary><div class="prophecy-prose">'+contents(p)+p.sections.map((section,index)=>'<section id="section-'+(index+1)+'"><h3>'+escape(section.heading)+'</h3>'+section.paragraphs.map(t=>'<p>'+escape(t)+'</p>').join('')+'</section>'+([0,5,10].includes(index)?graphic(p,index===0?'timeline':index===5?'map':'comparison'):'')).join('')+'<aside class="prophecy-sources"><h3>Books & reference notes</h3><p>Primary work: Frank Herbert, <em>'+escape(p.book)+'</em>. Plot context checked against these references; thematic interpretation is the Project Dune Journal’s own.</p><ul>'+p.sources.map(([title,url])=>'<li><a href="'+escape(url)+'" target="_blank" rel="noopener">'+escape(title)+' ↗</a></li>').join('')+'</ul></aside></div></details><nav class="prophecy-pager" aria-label="Chronicle navigation">'+(posts[i-1]?'<a href="'+postUrl(posts[i-1])+'">← Previous chronicle</a>':'<a href="prophecy.html">← Blog index</a>')+(posts[i+1]?'<a href="'+postUrl(posts[i+1])+'">Next chronicle →</a>':'<a href="prophecy.html">Back to the collection →</a>')+'</nav></article>';
writeFileSync(new URL(postUrl(p),web),page(postUrl(p),'The Prophecy',p.excerpt,body));}
console.log('Built The Prophecy index and six separate articles; updated top navigation');