Skip to content

Commit

Permalink
.eleventy.js: allow paths that start with .. to be rewritten from .md
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtynjala committed Aug 19, 2024
1 parent c558d5b commit 49c06d7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,23 @@ module.exports = function (eleventyConfig) {
) {
const lastSlashIndex = this.inputPath.lastIndexOf("/");
const startURL = this.inputPath.substring(1, lastSlashIndex + 1);
const lastLastSlashIndex = this.inputPath.lastIndexOf(
"/",
lastSlashIndex - 1
);
const startURLParent =
lastLastSlashIndex !== -1
? this.inputPath.substring(1, lastLastSlashIndex + 1)
: startURL;
return content
.replace(
/<a( class="[\w\-]+")? href="\.?\.\/([\w\-\/]+)\.md(#[\w+\-]+)?"/g,
/<a( class="[\w\-]+")? href="\.\/([\w\-\/]+)\.md(#[\w+\-]+)?"/g,
`<a$1 href="${startURL}$2/$3"`
)
.replace(
/<a( class="[\w\-]+")? href="\.\.\/([\w\-\/]+)\.md(#[\w+\-]+)?"/g,
`<a$1 href="${startURLParent}$2/$3"`
)
.replace("/index/", "/");
}
return content;
Expand Down

0 comments on commit 49c06d7

Please sign in to comment.