Skip to content

Commit

Permalink
Option to override project-wide front matter syntax default #2819
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Nov 3, 2023
1 parent 6360c0e commit 84610f0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class UserConfig {
this.dataFileDirBaseNameOverride = false;

this.frontMatterParsingOptions = {
// project-wide default.
// language: "yaml",

// supplementary engines
engines: {
node: (frontMatterCode, { filePath }) => {
let vm = new RetrieveGlobals(frontMatterCode, {
Expand Down
17 changes: 17 additions & 0 deletions test/JavaScriptFrontMatterTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,20 @@ test("Custom Front Matter Parsing Options (using JavaScript node-retrieve-global

t.is(result[0]?.content, `<div>Hi</div><div>Bye</div>`);
});

test("Custom Front Matter Parsing Options (using JavaScript node-retrieve-globals), override project-wide front matter default.", async (t) => {
let elev = new Eleventy("./test/stubs/script-frontmatter/test-default.njk", "./_site", {
config: (eleventyConfig) => {
eleventyConfig.setFrontMatterParsingOptions({
language: "node",
});
},
});
elev.setIsVerbose(false);

let result = await elev.toJSON();

t.deepEqual(result.length, 1);

t.is(result[0]?.content, `<div>Hi</div><div>Bye</div>`);
});
8 changes: 8 additions & 0 deletions test/stubs/script-frontmatter/test-default.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
import {noopSync} from "@zachleat/noop";
const myString = "Hi";

// export a function
function myFunction() { return "Bye" }
---
<div>{{ noopSync(myString) }}</div><div>{{ myFunction() }}</div>

0 comments on commit 84610f0

Please sign in to comment.