mirror of
https://github.com/tabler/tabler.git
synced 2025-12-21 17:34:25 +04:00
Refactor script and modal captures (#2220)
This commit is contained in:
@@ -591,29 +591,34 @@ export default function (eleventyConfig) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let _CAPTURES = {};
|
||||||
|
|
||||||
|
eleventyConfig.on('beforeBuild', () => {
|
||||||
|
_CAPTURES = {};
|
||||||
|
});
|
||||||
|
|
||||||
['script', 'modal'].forEach((tag) => {
|
['script', 'modal'].forEach((tag) => {
|
||||||
eleventyConfig.addPairedShortcode(`capture_${tag}`, function (content, inline) {
|
eleventyConfig.addPairedShortcode(`capture_${tag}`, function (content, inline) {
|
||||||
if (inline) {
|
if (inline) {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.page[tag]) {
|
if (!_CAPTURES[tag]) {
|
||||||
this.page[tag] = []
|
_CAPTURES[tag] = []
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.page[tag][this.page.url]) {
|
if (!_CAPTURES[tag][this.page.inputPath]) {
|
||||||
this.page[tag][this.page.url] = [];
|
_CAPTURES[tag][this.page.inputPath] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.page[tag][this.page.url].push(content);
|
_CAPTURES[tag][this.page.inputPath].push(content);
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
|
|
||||||
eleventyConfig.addShortcode(`${tag}s`, function () {
|
eleventyConfig.addShortcode(`${tag}s`, function () {
|
||||||
|
if (_CAPTURES[tag] && _CAPTURES[tag][this.page.inputPath]) {
|
||||||
if (this.page[tag]) {
|
return _CAPTURES[tag][this.page.inputPath] ? `<!-- BEGIN PAGE ${tag.toUpperCase()}S -->\n${_CAPTURES[tag][this.page.inputPath].join('\n').trim()}\n<!-- END PAGE ${tag.toUpperCase()}S -->` : '';
|
||||||
return this.page[tag][this.page.url] ? `<!-- BEGIN PAGE ${tag.toUpperCase()}S -->\n${this.page[tag][this.page.url].join('\n').trim()}\n<!-- END PAGE ${tag.toUpperCase()}S -->` : '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ''
|
return ''
|
||||||
|
|||||||
Reference in New Issue
Block a user