const fs = require("node:fs/promises"); let meta; const chooseFortune = () => { const authors = Object.keys(meta.fortune); const chosenAuthor = authors[Math.floor(Math.random()*authors.length)]; const fortunes = meta.fortune[chosenAuthor]; const chosenFortune = fortunes[Math.floor(Math.random()*fortunes.length)]; return { text: chosenFortune, name: chosenAuthor }; }; const getPosts = async () => { const posts = []; for (let i = 0; i < meta.targets.length; i++) { const t = meta.targets[i]; const data = JSON.parse(await fs.readFile(`./~${t}/manifest.rolsf.json`)); if (!data.document || data.document !== "xyz.rolsf.manifest.own.1") { throw new Error(`unsupported own manifest for target: '${t}'`); } data.posts.forEach(post => { post.user = t; posts.push(post); }); } posts.sort((a, b) => b.unix_time - a.unix_time); return posts; }; const Post = ({ href="#", user, date, title }) => ` ${user} ${date} ${title} `; const Fortune = ({text, name}) => `
“${text}” -- ${name}
`; const MainPage = async () => ` ${meta.brand}
${meta.brand} ${Fortune(chooseFortune())} ${(await getPosts()).map(Post).join("")}
`; const main = async () => { meta = JSON.parse((await fs.readFile("./meta.json"))); await fs.writeFile("./main.html", await MainPage()); }; main();