From d9c4feb75b0e35ece262a4d8f92b0f8bb7ebdec2 Mon Sep 17 00:00:00 2001 From: "Avery N. Nortonsmith" Date: Wed, 29 Jul 2020 18:32:19 -0400 Subject: [PATCH] Use function for second param to `replace` Should resolve #56. Uses [this strategy](https://stackoverflow.com/a/59697678/6680182) --- src/index.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index 0fa33ea..7529328 100644 --- a/src/index.js +++ b/src/index.js @@ -252,7 +252,7 @@ const compileSlots = (body, slots) => { } const [find, name, fallback] = m; - copy = copy.replace(find, slots[name] || fallback || ''); + copy = copy.replace(find, () => slots[name] || fallback || ''); } body = copy; @@ -263,7 +263,7 @@ const compileSlots = (body, slots) => { } const [find, name] = m; - copy = copy.replace(find, slots[name] || ''); + copy = copy.replace(find, () => slots[name] || ''); } body = copy; @@ -274,12 +274,12 @@ const compileSlots = (body, slots) => { } const [find, fallback] = m; - copy = copy.replace(find, slots.default || fallback || ''); + copy = copy.replace(find, () => slots.default || fallback || ''); } body = copy; // Simple default slots - body = body.replace(patterns.simpleDefaultSlots, slots.default); + body = body.replace(patterns.simpleDefaultSlots, () => slots.default); return body; }; @@ -307,7 +307,7 @@ const compileImport = (body, pattern) => { // Recurse replace = compileTemplate(replace, slots); - body = body.replace(find, replace); + body = body.replace(find, () => replace); } return body; @@ -350,7 +350,7 @@ const compileLinks = (body, path) => { const isCurrent = isCurrentPage(to, path); if (isCurrent || isParentPage(to, path)) { if (attributes.includes('class="')) { - attributes = attributes.replace('class="', `class="${ACTIVE_CLASS} `); + attributes = attributes.replace('class="', () => `class="${ACTIVE_CLASS} `); } else { attributes += ` class="${ACTIVE_CLASS}"`; } @@ -361,7 +361,7 @@ const compileLinks = (body, path) => { } replace = `${content}`; - copy = copy.replace(find, replace); + copy = copy.replace(find, () => replace); } body = copy;