lewisdale.dev/src/now.11tydata.js
Lewis Dale e0c315d837
Some checks failed
Build and copy to prod / build-and-copy (push) Has been cancelled
Upgrade to Eleventy 3.0.0
2024-10-06 12:36:54 +01:00

35 lines
1.4 KiB
JavaScript

import EleventyFetch from "@11ty/eleventy-fetch";
export default{
eleventyComputed: {
nowContent: async () => {
// Retrieve the /now page from the server
const body = await EleventyFetch("https://api.omg.lol/address/lewis/now", {
type: 'json',
duration: '10m'
});
// 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, "");
// drop all headings down by a single level (h3 -> h2 etc)
content = content.replaceAll(/^#/gm, "");
// 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;
}
}
}