mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 20:19:13 +00:00
24 lines
607 B
JavaScript
24 lines
607 B
JavaScript
|
|
import { parse } from 'node-html-parser';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Eleventy plugin to add remove elements with <div data-alpha="remove"> from the alpha build.
|
||
|
|
*/
|
||
|
|
export function removeDataAlphaElements(options = {}) {
|
||
|
|
options = {
|
||
|
|
isAlpha: false,
|
||
|
|
...options
|
||
|
|
};
|
||
|
|
|
||
|
|
return function (eleventyConfig) {
|
||
|
|
eleventyConfig.addTransform('remove-data-alpha-elements', content => {
|
||
|
|
const doc = parse(content, { blockTextElements: { code: true } });
|
||
|
|
|
||
|
|
if (options.isAlpha) {
|
||
|
|
doc.querySelectorAll('[data-alpha="remove"]').forEach(el => el.remove());
|
||
|
|
}
|
||
|
|
|
||
|
|
return doc.toString();
|
||
|
|
});
|
||
|
|
};
|
||
|
|
}
|