special case for <use> tag
All checks were successful
/ build (push) Successful in 47s

This commit is contained in:
Nycki 2025-08-21 19:00:09 -07:00
parent 14c5d7d61c
commit 34ef76515c

View file

@ -56,4 +56,19 @@ export default function (eleventyConfig) {
priority: -1, // run last last (after PathToUrl)
},
);
eleventyConfig.addTransform('relative-svg', function(content) {
if (!(this.page.outputPath || '').endsWith('.html')) {
return content;
}
const fromDir = this.url.endsWith("/") ? this.url : path.dirname(this.url);
return content.replaceAll(/<use href="([^"]*)"/g, (_, matchedUrl) => {
let relativePath = path.relative(fromDir, matchedUrl);
if (!relativePath.startsWith(".")) {
relativePath = "./" + relativePath;
}
return `<use href="${relativePath}"`;
});
})
}