-
-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds js
front matter type for arbitrary JavaScript front matter.
#2819
Comments
node
front matter type for node.js JavaScript front matter.
This is shipping with 3.0 as the |
For those curious, this is using https://github.com/zachleat/node-retrieve-globals |
If you have opinions on the name, please let me know! We can’t use |
TIL there is also an existing feature to override the default front matter syntax project-wide: eleventyConfig.setFrontMatterParsingOptions({
language: "node"
}); Now this nunjucks file will use ---
const hi = "hi";
---
{{ hi }} Docs for this shipping here: https://www.11ty.dev/docs/data-frontmatter/#change-the-default-format-project-wide |
Node’s not bad, in my opinion. A thought occurred looking at this again: Astro calls these “component scripts”, so maybe this could be just “script”.
I dunno if I think this is better, just wanted to put it up for debate. |
I don’t actually prefer this but it’s worth noting that |
I dunno if I like One thought that does occur to me about |
lmao they both kinda stink 😅 not terrible tho and bun is aiming for near node compatibility its strange the clarity of that perspective, serverside js being node called from the client |
Very late to this discussion, so not sure if this is already set in stone... but I would cast a very strong +1 towards Using the word "server" (whether in code or file names) as marker for code that is only run on the server and/or at build time is becoming so widely used across other frameworks I think it would be a nice alignment with prior work and be a really helpful transition for those coming to 11ty for the first time. For reference, see: |
Would it make sense to make a breaking change here? Alternatively, I guess
It's worth pointing out that React's data flow goes something like this:
For this reason, I don't think it's necessarily a good idea to borrow the server terminology. If we're looking at other frameworks, Vue's setup scripts might be closer to 11ty's node frontmatter. |
I agree with Mayank about |
I’m coming around to the idea that a breaking change might make sense here for |
My 2¢ Don't mind Do not like |
Ooh these are great call outs –– feeling much less strongly about that +1 now 😅
I hadn't given |
Actually one more (potentially naive) thought/question: Is there any way that the functionality of Aka is there some way of allowing both JS object front matter definition and component script functionality to be integrated under the same markers? An off the cuff example of this could be some type of reserved keyword (i.e. "frontmatter") that if defined/exported will be used as the front matter for the page, otherwise everything else is just part of the "component script."
The only issue with this is that forcing named variable exports to get the original behavior probably strays pretty far into painful breaking change territory. The potential solution is to have some type of check for the existence of only naked JS objects and if found will use the current JS object front matter behavior.
Since I'm new to 11ty I'm almost definitely missing something here, but if anything like is possible that would be my actual actual preference |
… `js` engine. Also works with `javascript` #2819
Alright @hawkticehurst! You’re absolutely right—the approach you suggested was a better solution that doesn’t require a breaking change. The existing I think this is an acceptable way to support the old behavior and the new behavior without using two different engine names here. Implemented on 6623330 In 3.0.0-alpha.15, both of these will be supported on both New: ---js
const title = "My page title";
function currentDate() { … }
--- Old: ---js
{
title: "My page title",
currentDate: function() { … }
}
--- |
node
front matter type for node.js JavaScript front matter.js
front matter type for arbitrary JavaScript front matter.
Notably, per some of the valid naming concerns noted above, the Appreciate y’all! |
* updep: switch node to js frontmatter 11ty/eleventy#2819 (comment)
There’s an example of configuring a custom JavaScript format for frontmatter in the official demos. It adds functionality that is fairly similar to the component scripts in Astro.
It strikes me as something that might be nice to add to the pre-configured frontmatter formats that are shipped with Eleventy. But I have a couple of reservations as well…
First, based on the demo, it looks like it does add a dependency to core:
node-retrieve-globals
.Second, there’s already the
js
format which allows you to specify frontmatter as a single JavaScript object. It’s not exactly the same as thejavascript
format in the demo, but it’s similar enough that I can imagine the difference being confusing. I’m not sure why a person might expect thatjs
lets you define a single objects andjavascript
lets you write a script where all of the variable are exported to the template context.Still, it’s not hard for me to imagine that this would be useful to people. I know a lot of people like the component scripts in Astro.
The text was updated successfully, but these errors were encountered: