From 982bc5a09b6bb257c3472fb5c8013075367e1627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kuna?= <1282324+codecalm@users.noreply.github.com> Date: Sun, 16 Mar 2025 21:39:14 +0100 Subject: [PATCH] Refactor script and modal captures (#2220) --- preview/eleventy.config.mjs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/preview/eleventy.config.mjs b/preview/eleventy.config.mjs index aed1f4f6f..60a2dd61e 100644 --- a/preview/eleventy.config.mjs +++ b/preview/eleventy.config.mjs @@ -591,29 +591,34 @@ export default function (eleventyConfig) { }); }); + let _CAPTURES = {}; + + eleventyConfig.on('beforeBuild', () => { + _CAPTURES = {}; + }); + ['script', 'modal'].forEach((tag) => { eleventyConfig.addPairedShortcode(`capture_${tag}`, function (content, inline) { if (inline) { return content; } - if (!this.page[tag]) { - this.page[tag] = [] + if (!_CAPTURES[tag]) { + _CAPTURES[tag] = [] } - if (!this.page[tag][this.page.url]) { - this.page[tag][this.page.url] = []; + if (!_CAPTURES[tag][this.page.inputPath]) { + _CAPTURES[tag][this.page.inputPath] = []; } - this.page[tag][this.page.url].push(content); + _CAPTURES[tag][this.page.inputPath].push(content); return '' }) eleventyConfig.addShortcode(`${tag}s`, function () { - - if (this.page[tag]) { - return this.page[tag][this.page.url] ? `\n${this.page[tag][this.page.url].join('\n').trim()}\n` : ''; + if (_CAPTURES[tag] && _CAPTURES[tag][this.page.inputPath]) { + return _CAPTURES[tag][this.page.inputPath] ? `\n${_CAPTURES[tag][this.page.inputPath].join('\n').trim()}\n` : ''; } return ''