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

make all front-matter available in KS rendering #3503

Conversation

peterbe
Copy link
Contributor

@peterbe peterbe commented Apr 12, 2021

Fixes #3258

In principle, this was an easy fix. Now I can make this change in the content:

diff --git a/files/en-us/web/api/headers/index.html b/files/en-us/web/api/headers/index.html
index d7e613f48..72eeaf9b3 100644
--- a/files/en-us/web/api/headers/index.html
+++ b/files/en-us/web/api/headers/index.html
@@ -9,6 +9,7 @@ tags:
   - Headers
   - Interface
   - Reference
+browser-compat: api.Headers
 ---
 <div>{{APIRef("Fetch API")}}</div>
 
@@ -118,7 +119,7 @@ myHeaders.get('Content-Type') // should return 'text/xml'
 
 <h2 id="Browser_compatibility">Browser compatibility</h2>
 
-<p>{{Compat("api.Headers")}}</p>
+<p>{{Compat}}</p>
 
 <h2 id="See_also">See also</h2>
 

and it works! It works because now any key in the front-matter becomes available in that env object you get inside the context of KS rendering.
We used to hardcode the "transfer" of slug, title, and tags. Now it just takes all and everything from the front-matter and makes it available. There is a slight exception for the front-matter tags because it could potentially be undefined but I think the KS macros expects it to always be an array. By leaving it to always fall back on an empty array, no macro code would need to do something like if (!Array.isArray(env.tags)) { or anything like that.
But yes, the env['browser-compat'] might be undefined but this is a new thing so I think it's fair for KS macros to always check for truthy'ness before using it.

I'm not entirely sure what the consequences might be related to KS rendering caching so I'm tempted to make this a draft for @escattone to ponder. But I don't usually make draft PRs if there's nothing left on my to-do list for the branch work.

Copy link
Contributor

@escattone escattone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small but exciting change!

@escattone escattone merged commit 849fcfc into mdn:main Apr 13, 2021
@wbamberg
Copy link
Collaborator

This is amazing :).

@Elchi3
Copy link
Member

Elchi3 commented Apr 14, 2021

Wohooo! Thanks so much Peter and Ryan!

@peterbe peterbe deleted the 3258-make-all-front-matter-available-in-ks-rendering branch April 14, 2021 13:14
@peterbe
Copy link
Contributor Author

peterbe commented Apr 14, 2021

Taking it for a test-drive here: mdn/content#4102

One thing I've never loved about kumascript is that it's actually perfectly fine to use {{Compat}} or {{Compat()}}. It hurts my 22-years Python muscle memory.

peterbe added a commit to peterbe/yari that referenced this pull request Jun 1, 2021
* make all front-matter available in KS rendering

Fixes mdn#3258

* better error handling in case it's falsy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support browser_compatibility as a front matter key
4 participants