@codesled/content
Version:
Composable content blocks for Node.js apps — flexible, pluggable, and framework-agnostic.
29 lines (27 loc) • 951 B
JavaScript
function renderBlocks(blocks = []) {
return blocks
.map((block) => {
switch (block.type) {
case "text":
return `<p>${block.content}</p>`;
case "heading":
return `<h2>${block.content}</h2>`;
case "image":
return `<img src="${block.content}" alt="${block.meta.alt || ""}" />`;
case "code":
return `<pre><code>${block.content}</code></pre>`;
case "quote":
return `<blockquote>${block.content}</blockquote>`;
case "divider":
return `<hr />`;
case "video":
return `<video controls src="${block.content}"></video>`;
case "embed":
return `<iframe src="${block.content}" frameborder="0" allowfullscreen></iframe>`;
default:
return "";
}
})
.join("\n");
}
module.exports = renderBlocks;