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:
@@ -12,7 +12,7 @@
|
|||||||
eleventyExcludeFromCollections: true
|
eleventyExcludeFromCollections: true
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
{%- set bodyContent = article.template.frontMatter.content -%}
|
{%- set bodyContent = article.inputPath | rawMarkdownBody -%}
|
||||||
{%- set tokens = (bodyContent.length / 4) | round(0, "ceil") -%}
|
{%- set tokens = (bodyContent.length / 4) | round(0, "ceil") -%}
|
||||||
---
|
---
|
||||||
title: "{{ article.data.title | replace('"', '\\"') }}"
|
title: "{{ article.data.title | replace('"', '\\"') }}"
|
||||||
|
|||||||
@@ -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)
|
// Current timestamp filter (for client-side JS buildtime)
|
||||||
eleventyConfig.addFilter("timestamp", () => Date.now());
|
eleventyConfig.addFilter("timestamp", () => Date.now());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user