Add tags in post cards from search results (#895)

* Add tags in post cards from search results

* Use on_card parameter to decide to show the cards or not

* Fix search cards height

* Minor fix

* Fix null tags

* Fix CSS not applied properly in search page

Signed-off-by: hossainemruz <hossainemruz@gmail.com>

---------

Signed-off-by: hossainemruz <hossainemruz@gmail.com>
Co-authored-by: Emruz Hossain <hossainemruz@gmail.com>
This commit is contained in:
Bernat Borràs Civil 2024-02-23 18:37:35 +01:00 committed by GitHub
parent 9f5a44e24e
commit 1ec4cd2688
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 7 deletions

View file

@ -79,6 +79,13 @@ window.addEventListener('DOMContentLoaded', () => {
// pull template from hugo template definition
const templateDefinition = document.getElementById('search-result-template').innerHTML
// replace values
function adaptTags() {
const tags = value.item.tags;
let string = '';
if (tags) tags.forEach((t) => {string += '<li class="rounded"><a href="/tags/' + t.toLowerCase() + '/" class="btn btn-sm btn-info">' + t + "</a></li>"});
return string;
}
const output = render(templateDefinition, {
key,
title: value.item.title,
@ -86,7 +93,7 @@ window.addEventListener('DOMContentLoaded', () => {
date: value.item.date,
summary: value.item.summary,
link: value.item.permalink,
tags: value.item.tags,
tags: adaptTags(),
categories: value.item.categories,
snippet
})