oleeskild / digitalgarden

275 stars 158 forks source link

breakage in links that points to headers #217

Closed bayang closed 10 months ago

bayang commented 10 months ago

Latest release makes my links pointing to headers render as 404 pages with following classes : "internal-link is-unresolved"

I grepped the source code and the only part that sets this classes is .eleventyconfig.js in getAnchorAttributes.

My links look like this :

[[JDR/solo-tools#systèmes de jeu\|solo-tools#systèmes de jeu]]

Which looks fine in obsidian.

The problem seems to start at the following line in the if (filePath.includes("#")) { code block

[fileName, header] = filePath.split("#");

My editor tells me : Unexpected use of comma operator

Ans I think the code breaks at this line.

Maybe destructuring assignment cannot be used like this to overwrite existing variables ?

If I replace it temporarily by the beginner array version :

let parts = filePath.split("#");
    console.log("parts " + parts)
    fileName = parts[0]
    header = parts[1]

The code goes further and then breaks again.

I added the exception to the final catch and logged it :

Error: ENOENT: no such file or directory, open './src/site/notes/JDR/solo-tools#outils/émulateur.md'
at Object.openSync (node:fs:590:3)
at Object.readFileSync (node:fs:458:35)
at getAnchorAttributes (/home/user/perso/digitalgarden/.eleventy.js:62:21)
at getAnchorLink (/home/ubik/perso/digitalgarden/.eleventy.js:33:35)
at /home/user/perso/digitalgarden/.eleventy.js:297:16
at String.replace (<anonymous>)
at Context.<anonymous> (/home/ubik/perso/digitalgarden/.eleventy.js:290:11)
at Context.<anonymous> (/home/ubik/perso/digitalgarden/node_modules/@11ty/eleventy/src/UserConfig.js:235:26)
at Context.<anonymous> (/home/ubik/perso/digitalgarden/node_modules/@11ty/eleventy/src/BenchmarkGroup.js:32:26)
at Context.<anonymous> (/home/ubik/perso/digitalgarden/node_modules/@11ty/eleventy/src/Engines/Nunjucks.js:104:17) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: './src/site/notes/JDR/solo-tools#outils/émulateur.md'
}

The code seems to use the full path with the anchor and the header. The actual file referenced in the stacktrace should be solo-tools.md and the header in the file is outils/émulateur

oleeskild commented 10 months ago

Sorry, this was broken in a recent refactor I did when adding better support for dataview js. I've found the issue and released an update which should fix this, so that headerlinks should work just as they did before. You need to update the template for the fix. Let me know the issue was resolved or not after updating 😄

bayang commented 10 months ago

I deployed with the fix and my links are ok now, thank you for all your work ! :)