From 1ec4cd2688547cd26b556a0b568fe38459458d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bernat=20Borr=C3=A0s=20Civil?= <70479573+BernatBC@users.noreply.github.com> Date: Fri, 23 Feb 2024 18:37:35 +0100 Subject: [PATCH] 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 --------- Signed-off-by: hossainemruz Co-authored-by: Emruz Hossain --- assets/scripts/pages/search.js | 9 ++++++++- layouts/_default/search.html | 24 ++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/assets/scripts/pages/search.js b/assets/scripts/pages/search.js index cd5eb080c..87cd0c53e 100644 --- a/assets/scripts/pages/search.js +++ b/assets/scripts/pages/search.js @@ -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 += '
  • ' + t + "
  • "}); + 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 }) diff --git a/layouts/_default/search.html b/layouts/_default/search.html index 75aad9829..5877e7ddd 100644 --- a/layouts/_default/search.html +++ b/layouts/_default/search.html @@ -28,28 +28,40 @@ {{ end }} {{ define "content" }} +
    -
    +