mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 04:09:12 +00:00
20 lines
710 B
JavaScript
20 lines
710 B
JavaScript
|
|
/**
|
||
|
|
* Eleventy plugin to replace arbitrary text in the page's HTML.
|
||
|
|
*
|
||
|
|
* @param replacement - The terms to replace and what to replace them with. This must be an object (or an array of
|
||
|
|
* objects) containing a `replace` key that's a string or RegExp and a `replaceWith` key that's a string.
|
||
|
|
*/
|
||
|
|
export function replaceTextPlugin(replacements = []) {
|
||
|
|
replacements = Array.isArray(replacements) ? replacements : [replacements];
|
||
|
|
|
||
|
|
return function (eleventyConfig) {
|
||
|
|
eleventyConfig.addTransform('replace-text', function (content) {
|
||
|
|
replacements.forEach(replacement => {
|
||
|
|
content = content.replace(replacement.replace, replacement.replaceWith);
|
||
|
|
});
|
||
|
|
|
||
|
|
return content;
|
||
|
|
});
|
||
|
|
};
|
||
|
|
}
|