2024-10-06 11:36:54 +00:00
|
|
|
import EleventyFetch from "@11ty/eleventy-fetch";
|
2023-03-13 08:33:53 +00:00
|
|
|
|
2024-10-06 11:36:54 +00:00
|
|
|
export default{
|
2023-03-07 09:51:25 +00:00
|
|
|
eleventyComputed: {
|
2024-10-06 11:36:54 +00:00
|
|
|
nowContent: async () => {
|
2023-03-07 09:51:25 +00:00
|
|
|
// Retrieve the /now page from the server
|
2023-03-13 08:33:53 +00:00
|
|
|
const body = await EleventyFetch("https://api.omg.lol/address/lewis/now", {
|
|
|
|
type: 'json',
|
2023-08-18 09:14:35 +00:00
|
|
|
duration: '10m'
|
2023-03-13 08:33:53 +00:00
|
|
|
});
|
2023-03-07 09:51:25 +00:00
|
|
|
|
|
|
|
// 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, "");
|
|
|
|
|
2023-03-13 08:33:53 +00:00
|
|
|
// drop all headings down by a single level (h3 -> h2 etc)
|
|
|
|
content = content.replaceAll(/^#/gm, "");
|
|
|
|
|
2023-03-07 09:51:25 +00:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|