diff options
author | tdro <tdro@noreply.example.com> | 2022-06-01 19:16:58 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-06-01 19:16:58 -0400 |
commit | 473a08150b875112c522522e21fb542d3ec26736 (patch) | |
tree | ec1d5f7c9e7ce80d5d2073490ff6a35f5351b6a1 | |
parent | dff47d17bb0ed4479bfb187b19ba1c8b1fa61226 (diff) | |
download | canory-473a08150b875112c522522e21fb542d3ec26736.tar.gz canory-473a08150b875112c522522e21fb542d3ec26736.tar.bz2 canory-473a08150b875112c522522e21fb542d3ec26736.zip |
themes/default/layouts: Handle image search errors
Namespace 404 image processing.
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | assets/css/default.css | 4 | ||||
-rw-r--r-- | themes/default/layouts/_default/_markup/render-image.html | 14 | ||||
-rw-r--r-- | themes/default/layouts/partials/author-card.html | 11 | ||||
-rw-r--r-- | themes/default/layouts/partials/author-header.html | 20 | ||||
-rw-r--r-- | themes/default/layouts/partials/author-picture.html | 34 | ||||
-rw-r--r-- | themes/default/layouts/partials/context-profile.html | 14 | ||||
-rw-r--r-- | themes/default/layouts/partials/profile.html | 4 |
8 files changed, 64 insertions, 41 deletions
@@ -35,7 +35,9 @@ else endif test: - validatornu public/index.html + validatornu \ + public/index.html \ + public/default/index.html icons: rm -rf static/icons diff --git a/assets/css/default.css b/assets/css/default.css index 0f81b68..89071f6 100644 --- a/assets/css/default.css +++ b/assets/css/default.css @@ -807,11 +807,11 @@ micro-header-description { flex: 6; } -micro-header h1 { +micro-header h2 { margin-bottom: 0.25rem; + font-size: 700; } -micro-header h2, micro-header h3 { font-weight: 400; color: #444; diff --git a/themes/default/layouts/_default/_markup/render-image.html b/themes/default/layouts/_default/_markup/render-image.html index d2a9ff7..fd83d75 100644 --- a/themes/default/layouts/_default/_markup/render-image.html +++ b/themes/default/layouts/_default/_markup/render-image.html @@ -1,23 +1,23 @@ {{- $source := $.Destination | safeURL -}} -{{- $localPath := print "content/" $source -}} +{{- $local := print "content/" $source -}} {{- $remoteImage := resources.GetRemote $source -}} {{- $width := "" -}} {{- $height := "" -}} {{- with $remoteImage -}} {{- with .Err -}} - {{- if fileExists $localPath -}} - {{- $localImage := imageConfig $localPath -}} - {{- with $localImage -}} + {{- if fileExists $local -}} + {{- $404image := imageConfig $local -}} + {{- with $404image -}} {{- $width = .Width -}} {{- $height = .Height -}} {{- end -}} {{ $source = print ("" | absURL) $source }} {{- else -}} {{- $source = print "/images/404.png" -}} - {{- $localPath = print "static/" $source -}} - {{- $localImage := imageConfig $localPath -}} - {{- with $localImage -}} + {{- $local = print "static/" $source -}} + {{- $404image := imageConfig $local -}} + {{- with $404image -}} {{- $width = .Width -}} {{- $height = .Height -}} {{- end -}} diff --git a/themes/default/layouts/partials/author-card.html b/themes/default/layouts/partials/author-card.html index e2a2623..23e007a 100644 --- a/themes/default/layouts/partials/author-card.html +++ b/themes/default/layouts/partials/author-card.html @@ -5,7 +5,16 @@ <figure> <a title="{{ .Data.name }}" href="{{ "" | absURL }}/{{ .Data.user }}"> <picture> - <img alt="{{ .Data.name }}" src="{{ "" | absURL }}/{{ .Data.user }}/media/profile/picture.png" /> + <img + alt="{{ .Data.name }}" + {{- if fileExists (print "content/" .Data.user "/media/profile/picture.png") }} + src="{{ "" | absURL }}/{{ .Data.user }}/media/profile/picture.png" + {{ else }} + {{- $404origin := print "/images/404.png" }} + {{- $404image := imageConfig (print "static/" $404origin) }} + src="{{ $404origin }}" + {{- end -}} + /> </picture> </a> </figure> diff --git a/themes/default/layouts/partials/author-header.html b/themes/default/layouts/partials/author-header.html index f987560..174d057 100644 --- a/themes/default/layouts/partials/author-header.html +++ b/themes/default/layouts/partials/author-header.html @@ -1,10 +1,20 @@ -{{- $file := "/profile/header.jpg" -}} -{{- $image := imageConfig (print "content/" (partial "author-media-path.html" .) $file) -}} +{{- $file := "/profile/header.jpg" -}} +{{- $path := print "content/" (partial "author-media-path.html" .) $file -}} -<img +{{- $404origin := print "/images/404.png" -}} +{{- $404image := imageConfig (print "static/" $404origin) -}} + +<img loading="lazy" + {{- if fileExists $path }} + {{ $image := imageConfig $path -}} width="{{ $image.Width }}" height="{{ $image.Height }}" - alt="{{ partial "author-name.html" . }}" - src="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}{{ $file }}" + src="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}{{ $file }}" + {{- else }} + width="{{ $404image.Width }}" + height="{{ $404image.Height }}" + src="{{ $404origin }}" + {{- end }} + alt="{{ partial "author-name.html" . }}" /> diff --git a/themes/default/layouts/partials/author-picture.html b/themes/default/layouts/partials/author-picture.html index e288410..88dc0df 100644 --- a/themes/default/layouts/partials/author-picture.html +++ b/themes/default/layouts/partials/author-picture.html @@ -1,12 +1,18 @@ -{{- $file := "/profile/picture.png" -}} -{{- $image := imageConfig (print "content/" (partial "author-media-path.html" .) $file) -}} +{{- $file := "/profile/picture.png" -}} +{{- $path := print "content/" (partial "author-media-path.html" .) $file -}} -{{- with .Params.feed -}} -{{ else }} -<source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.png" type="image/png" /> -<source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.jpg" type="image/jpeg" /> -<source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.webp" type="image/webp" /> -{{ end }} +{{- $404origin := print "/images/404.png" -}} +{{- $404image := imageConfig (print "static/" $404origin) -}} + +{{- if fileExists $path }} + {{- $image := imageConfig $path -}} + {{- with .Params.feed -}} + {{ else }} + <source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.png" type="image/png" /> + <source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.jpg" type="image/jpeg" /> + <source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.webp" type="image/webp" /> + {{ end }} +{{- end -}} <img loading="lazy" @@ -16,9 +22,17 @@ alt="{{ .name }}" src="{{ .image }}" {{ else }} + {{ if fileExists $path }} + {{- $image := imageConfig $path -}} width="{{ $image.Width }}" height="{{ $image.Height }}" - alt="{{ partial "author-name.html" . }}" src="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}{{ $file }}" - {{ end }} + {{- else -}} + width="{{ $404image.Width }}" + height="{{ $404image.Height }}" + src="{{ $404origin }}" + {{- end }} + alt="{{ partial "author-name.html" . }}" + {{ end -}} /> +{{- /* This comment removes trailing newlines and white spaces. */ -}} diff --git a/themes/default/layouts/partials/context-profile.html b/themes/default/layouts/partials/context-profile.html index d96b641..3647ba2 100644 --- a/themes/default/layouts/partials/context-profile.html +++ b/themes/default/layouts/partials/context-profile.html @@ -11,19 +11,7 @@ <a title="{{ $author.name }}" href="{{ .Site.BaseURL }}/{{ $author.user }}"> {{- end -}} <picture> - {{- with .Params.feed -}} - <img - width="64" - height="64" - alt="{{ .name }}" - src="{{ .image }}" - /> - {{ else }} - <img - alt="{{ $author.name }}" - src="{{ .Site.BaseURL }}/{{ $author.user }}/media/profile/picture.png" - /> - {{ end }} + {{ partial "author-picture" . }} </picture> </a> </figure> diff --git a/themes/default/layouts/partials/profile.html b/themes/default/layouts/partials/profile.html index ee9efe6..ffcc677 100644 --- a/themes/default/layouts/partials/profile.html +++ b/themes/default/layouts/partials/profile.html @@ -16,8 +16,8 @@ <section> <micro-header-title> - <h1>{{ $author.name }}</h1> - <h2>@{{ $author.user }}</h2> + <h2>{{ $author.name }}</h2> + <h3>@{{ $author.user }}</h3> </micro-header-title> <micro-header-description> <p> |