provide JavaScript Layout Templates' data
and permalink
class members with some useful info
#1082
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Provide JavaScript Layout Templates'
data
andpermalink
class members with some useful info: the inputPath (template), the invoking template instance and the current engine instance.permalink
Relevant documentation which drove this change: https://www.11ty.dev/docs/languages/javascript/#permalink-function -- without the change, the
permalink
member in a_data/layouts/layout.js
layout template will fail when it's made a function like the documentation says it can. (The magic line there being https://github.com/11ty/eleventy/compare/master...GerHobbelt:custom-permalinks?expand=1#diff-af43fd5417c10edb3b7199d7c847be65R119)data
Extra are the extra parameters passed into such a class'
data
member function: template and engine. For that, a few other classes needed to have their APIs changed as well.(Magic line: https://github.com/11ty/eleventy/compare/master...GerHobbelt:custom-permalinks?expand=1#diff-34fe2185370965f1cbbd2d8e5e0f3e97R98)
The meat for making the
permalink
member work as a member function type is in src/Template.js, while the meat for thedata
member function is in src/Engines/JavaScript.js (theinst.data(...)
call in there).Related issues
While working on this I did an issue search (including closed ones) on the 11ty repo in hopes to find someone had encountered the same and tackled it. Alas, not entirely: what I wanted was 11ty to produce URIs which are not exactly "cool" in the perception of 11ty, but which are at least pre/postfixed with a content hash for each page, kinda like 'immutable URIs': every URI has guaranteed never changing content.
After a few iterations I went for the custom dynamic permalink + JavaScript Layout Template approach, defining a site-global template in
_data/layouts/default.11ty.js
along the lines of https://www.11ty.dev/docs/languages/javascript/#optional-data-method (and onwards in that page). The result was a number of failures, including the lack of template (and engine) info in both thedata
andpermalink
members of said_data/layouts/default.11ty.js
.Anyway, these issues look like they come close/near: