From b94e627a0a9c2d88cea23c0199f3d403719556eb Mon Sep 17 00:00:00 2001 From: Nicholas Lamicela Date: Fri, 13 Dec 2024 20:45:59 -0800 Subject: [PATCH] section splitter --- _includes/updates.njk | 6 ++++++ content/sitemap/sitemap.xml.njk | 14 -------------- content/updates.md | 11 +++++++++++ eleventy.config.js | 26 +++++++++++++++++++++++++- package.json | 1 + 5 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 _includes/updates.njk delete mode 100644 content/sitemap/sitemap.xml.njk create mode 100644 content/updates.md diff --git a/_includes/updates.njk b/_includes/updates.njk new file mode 100644 index 0000000..2d700e9 --- /dev/null +++ b/_includes/updates.njk @@ -0,0 +1,6 @@ + +{% for section in content | sections %} + START SECTION + {{ section | safe }} + END SECTION +{% endfor %} diff --git a/content/sitemap/sitemap.xml.njk b/content/sitemap/sitemap.xml.njk deleted file mode 100644 index 4da684a..0000000 --- a/content/sitemap/sitemap.xml.njk +++ /dev/null @@ -1,14 +0,0 @@ ---- -permalink: /sitemap.xml -eleventyExcludeFromCollections: true ---- - - -{%- for page in collections.all %} - {% set absoluteUrl %}{{ page.url | htmlBaseUrl(metadata.url) }}{% endset %} - - {{ absoluteUrl }} - {{ page.date | htmlDateString }} - -{%- endfor %} - diff --git a/content/updates.md b/content/updates.md new file mode 100644 index 0000000..1f1438b --- /dev/null +++ b/content/updates.md @@ -0,0 +1,11 @@ +--- +layout: updates.njk +--- + +# first update + +content + +# second update + +more content diff --git a/eleventy.config.js b/eleventy.config.js index 51eac90..a5a12df 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -1,7 +1,8 @@ -import { DateTime } from "luxon"; import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight"; import { EleventyHtmlBasePlugin } from "@11ty/eleventy"; import pluginRss from '@11ty/eleventy-plugin-rss'; +import { JSDOM } from 'jsdom'; +import { DateTime } from "luxon"; /** @param {import('@11ty/eleventy').UserConfig} eleventyConfig */ export default function(eleventyConfig) { @@ -92,6 +93,29 @@ export default function(eleventyConfig) { } }); + // https://stackoverflow.com/a/74005383 + eleventyConfig.addFilter('sections', (html) => { + const dom = new JSDOM(html); + const document = dom.window.document; + const chunks = []; + for (const h1 of document.querySelectorAll('h1')) { + let chunk = ''; + let elem = h1; + while (true) { + chunk += elem.outerHTML; + elem = document.evaluate( + "following-sibling::*[1]", + elem, + function() {}, + dom.window.XPathResult.FIRST_ORDERED_NODE_TYPE + ).singleNodeValue; + if (!elem || elem.nodeName === 'H1') break; + } + chunks.push(chunk); + } + return chunks; + }); + eleventyConfig.addShortcode("currentBuildDate", () => { return (new Date()).toISOString(); }) diff --git a/package.json b/package.json index dc4106d..938918b 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@11ty/eleventy-plugin-rss": "^2.0.2", "@11ty/eleventy-plugin-syntaxhighlight": "^5.0.0", "cross-env": "^7.0.3", + "jsdom": "^25.0.1", "luxon": "^3.3.0", "markdown-it-anchor": "^8.6.7" }