Skip to content

Commit

Permalink
feat: show page image if present
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Feb 19, 2024
1 parent 1559bcf commit d87ed08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions assets/search/js/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ 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
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 d87ed08

Please sign in to comment.