Skip to content
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

provide JavaScript Layout Templates' data and permalink class members with some useful info #1082

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GerHobbelt
Copy link
Contributor

@GerHobbelt GerHobbelt commented Apr 9, 2020

Provide JavaScript Layout Templates' data and permalink 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 the data member function is in src/Engines/JavaScript.js (the inst.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 the data and permalink members of said _data/layouts/default.11ty.js.

Also there was the surprise mistake of naming the bugger _data/layout/default.js and only finding out it MUST be with .11ty.js extension (another one where #1079 was needed to help me out).

Anyway, these issues look like they come close/near:

…eful info: the inputPath (template), the invoking template instance and the current engine instance. 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.

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.

The meat for making the `permalink` member work as a member function type is in src/Template.js, while the meat for the `data` member function is in src/Engines/JavaScript.js (the `inst.data(...)` call in there).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants