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

Plugin no longer works with 11ty 3.0.0-beta #10

Open
jordan-thirus opened this issue Sep 18, 2024 · 1 comment · May be fixed by #11
Open

Plugin no longer works with 11ty 3.0.0-beta #10

jordan-thirus opened this issue Sep 18, 2024 · 1 comment · May be fixed by #11

Comments

@jordan-thirus
Copy link

jordan-thirus commented Sep 18, 2024

I wanted to try upgrading to 3.0.0 which required forcing the install of this plugin to see if it was possible. This plugin fails with the error following error

[11ty] Problem writing Eleventy templates:
[11ty] Unfortunately you’re using code that monkey patched some Eleventy internals and it isn’t async-friendly. Change your code to use the async `read()` method on the template instead!
[11ty] 
[11ty] Original error stack trace: Error: Unfortunately you’re using code that monkey patched some Eleventy internals and it isn’t async-friendly. Change your code to use the async `read()` method on the template instead!
[11ty]     at get frontMatter [as frontMatter] (file:///home/user/github/projects/site/node_modules/@11ty/eleventy/src/TemplateContent.js:154:10)
[11ty]     at /home/user/github/projects/site/node_modules/eleventy-plugin-backlinks/lib/get-backlinks.js:18:52
[11ty]     at Object.backlinks (/home/user/github/projects/site/node_modules/eleventy-plugin-backlinks/index.js:41:38)
...

I believe what needs to happen is that the link in get-backlinks.js needs to use (await otherNote.template.read()) instead of accessing the frontmatter directly.

@jordan-thirus
Copy link
Author

I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/eleventy-plugin-backlinks/lib/get-backlinks.js b/node_modules/eleventy-plugin-backlinks/lib/get-backlinks.js
index 87b0c18..3a9a814 100644
--- a/node_modules/eleventy-plugin-backlinks/lib/get-backlinks.js
+++ b/node_modules/eleventy-plugin-backlinks/lib/get-backlinks.js
@@ -6,7 +6,7 @@ function caselessCompare(a, b) {
 const wikilinkRegExp = /\[\[\s*([^\[\]\|\n\r]+)(\|[^\[\]\|\n\r]+)?\s*\]\]/g
 
 module.exports = function (options) {
-    return ({ collections, page }) => {
+    return async ({ collections, page }) => {
         const { notes } = collections;
 
         const fileStem = page.filePathStem.replace(`/${options.folder}/`, '');
@@ -15,7 +15,7 @@ module.exports = function (options) {
 
         // Search the other notes for backlinks
         for (const otherNote of notes) {
-            const noteContent = otherNote.template.frontMatter.content;
+            const noteContent = (await otherNote.template.read()).content;
 
             // Get all links from otherNote
             const outboundLinks = (noteContent.match(wikilinkRegExp) || [])

This issue body was partially generated by patch-package.

@jordan-thirus jordan-thirus linked a pull request Sep 28, 2024 that will close this issue
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 a pull request may close this issue.

1 participant