Skip to content

Commit

Permalink
Merge branch 'evayde-chore/reduce-build-time' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
claviska committed Jun 10, 2024
2 parents 9399df6 + 77c482e commit 4120988
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions docs/_utilities/replacer.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
*/

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

return content;
};
13 changes: 7 additions & 6 deletions docs/eleventy.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ module.exports = function (eleventyConfig) {
//
// 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
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
Expand All @@ -140,11 +146,6 @@ module.exports = function (eleventyConfig) {
scrollingTables(doc);
copyCodeButtons(doc); // must be after codePreviews + highlightCodeBlocks
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
content = `<!DOCTYPE html>\n${doc.documentElement.outerHTML}`;
Expand Down

0 comments on commit 4120988

Please sign in to comment.