-
Notifications
You must be signed in to change notification settings - Fork 1
Tweaking custom Nunjucks env #1
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| {% block head %} | ||
| <meta charset="utf-8"> | ||
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
| <title>{{ title }}</title> | ||
| <title>{{ title or "NO TITLE" }}</title> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was seemingly causing errors due to |
||
| <link href="https://unpkg.com/prismjs@1.20.0/themes/prism-okaidia.css" rel="stylesheet"> | ||
| <link rel="stylesheet" href="/assets/css/style.css?v={{ site.github.build_revision}}"> | ||
| <!-- Build Revision: {{ site.github.build_revision }} & Sha: {{ site.github.build_sha }} --> | ||
|
|
@@ -32,7 +32,7 @@ | |
| {% else %} | ||
| <!-- else mode --> | ||
| {% endif %} | ||
| <h1 class="header">{{ title }}</h1> | ||
| <h1 class="header">{{ title or "NO TITLE" }}</h1> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. One template has |
||
| <p class="header">{{ description }}</p> | ||
|
|
||
| {% endblock %} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| {% extends "base.njk" %} | ||
|
|
||
| {%- from "postList/macros.njk" import postList -%} | ||
|
|
||
| {% block postcontent %} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,10 @@ | |
| "subtitle": "Notes on various projects", | ||
| "url": (function(){ return process.env.DOMAIN + "/" })(), | ||
| "feedUrl": (function(){ return process.env.DOMAIN + "/rss/" })(), | ||
| "lastBuildDate": (function(){ | ||
| var date = new Date(); | ||
| return date.toUTCString() | ||
| })(), | ||
| "lastBuildDate": (function(){ | ||
| var date = new Date(); | ||
| return date.toUTCString() | ||
| })(), | ||
| "author": { | ||
| "name": "Aram Zucker-Scharff", | ||
| "email": "aramdevblog@aramzs.me" | ||
|
|
@@ -31,7 +31,7 @@ | |
| <title>{{ metadata.title }}</title> | ||
| <atom:link href="{{ metadata.feedUrl }}" rel="self" type="application/rss+xml" /> | ||
| <link>{{ metadata.url }}</link> | ||
| <description>{{ subtitle }}</description> | ||
| <description>{{ metadata.subtitle }}</description> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was throwing errors due to -{{ subtitle }}
+{{ metadata.subtitle }} |
||
| <lastBuildDate>{{ metadata.lastBuildDate }}</lastBuildDate> | ||
| <language>en-US</language> | ||
| <sy:updatePeriod>hourly</sy:updatePeriod> | ||
|
|
@@ -48,10 +48,10 @@ | |
| <pubDate>{{ post.date.toUTCString() }}</pubDate> | ||
| <dc:creator>{{ metadata.author.name }}</dc:creator> | ||
| <guid isPermaLink="true">{{ absolutePostUrl }}</guid> | ||
| <description>{{ post.data.excerpt }}</description> | ||
| <description>{{ post.data.excerpt or "???" }}</description> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here… I guess some post didn't have an |
||
| <content:encoded><![CDATA[{{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) | safe }}]]></content:encoded> | ||
| {%- for tag in post.tags %} | ||
| <category><![CDATA[tag]]></category> | ||
| <category><![CDATA[{{tag}}]]></category> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't remember why I changed this. I don't think it broke anything. Just looked funny without the |
||
| {%- endfor %} | ||
| </item> | ||
| {%- endfor %} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,10 +111,10 @@ And I can also change my passthroughs in `.eleventy.js`. | |
|
|
||
| ```javascript | ||
| eleventyConfig.addPassthroughCopy({ | ||
| "dinky/_sass": "sass/dinky/_sass", | ||
| "dinky/_sass": "sass/dinky/_sass" | ||
| }); | ||
| eleventyConfig.addPassthroughCopy({ | ||
| "src/_sass": "sass/src/_sass", | ||
| "src/_sass": "sass/src/_sass" | ||
| }); | ||
| ``` | ||
|
|
||
|
|
@@ -124,9 +124,11 @@ If this works correctly on publish, it will resolve the last of my base requirem | |
|
|
||
| Ok, I was thinking about how to handle build-time cache-breaking and realized that there's likely a way to handle getting a cache-break variable at the build stage. There's [a plugin for Jekyll to do it](https://github.com/jekyll/github-metadata), it looks like [it does so at least partially via the Github API](https://github.com/jekyll/github-metadata/blob/master/docs/authentication.md). It gets [a pretty good list of data too](https://github.com/jekyll/github-metadata/blob/master/docs/site.github.md). There's also [the "Github Context" which is available to GitHub actions](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context). I could call the API during build time, which is what it appears that Jekyll is doing (I didn't really look too deeply into the plugin). But if this data is available in the Actions context... couldn't I export it as a environment variable? Why not try adding that to the Github Actions script? | ||
|
|
||
| {% raw %} | ||
| ```yaml | ||
| - run: export GITHUB_HEAD_SHA=${{ github.run_id }} | ||
| ``` | ||
| {% endraw %} | ||
|
Comment on lines
+127
to
+131
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, thanks for the catch here! |
||
|
|
||
| Now I should be able to call this in my site data, right? So I'll update the file at `src/_data/site.js`. | ||
|
|
||
|
|
@@ -150,13 +152,15 @@ Well... the Sass sitemaps built properly, but none of the Github Actions env stu | |
|
|
||
| What if I set the `env` at the level of job? I think this means I could prob use `GITHUB_SHA`, but I want to see what works. | ||
|
|
||
| {% raw %} | ||
| ```yaml | ||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| MY_GITHUB_RUN_ID: ${{ github.run_id }} | ||
| ``` | ||
| {% endraw %} | ||
|
Comment on lines
+155
to
+163
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above, where Nunjucks tries to evaluate |
||
|
|
||
| Ah, that did it, so now I know how to use both! | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inspired by another 11ty issue that you commented on, but I'm sure the
Nunjucks.FileSystemLoaderapproach works just as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdehaan I was able to get everything to work with your changes and this configuration but.... the thing I don't understand is why the other way with
new Nunjucks.FileSystemLoader(doesn't seem to work.This matches what I've seen elsewhere and the given documentation, but I tried it with absolute and relative paths, and it didn't load the folders properly.
This should work right? But it doesn't seem to read the paths. The site builds fine this way, but I am somewhat disappointed I couldn't get it working the original way, or figure out why it isn't working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might not be following. I recloned your repo and built it locally and it seems to work for me (well, except for the Sass stuff, I had to comment out Sass in .eleventy.js):
OUTPUT
And I think the
{% include %}was working as expected. It built fine, and the tag pages seem to render like I thought (since that might have been the onlyincludestatement I found:via