frjo / hugo-theme-zen

A fast and clean Hugo base theme with css-grid and Hugo pipes support.
https://zen-demo.xdeb.org/
GNU General Public License v2.0
264 stars 75 forks source link

Disable submission dates in Search results #74

Closed arky closed 1 year ago

arky commented 1 year ago

The search results doesn't seem to check if submitted = false. It will always show submitted dates in search results.

example-screenshot

Am using following language specific settings in config/_default/languages.toml

[en]
languageCode = "en-US"
languageName = "English"
weight = 1
contact = "OFDN"
copyright = "© OFDN 2023"
description = "OFDN Library Project"
dateformat = "January 2, 2006"
feedlinks = false
realfavicongenerator = true
relatedposts = true
footer = "OFDN Library Prototype."
imageMaxWidth = 400
mobileMenu = true
poweredby = false
submitted = false
sidebar = true
pluralizelisttitles = false
removePathAccents = true
paginate = 10
paginatePath = "page"
rssLimit = 20
searchform = true
menuInHeader = false 

[or]
languageCode = "or"
languageName = "Odia"
weight = 2
title = "OFDN ଲାଇବ୍ରେରୀ ପ୍ରୋଟୋଟାଇପ୍ |"
description = "OFDN ଲାଇବ୍ରେରୀ ପ୍ରୋଜେକ୍ଟ |"
contact = "Odia OFDN"
copyright = "Odia © OFDN 2023"
dateformat = "January 2, 2006"
feedlinks = false
realfavicongenerator = true
relatedposts = true
footer = "OFDN ଲାଇବ୍ରେରୀ ପ୍ରୋଟୋଟାଇପ୍ |"
imageMaxWidth = 400
mobileMenu = true
poweredby = false
submitted = false
sidebar = true
pluralizelisttitles = false
removePathAccents = true
paginate = 10
paginatePath = "page"
rssLimit = 20
searchform = true
menuInHeader = false 
frjo commented 1 year ago

The search results are not built with Hugo and the standard templates.

The Zen theme use Hugo to construct a search index in json format. The search results are built from that json file with javascript.

To change the search results you need to override the "search" shortcut. See the <template> tag at the bottom of that shortcode.

https://github.com/frjo/hugo-theme-zen/blob/c909fa81394c43accce6f56bc6da84d59da4b2c4/layouts/shortcodes/search.html#L14-L22

arky commented 1 year ago

I have the following code in my 'layouts/shortcodes/search.html'. Modifying the template as follows. Then no search results are shown.

<p class="error message js-hidden">{{ i18n "js_required" }}</p>
<p class="search-loading status message hidden">{{ i18n "search_loading" }}</p>

<div class="search-input hidden">
  <form id="search-form" class="search-form" action="#" method="post" accept-charset="UTF-8" role="search">
    <label for="query" class="visually-hidden">{{ i18n "search_title" }}</label>
    <input type="search" id="query" name="query" class="search-text" placeholder="{{ i18n "search_placeholder" }}" maxlength="128">
    <button type="submit" name="submit" class="form-submit" >{{ i18n "search_title" }}</button>
  </form>
</div>

<div class="search-results"></div>

<template>
  <article class="search-result list-view">
    <header>
      <h2 class="title"><a href="#">Title here</a></h2>
      </header>
    <div class="content">Summary here</div>
  </article>
</template>
frjo commented 1 year ago

Apprently the search js does not like it when you remove things it assumes are there.

To avoid the need to modify the js as well try this. Instead of removing the div with the date, change the class from "submitted" to "hidden", then it will not show.

arky commented 1 year ago

Thank you @frjo I think that is a good stop-gap solution for now. I have few ideas for extending search feature in the next release.