Skip to content

Commit

Permalink
Push once and prepend
Browse files Browse the repository at this point in the history
  • Loading branch information
thewebartisan7 committed Oct 18, 2022
1 parent 112ccde commit 1cfe598
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,24 @@ function setFilledSlots(currentNode, slots, {slot}) {
*/
function processPushes(tree, content, {push}) {
match.call(tree, {tag: push}, pushNode => {
if (!pushNode.attrs || !pushNode.attrs.name) {
throw new Error(`[components] Push <${push}> tag must have an attribute "name".`);
}

if (!content[pushNode.attrs.name]) {
content[pushNode.attrs.name] = [];
}

content[pushNode.attrs.name].push(pushNode.content);
const pushContent = render(pushNode.content);

if (typeof pushNode.attrs.once === 'undefined' || !content[pushNode.attrs.name].includes(pushContent)) {
if (typeof pushNode.attrs.prepend === 'undefined') {
content[pushNode.attrs.name].push(pushContent);
} else {
content[pushNode.attrs.name].unshift(pushContent);
}
}

pushNode.tag = false;
pushNode.content = null;

Expand Down

0 comments on commit 1cfe598

Please sign in to comment.