From 356d0747009bcd2675a5b0805cc294a4dd146d44 Mon Sep 17 00:00:00 2001 From: Ricardo Date: Tue, 24 Feb 2026 20:32:46 +0100 Subject: [PATCH] fix: use rawMarkdownBody filter instead of template.frontMatter.content Eleventy 3.x no longer allows synchronous access to template internals from pagination templates. Replace article.template.frontMatter.content with a custom filter that reads the source file via gray-matter. --- article-markdown.njk | 2 +- eleventy.config.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/article-markdown.njk b/article-markdown.njk index 3997f19..43a1974 100644 --- a/article-markdown.njk +++ b/article-markdown.njk @@ -12,7 +12,7 @@ eleventyExcludeFromCollections: true } --- -{%- set bodyContent = article.template.frontMatter.content -%} +{%- set bodyContent = article.inputPath | rawMarkdownBody -%} {%- set tokens = (bodyContent.length / 4) | round(0, "ceil") -%} --- title: "{{ article.data.title | replace('"', '\\"') }}" diff --git a/eleventy.config.js b/eleventy.config.js index 68a5ed6..504e300 100644 --- a/eleventy.config.js +++ b/eleventy.config.js @@ -456,6 +456,17 @@ export default function (eleventyConfig) { } }); + // Extract raw Markdown body from a source file (strips front matter) + eleventyConfig.addFilter("rawMarkdownBody", (inputPath) => { + try { + const src = readFileSync(inputPath, "utf-8"); + const { content } = matter(src); + return content.trim(); + } catch { + return ""; + } + }); + // Current timestamp filter (for client-side JS buildtime) eleventyConfig.addFilter("timestamp", () => Date.now());