Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags in post cards from search results #895

Merged
merged 9 commits into from
Feb 23, 2024
9 changes: 8 additions & 1 deletion assets/scripts/pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,21 @@ 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;
BernatBC marked this conversation as resolved.
Show resolved Hide resolved
let string = '';
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,
hero: value.item.hero,
date: value.item.date,
summary: value.item.summary,
link: value.item.permalink,
tags: value.item.tags,
tags: adaptTags(),
categories: value.item.categories,
snippet
})
Expand Down
21 changes: 15 additions & 6 deletions layouts/_default/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,34 @@
<section class="content-section" id="content-section">
<div class="content container-fluid" id="content">
<div class="container-fluid post-card-holder" id="post-card-holder">
<div id="search-results">
<div id="search-results" style="display: flex;">

<script id="search-result-template" type="text/x-js-template">
<div class="post-card">
<a href="${link}" class="post-card-link">
<div class="card" style="min-height: 352px;"><a href="${link}" class="post-card-link">
<div class="card">
<div class="card-head">
<a href="${link}" class="post-card-link">
<img class="card-img-top" src="${hero}" alt="Card Heading Image">
</a>
</div>
<div class="card-body">
<h5 class="card-title">${title}</h5>
<p class="card-text post-summary">${summary}</p>
<a href="${link}" class="post-card-link">
<h5 class="card-title">${title}</h5>
<p class="card-text post-summary">${summary}</p>
</a>
{{ if site.Params.features.tags.on_card }}
<div class="tags">
<ul style="padding-left: 0;">
${tags}
</ul>
</div>
{{ end }}
</div>
<div class="card-footer">
<span class="float-left">${date}</span>
<a href="${link}" class="float-right btn btn-outline-info btn-sm">Read</a>
</div>
</div>
</a>
</div>
</script>

Expand Down
Loading