11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
17.32k stars 495 forks source link

Expose data cascade in transforms #796

Closed Ryuno-Ki closed 3 years ago

Ryuno-Ki commented 5 years ago

Right now, I'm adding <abbr> tags in abbreviations I use in my markdown files manually. This morning it struck me, that it would be neat if Eleventy would have access to the frontmatter in the transform function (or at the point in a content lifecycle, where it gets injected into a template).

Describe the solution you'd like This way I could declare a key value pair in the frontmatter of an abbreviation to its extended from. Another use case could be to apply microformats2 to certain element (e.g. a checkin) where I only declare a phrase (e.g. „Checked in to <X>”) and have a transform which applies the markup for it.

Describe alternatives you've considered Right now, I'm adding the markup directly. Alternatively I could declare some partials and somehow use them (e.g. as shortcode). But I have bad experiences with that from my WordPress time (template „broken” once the plugin is removed without a reliable way to spot the affected sites).

Additional context As mentioned, it is a quick idea of mine. Feedback welcome :-)

jevets commented 5 years ago

Are you using markdown-it-abbr?

I'd guess that transform is too late in the game for access to front-matter.

(or at the point in a content lifecycle, where it gets injected into a template)

Maybe you could use an intermediate .md layout that includes a list of your abbr definitions, then have that .md layout use the layout you're currently using. Seems a bit redundant, but it could let you keep a single file of all abbr definitions, then let the new .md layout include the abbr definitions which (hopefully) should transform them into appropriate abbr title elements (via markdown-it-abbr).

Another idea: you could consider transforming final HTML files via DOM manipulation. Andy Bell does this in Hylia. js-dom reads Eleventy's final HTML and converts imgs that have title attributes into figure and figcaption elements (and a few other similar things). A cool technique that I've been using recently, too. Just an idea.

And if you disable the DOM transformer at some point in the future, you'll just end up with plain old HTML from markdown, as opposed to some broken looking WP style shortcode like [supermegaplugin_tabs]we forgot to update our posts[/supermegaplugin_tabs].

Ryuno-Ki commented 5 years ago

Hey @jevets, thanks for

Are you using markdown-it-abbr?

No, I haven't heard of it before.

Seems a bit redundant, but it could let you keep a single file of all abbr definitions

That wouldn't help me much (but perhaps in the beginning). Think of cases, where an abbreviation could have different meanings. Say, „IP” as „Internet Protocol” or „Intellectual Property”. That's why I thought putting it in the Frontmatter ;-)

js-dom reads Eleventy's final HTML and converts imgs that have title attributes into figure and figcaption elements (and a few other similar things).

Hm … I have used JS-DOM only for testing. Interesting idea to use it in post-processing!

You've provided me with some more aspects to think over. Thanks for this! Happy first advent!

zachleat commented 3 years ago

I don’t think we would want to limit this to front matter specifically but rather just the entire data cascade result would be easier to implement.

This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.

View the enhancement backlog here. Don’t forget to upvote the top comment with 👍!