chore(docs) - reduce build time

This commit is contained in:
Enrico Gruner
2024-06-09 23:53:52 +02:00
parent 9399df6e19
commit 77c482ed16
2 changed files with 13 additions and 9 deletions

View File

@@ -9,11 +9,14 @@
*/ */
/** /**
* @param {Document} content * @param {String} rawContent
* @param {Replacements} replacements * @param {Replacements} replacements
*/ */
module.exports = function (content, replacements) { module.exports = function (rawContent, replacements) {
let content = rawContent;
replacements.forEach(replacement => { replacements.forEach(replacement => {
content.body.innerHTML = content.body.innerHTML.replaceAll(replacement.pattern, replacement.replacement); content = content.replaceAll(replacement.pattern, replacement.replacement);
}); });
return content;
}; };

View File

@@ -115,7 +115,13 @@ module.exports = function (eleventyConfig) {
// //
// Transforms // Transforms
// //
eleventyConfig.addTransform('html-transform', function (content) { eleventyConfig.addTransform('html-transform', function (rawContent) {
let content = replacer(rawContent, [
{ pattern: '%VERSION%', replacement: customElementsManifest.package.version },
{ pattern: '%CDNDIR%', replacement: cdndir },
{ pattern: '%NPMDIR%', replacement: npmdir }
]);
// Parse the template and get a Document object // Parse the template and get a Document object
const doc = new JSDOM(content, { const doc = new JSDOM(content, {
// We must set a default URL so links are parsed with a hostname. Let's use a bogus TLD so we can easily // We must set a default URL so links are parsed with a hostname. Let's use a bogus TLD so we can easily
@@ -140,11 +146,6 @@ module.exports = function (eleventyConfig) {
scrollingTables(doc); scrollingTables(doc);
copyCodeButtons(doc); // must be after codePreviews + highlightCodeBlocks copyCodeButtons(doc); // must be after codePreviews + highlightCodeBlocks
typography(doc, '#content'); typography(doc, '#content');
replacer(doc, [
{ pattern: '%VERSION%', replacement: customElementsManifest.package.version },
{ pattern: '%CDNDIR%', replacement: cdndir },
{ pattern: '%NPMDIR%', replacement: npmdir }
]);
// Serialize the Document object to an HTML string and prepend the doctype // Serialize the Document object to an HTML string and prepend the doctype
content = `<!DOCTYPE html>\n${doc.documentElement.outerHTML}`; content = `<!DOCTYPE html>\n${doc.documentElement.outerHTML}`;