added optional js powered search
This commit is contained in:
parent
cfad046bb8
commit
f51db60b35
8 changed files with 159 additions and 43 deletions
|
|
@ -1,48 +1,7 @@
|
|||
{{ if .Site.Params.infiniteScrolling }}
|
||||
{{- partial "js_paginator.html" . -}}
|
||||
<script>
|
||||
var nextPage = '/index.json';
|
||||
function renderTags(tags) {
|
||||
if (tags.length <= 0) return '';
|
||||
let res = '| <span title="tags"> </span>';
|
||||
for (let tag of tags) {
|
||||
res += `<a href="/tags/${tag}">#${tag}</a>
|
||||
`;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
function renderImage(image) {
|
||||
if (!image) return '';
|
||||
return `<img src="${image}" />`
|
||||
}
|
||||
function renderSingleArticle(article) {
|
||||
if (article.ignore) return '';
|
||||
return `
|
||||
<article class="card postlistitem {{ if .Site.Params.discreteCards }}discrete{{ end }}">
|
||||
<div>
|
||||
<h2>
|
||||
<a href="${article.link}">${article.title}</a>
|
||||
</h2>
|
||||
<p class="date">
|
||||
<span title="Date"> </span>
|
||||
${article.date}
|
||||
${renderTags(article.tags)}
|
||||
</p>
|
||||
{{ if .Site.Params.imageInArticlePreview }}
|
||||
${renderImage(article.image)}
|
||||
{{end}}
|
||||
<div class="articlePreview">
|
||||
<p>${article.summary}</p>
|
||||
<p><a href="${article.link}">Continue reading </a></p>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
</article>
|
||||
`;
|
||||
}
|
||||
function renderArticles(articles) {
|
||||
let rendered = articles.map(a => renderSingleArticle(a)).join('\n');
|
||||
document.getElementById('postlist').innerHTML += rendered;
|
||||
}
|
||||
function getNext(first=false) {
|
||||
if (!nextPage) return;
|
||||
fetch(nextPage).then(res => res.json())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue