Fix headings for now page, use EleventyFetch for caching

This commit is contained in:
Lewis Dale 2023-03-13 08:33:53 +00:00
parent 1be89433c1
commit 87ca6671e0
2 changed files with 315 additions and 1190 deletions

1494
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,13 @@
const EleventyFetch = require("@11ty/eleventy-fetch");
module.exports = { module.exports = {
eleventyComputed: { eleventyComputed: {
content: async () => { content: async () => {
// Retrieve the /now page from the server // Retrieve the /now page from the server
const response = await fetch("https://api.omg.lol/address/lewis/now"); const body = await EleventyFetch("https://api.omg.lol/address/lewis/now", {
const body = await response.json(); type: 'json',
duration: '6h'
});
// Convert the unix timestamp to a JS datetime timestamp // Convert the unix timestamp to a JS datetime timestamp
const updated = new Date(body.response.now.updated * 1000); const updated = new Date(body.response.now.updated * 1000);
@ -16,6 +20,9 @@ module.exports = {
// remove comments // remove comments
content = content.replaceAll(/\/\*.*?\*\//g, ""); 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 // Remove everything before the --- Now --- marker, because I handle page titles and headings in 11ty
if (content.includes("--- Now ---")) { if (content.includes("--- Now ---")) {
const [before, after] = content.split("--- Now ---"); const [before, after] = content.split("--- Now ---");