Fix headings for now page, use EleventyFetch for caching
This commit is contained in:
parent
1be89433c1
commit
87ca6671e0
1494
package-lock.json
generated
1494
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,13 @@
|
||||
const EleventyFetch = require("@11ty/eleventy-fetch");
|
||||
|
||||
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();
|
||||
const body = await EleventyFetch("https://api.omg.lol/address/lewis/now", {
|
||||
type: 'json',
|
||||
duration: '6h'
|
||||
});
|
||||
|
||||
// Convert the unix timestamp to a JS datetime timestamp
|
||||
const updated = new Date(body.response.now.updated * 1000);
|
||||
@ -16,6 +20,9 @@ module.exports = {
|
||||
// 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 ---");
|
||||
|
Loading…
Reference in New Issue
Block a user