override icon shortcode to make the SVGs accessible
This commit is contained in:
parent
35cb6c7def
commit
79e9051db6
1 changed files with 16 additions and 0 deletions
|
@ -19,6 +19,22 @@ module.exports = function(eleventyConfig) {
|
|||
{ name: "solid", path: `${fontawesomePath}/solid` },
|
||||
{ name: "brands", path: `${fontawesomePath}/brands` },
|
||||
],
|
||||
icon: {
|
||||
shortcode: "rawIcon",
|
||||
},
|
||||
});
|
||||
|
||||
// override icon shortcode to make the SVGs accessible
|
||||
eleventyConfig.addAsyncShortcode("icon", async function(input, attrs) {
|
||||
if (!attrs || !("title" in attrs)) {
|
||||
return eleventyConfig.nunjucksAsyncShortcodes.rawIcon(input, attrs);
|
||||
}
|
||||
|
||||
const { title, ...newAttrs } = attrs;
|
||||
newAttrs.role = "img";
|
||||
const svgStr = await eleventyConfig.nunjucksAsyncShortcodes.rawIcon(input, newAttrs);
|
||||
const match = svgStr.match(/(<svg.*?>)(.*$)/s);
|
||||
return match[1] + "<title>" + title + "</title>" + match[2];
|
||||
});
|
||||
|
||||
// process the logo files
|
||||
|
|
Loading…
Reference in a new issue