Skip to content

Commit

Permalink
fix: set the height and width attributes for image resources (#274)
Browse files Browse the repository at this point in the history
Closes #242
  • Loading branch information
razonyang authored Oct 25, 2024
1 parent 36af817 commit 4b09871
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 10 additions & 2 deletions assets/search/js/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class Renderer {
}

return this.statistics
}
}""

private getLang(): string {
if (!this.lang) {
Expand All @@ -63,7 +63,15 @@ export default class Renderer {

icon(page) {
if (page.img) {
return `<img class="search-result-img" src="${this.url(page, page.img)}" />`
let h = ''
let w = ''
if (page.img_h) {
h = ` height="${page.img_h}"`
}
if (page.img_w) {
w = ` width="${page.img_w}"`
}
return `<img class="search-result-img" src="${page.img}"${w}${h} />`
}

return page.kind in params.icons ? params.icons[page.kind] : params.icons.page
Expand Down
3 changes: 2 additions & 1 deletion assets/search/scss/_result.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
}

.search-result-img {
height: 48px;
height: 64px;
width: auto;
}

.search-result-content {
Expand Down
10 changes: 9 additions & 1 deletion layouts/partials/search/index.json.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
{{- if or $page.Params.images ($page.Resources.GetMatch "{*feature*,*cover*,*thumbnail*}") -}}
{{- with partial "_funcs/get-page-images" $page -}}
{{- $img := index . 0 -}}
{{- $item.Set "img" $img.RelPermalink -}}
{{- $item.Set "img" $img.Permalink -}}
{{- with $img.Image -}}
{{- with .Width -}}
{{- $item.Set "img_w" . -}}
{{- end -}}
{{- with .Height -}}
{{- $item.Set "img_h" . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if default true site.Params.search.index_headings -}}
Expand Down

0 comments on commit 4b09871

Please sign in to comment.