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

Add live preview support for nunjucks dependencies #1361

Merged
merged 1 commit into from
Sep 25, 2020

Conversation

ang-zeyu
Copy link
Contributor

@ang-zeyu ang-zeyu commented Sep 20, 2020

What is the purpose of this pull request? (put "X" next to an item, remove the rest)

• [x] Bug fix
• [x] Enhancement to an existing feature

Part of #1353
Fixes #672

What is the rationale for this request?
Live preview does not regenerate pages when a nunjucks dependency has changed (e.g. from {% include ... %}

What changes did you make? (Give an overview)

  • Use the convenient nunjucks https://mozilla.github.io/nunjucks/api.html#load-event api to implement this
  • Patch nunjucks to also emit this event even when the rendered template is accessed from its internal cache
    • this is necessary since multiple files sharing the nunjucks environment may reference the same nunjucks dependency
  • Bust the nunjucks internal cache during live preview page regeneration
    • freebie bug fix: nunjucks dependency removals and changes do not register during live preview even if the page (which depends on these nunjucks dependencies) is regenerated through other means (e.g. force reload option or editing the page) (--force-reload does not reload nunjucks code #672)

Alternative considered:
nunjucks has a watch option https://mozilla.github.io/nunjucks/api.html#configure that recompiles templates on file system events, this:

  • is expensive, requiring initiating one file watcher per nunjucks environment (i.e. per (sub)site), on top of our own
  • only works for file changes and not removals by design
  • we do some processing before nunjucks, making this unusable, as it directly compiles the template from the file

Testing instructions:
nunjucks + live preview works:

  • file change
  • file removal
  • file additions already worked

Proposed commit message: (wrap lines at 72 characters)
Add live preview support for nunjucks dependencies

@ang-zeyu ang-zeyu force-pushed the nunjucks-live-preview branch 4 times, most recently from c2e08e6 to 38856e5 Compare September 24, 2020 15:21
@ang-zeyu ang-zeyu merged commit 70d29b8 into MarkBind:master Sep 25, 2020
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.

--force-reload does not reload nunjucks code
1 participant