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.
This commit is contained in:
Ricardo
2026-02-24 20:32:46 +01:00
parent e56e2c67a5
commit 356d074700
2 changed files with 12 additions and 1 deletions

View File

@@ -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('"', '\\"') }}"

View File

@@ -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());