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

BUGFIX: Fix crashing bug when embeded file changed while in --watch mode #56

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fix crashing bug when embedded file changed while in `--watch` mode (#56)
- Wikilinks should not contain new lines (#54)
- On resolving fn lookup failure, only throw error if page not found (#52)
- Clear internal state before each 11ty build (#51)
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ module.exports = function (eleventyConfig, options = {}) {

const interlinker = new Interlinker(opts);

// TODO: document
// This populates templateConfig with an instance of TemplateConfig once 11ty has initiated it, it's
// used by the template compiler function that's exported by the EleventyRenderPlugin and used
// by the defaultEmbedFn resolving function for compiling embed templates.
eleventyConfig.on("eleventy.config", (cfg) => {
interlinker.templateConfig = cfg;
});
Expand Down
8 changes: 3 additions & 5 deletions src/interlinker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const HTMLLinkParser = require("./html-link-parser");
const WikilinkParser = require("./wikilink-parser");
const {EleventyRenderPlugin} = require("@11ty/eleventy");
const DeadLinks = require("./dead-links");
const {pageLookup} = require("./find-page");

Expand All @@ -21,12 +20,11 @@ module.exports = class Interlinker {
// Map of Wikilink Meta that have been resolved by the WikilinkParser
this.linkCache = new Map();

// TODO: document
// Instance of TemplateConfig loaded by the `eleventy.config` event
this.templateConfig = undefined;
this.extensionMap = undefined;

// TODO: document
this.rm = new EleventyRenderPlugin.RenderManager();
// Instance of EleventyExtensionMap loaded by the `eleventy.extensionmap` event
this.extensionMap = undefined;

this.wikiLinkParser = new WikilinkParser(opts, this.deadLinks, this.linkCache);
this.HTMLLinkParser = new HTMLLinkParser(this.deadLinks);
Expand Down
5 changes: 4 additions & 1 deletion src/resolvers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const {EleventyRenderPlugin} = require("@11ty/eleventy");
const entities = require("entities");
/**
* Default Resolving function for converting Wikilinks into html links.
Expand Down Expand Up @@ -48,7 +49,9 @@ const defaultEmbedFn = async (link, currentPage, interlinker) => {
? frontMatter.content
: `{% layout "${layout}" %} {% block content %} ${frontMatter.content} {% endblock %}`;

const fn = await interlinker.rm.compile(tpl, language, {
const compiler = EleventyRenderPlugin.String;

const fn = await compiler(tpl, language, {
templateConfig: interlinker.templateConfig,
extensionMap: interlinker.extensionMap
});
Expand Down