Skip to content

Commit

Permalink
feat: show page image if present (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Feb 19, 2024
1 parent 1559bcf commit 0a36bdb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions assets/search/js/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export default class Renderer {
}

icon(page) {
if (page.img) {
return `<img class="search-result-img" src="${page.img}" />`
}

return page.kind in params.icons ? params.icons[page.kind] : params.icons.page
}

Expand Down
4 changes: 4 additions & 0 deletions assets/search/scss/_result.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
}
}

.search-result-img {
max-height: 48px;
}

.search-result-content {
display: flex;
flex: 1;
Expand Down
2 changes: 1 addition & 1 deletion hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ notAlternative = true
[module]
[module.hugoVersion]
extended = true
min = "0.111.3"
min = "0.121.0"

[[module.imports]]
path = "github.com/hugomods/i18n-js"
Expand Down
13 changes: 10 additions & 3 deletions layouts/partials/search/index.json.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@
{{- $item.Set "lang" .Language.Lang -}}
{{- $item.Set "url" (cond $multihost .Permalink .RelPermalink) -}}
{{- $item.Set "date" .Date.Unix -}}
{{- if $years }}
{{- $item.Set "year" (.Date.Format "2006") }}
{{- end }}
{{- if $years -}}
{{- $item.Set "year" (.Date.Format "2006") -}}
{{- end -}}
{{/* Image */}}
{{- if or $page.Params.images ($page.Resources.GetMatch "{*feature*,*cover*,*thumbnail*}") -}}
{{- with partial "_funcs/get-page-images" $page -}}
{{- $img := index . 0 -}}
{{- $item.Set "img" (cond $multihost $img.Permalink $img.RelPermalink) -}}
{{- end -}}
{{- end -}}
{{- $item.Set "headings" (partialCached "search/functions/parse-headings" . .) -}}
{{/* Taxonomies */}}
{{- range $name, $taxonomy := site.Taxonomies -}}
Expand Down

0 comments on commit 0a36bdb

Please sign in to comment.