mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-20 17:32:15 +03:00
29 lines
813 B
JavaScript
29 lines
813 B
JavaScript
|
module.exports = function createCard(card) {
|
||
|
const {name, type} = card;
|
||
|
|
||
|
return {
|
||
|
name,
|
||
|
type,
|
||
|
render({env, payload, options}) {
|
||
|
const {dom} = env;
|
||
|
const cleanName = name.replace(/^card-/, '');
|
||
|
|
||
|
const cardOutput = card.render({env, payload, options});
|
||
|
|
||
|
if (!cardOutput) {
|
||
|
return cardOutput;
|
||
|
}
|
||
|
|
||
|
const beginComment = dom.createComment(`kg-card-begin: ${cleanName}`);
|
||
|
const endComment = dom.createComment(`kg-card-end: ${cleanName}`);
|
||
|
const fragment = dom.createDocumentFragment();
|
||
|
|
||
|
fragment.appendChild(beginComment);
|
||
|
fragment.appendChild(cardOutput);
|
||
|
fragment.appendChild(endComment);
|
||
|
|
||
|
return fragment;
|
||
|
}
|
||
|
};
|
||
|
};
|