lewisdale.dev/src/now.11tydata.js

28 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-03-07 09:51:25 +00:00
module.exports = {
eleventyComputed: {
content: async () => {
// Retrieve the /now page from the server
const response = await fetch("https://api.omg.lol/address/lewis/now");
const body = await response.json();
// Convert the unix timestamp to a JS datetime timestamp
const updated = new Date(body.response.now.updated * 1000);
let content = body.response.now.content;
// Replace the last-updated tag
content = content.replace("{last-updated}", `<span class="now_updated">Updated ${updated.toLocaleDateString('en-GB', { dateStyle: "medium" })}</span>`);
// Strip out omg.lol-specific tags
content = content.replaceAll(/{[^}]*}/g, "");
// remove comments
content = content.replaceAll(/\/\*.*?\*\//g, "");
// Remove everything before the --- Now --- marker, because I handle page titles and headings in 11ty
if (content.includes("--- Now ---")) {
const [before, after] = content.split("--- Now ---");
content = after;
}
return content;
}
}
}