neaten up shortcode

This commit is contained in:
2023-10-11 20:20:17 +10:30
parent d4ebf696e4
commit 3f2e659778

View File

@ -39,6 +39,10 @@ module.exports = function (eleventyConfig) {
return ''; return '';
}; };
var imageString = "";
var linkString = "";
var videoString = "";
var slug = title var slug = title
.toLowerCase() .toLowerCase()
.trim() .trim()
@ -51,32 +55,38 @@ module.exports = function (eleventyConfig) {
// replace multiple spaces or hyphens with a hyphen // replace multiple spaces or hyphens with a hyphen
.replace(/[\s-]+/g, '-'); .replace(/[\s-]+/g, '-');
return `<hr> if (Array.isArray(link)) {
<p> if (typeof link[0] === 'string') {
<strong>${title}</strong><br> linkString = link.map((l) => `<a href="${l}">link</a><br>`).join(" // ") + '<br>';
${ } else {
// evil nested tertiary this is the worlds least oneline oneliner linkString = link.map((l) => `<a href="${l.link}">${l.title}</a>`).join(" // ") + '<br>';
!link || link == "" ? }
"" : } else if (typeof link === 'string') {
Array.isArray(link) ? linkString = `<a href="${link}">link</a><br>`;
(typeof link[0] === 'string' ? }
link.map((l) => `<a href="${l}">link</a><br>`).join(" // ") + '<br>' :
link.map((l) => `<a href="${l.link}">${l.title}</a>`).join(" // ") + '<br>') : if (Array.isArray(image)) {
`<a href="${link}">link</a><br>` imageString = image.map((i, index) => `<a href="#img_${slug}_${index}"><img src="${i}"/></a>
}${!image || image == "" ? <a href="#_${slug}_${index}" class="lightbox trans" id="img_${slug}_${index}"><img src="${i}"/></a><br>`).join(" ");
"" : } else if (typeof image === 'string') {
Array.isArray(image) ? imageString = `<a href="#img_${slug}"><img src="${image}"/></a>
image.map((i, index) => `<a href="#img_${slug}_${index}"><img src="${i}"/></a><br> <a href="#_${slug}" class="lightbox trans" id="img_${slug}"><img src="${image}"/></a><br>`
<a href="#_${slug}_${index}" class="lightbox trans" id="img_${slug}_${index}"><img src="${i}"/></a>`).join(" ") : }
`<a href="#img_${slug}"><img src="${image}"/></a><br>
<a href="#_${slug}" class="lightbox trans" id="img_${slug}"><img src="${image}"/></a>` if (video) {
}${!video || video == "" ? videoString = `<video autoplay loop muted controls poster="${video.poster}">
"" :
`<video autoplay loop muted controls poster="${video.poster}">
<source src="${video.link}" type="video/mp4"></source> <source src="${video.link}" type="video/mp4"></source>
<img src="${video.poster}"></img> <img src="${video.poster}"></img>
</video><br>` </video><br>`
}${description} }
return `<hr>
<p>
<strong>${title}</strong><br>
${linkString}
${imageString}
${videoString}
${description}
</p>` </p>`
}); });