blog/themes/ficurinia/layouts/partials/js_paginator.html

65 lines
2.0 KiB
HTML
Raw Normal View History

2023-04-29 14:12:36 +00:00
<script>
2023-08-15 16:41:03 +00:00
const tagsStr = '{{ i18n "tags" | safeJS }}'
2023-04-29 14:12:36 +00:00
function renderTags(tags) {
if (tags.length <= 0) return '';
2023-08-15 16:41:03 +00:00
let res = `| <span title=''></span>`;
2023-04-29 14:12:36 +00:00
for (let tag of tags) {
// regular space
res += `<a href="/tags/${tag}">#${tag}</a>&#32;`;
}
return res;
}
function renderImage(image, link, alt) {
if (!image) return '';
return `<a href="${link}"><img src="${image}" alt="${alt}" /></a>`;
}
function renderSingleArticle(article) {
2023-08-15 16:41:03 +00:00
{{ if (.Site.Params.tagsInArticlePreview | default true) }}
const tags = renderTags(article.tags)
{{ else }}
const tags = ''
{{ end }}
{{ if .Site.Params.imageInArticlePreview }}
const img = renderImage(article.image, article.link, article.imageAlt)
{{ else }}
const img = ''
{{ end }}
{{ if (site.Params.articleSummary | default true) }}
const continueReadingStr = '{{ i18n "continueReading" | safeJS }}'
const summ = `<div class="articlePreview">
<p>${article.summary}</p>
<p><a href="${article.link}">${continueReadingStr} </a></p>
</div>`
{{ else }}
const summ = ''
{{ end }}
const dateStr = '{{ i18n "date" | safeJS }}'
2023-04-29 14:12:36 +00:00
return `
<article class="card postlistitem">
<div>
<h2>
<a href="${article.link}">${article.title}</a>
</h2>
<p class="date">
2023-08-15 16:41:03 +00:00
<span title='${dateStr}'></span>
2023-04-29 14:12:36 +00:00
${article.date}
2023-08-15 16:41:03 +00:00
${tags}
2023-04-29 14:12:36 +00:00
</p>
2023-08-15 16:41:03 +00:00
${img}
${summ}
2023-04-29 14:12:36 +00:00
</div>
<hr />
</article>
`;
}
function renderArticles(articles) {
let rendered = articles.map(a => renderSingleArticle(a)).join('\n');
document.getElementById('postlist').innerHTML += rendered;
}
</script>