Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Update for minimal-test-theme updates
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel F. Dickinson <[email protected]>
  • Loading branch information
danielfdickinson committed Jul 17, 2023
1 parent 3de7025 commit 2ef03f4
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 27 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ public
resources
node_modules
.hugo_build.lock
html-validate.log
check-links.log
hugo-audit.log
md-lint.log
hugo-audit.log
*.log
*.jpg
*.png
*.jpeg
Expand Down
4 changes: 4 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,7 @@ target = "i18n"
[[module.imports.mounts]]
source = "archetypes"
target = "archetypes"

[[module.mounts]]
source = "assets/css/custom"
target = "assets/css/custom"
3 changes: 1 addition & 2 deletions exampleSite/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ go 1.20

require (
github.com/danielfdickinson/image-handling-mod-demo v0.0.0-20230510044803-cd4236a91ee2 // indirect
github.com/danielfdickinson/link-handling-mod-hugo-dfd v0.3.3-0.20221028012233-aa14c648c5a2 // indirect
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-0.20230510035937-5d1cad314bb2 // indirect
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-alpha.4 // indirect
)
8 changes: 2 additions & 6 deletions exampleSite/go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
github.com/danielfdickinson/image-handling-mod-demo v0.0.0-20230509133327-e451b1695fa1 h1:5o/znepGEduxv0v7b6zw3nBBPaWnEF2C1mHBuKRN7Aw=
github.com/danielfdickinson/image-handling-mod-demo v0.0.0-20230509133327-e451b1695fa1/go.mod h1:qx251KbyTQVhEg03K8en+fNbFNK4Vq8dmqiqndm98Hg=
github.com/danielfdickinson/image-handling-mod-demo v0.0.0-20230510044803-cd4236a91ee2 h1:VgZz20xxsP9rkG211/0Y8ONXsKNyA6MjFzHASCU2ERs=
github.com/danielfdickinson/image-handling-mod-demo v0.0.0-20230510044803-cd4236a91ee2/go.mod h1:JEHjx5TqNrs7KW89wC2H5ET+I6nTJUyleLi9XhbIfE4=
github.com/danielfdickinson/image-handling-mod-hugo-dfd v0.0.0-20230502185344-ad0d7937d90f/go.mod h1:PKb7pGYDJO23NhRgFAf25DxUqELpEHHidbLBCwte09Y=
github.com/danielfdickinson/image-handling-mod-hugo-dfd v0.0.0-20230510042222-1bce782a3bf0/go.mod h1:PKb7pGYDJO23NhRgFAf25DxUqELpEHHidbLBCwte09Y=
github.com/danielfdickinson/link-handling-mod-hugo-dfd v0.3.3-0.20221028012233-aa14c648c5a2 h1:e1kf4nRllGvzSDz6OvHbfCgoANBGUH95NsOAtNrCAMw=
github.com/danielfdickinson/link-handling-mod-hugo-dfd v0.3.3-0.20221028012233-aa14c648c5a2/go.mod h1:ajYr1qZHU5FJloKLT9rF8jSzKhuv5uSzQ/kA5M1vsY8=
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-0.20230508152613-76634213f5cd/go.mod h1:37XkrDengUFYzMKRN7XU6V3G2AtecY3z+Z0nzQ0Pv20=
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-0.20230510035937-5d1cad314bb2 h1:9cLKZ7vzADUPA7PDlUsSHEJape9mRGJScxEJLieA1kw=
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-0.20230510035937-5d1cad314bb2/go.mod h1:37XkrDengUFYzMKRN7XU6V3G2AtecY3z+Z0nzQ0Pv20=
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-alpha.4 h1:VnJaz6DS8bLIZQwO8R6cdFLsPJIuypka6Qp81les2XY=
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-alpha.4/go.mod h1:3zR5rQ8QliVNkzEuGx8rJeNF9EZ2dCCiDgqPmFAkt1I=
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-alpha.2 h1:utiFoj5ElToTgjqlGrfxu0TXWRcDK5m9jNbeQxQvqCM=
github.com/danielfdickinson/minimal-test-theme-hugo-dfd v0.4.4-alpha.2/go.mod h1:3zR5rQ8QliVNkzEuGx8rJeNF9EZ2dCCiDgqPmFAkt1I=
33 changes: 23 additions & 10 deletions layouts/partials/helpers/lib/image-handling/find-image-src.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- $destination := .src -}}
{{- $destMap := .destMap -}}
{{- $curPage := .page -}}
{{- $getRelative := .getRelative -}}
{{- $ignoreBundleAssets := .ignoreBundleAssets -}}
Expand All @@ -16,16 +17,18 @@
{{- if strings.HasPrefix $destination "data:image" -}}
{{- $base64 = true -}}
{{- else -}}
{{- with urls.Parse $destination -}}
{{- if or .Host .Scheme -}}
{{- $external = true -}}
{{- if not $destMap -}}
{{- with urls.Parse $destination -}}
{{- if or .Host .Scheme -}}
{{- $external = true -}}
{{- end -}}
{{- $path = .Path -}}
{{- else -}}
{{- errorf printf "Unable to parse image src '%s'" $destination -}}
{{- end -}}
{{- $path = .Path -}}
{{- else -}}
{{- errorf printf "Unable to parse image src '%s'" $destination -}}
{{- end -}}
{{- end -}}
{{- if and $path (not $external) (not $base64) -}}
{{- if and $path (not $external) (not $base64) (not $destMap) -}}
{{- /* For compatibility with Git repos, strip relative paths; the repos need them */ -}}
{{- /* but resources expect a different 'root' */ -}}
{{- if hasPrefix $path ".." -}}
Expand Down Expand Up @@ -64,12 +67,22 @@
{{- errorf (printf "Image %s is missing and not external for page %s" $path $curPage.Title) -}}
{{- end -}}
{{- end -}}
{{- else if $external -}}{{- /* Use external URLs verbatim (not as a resource so no Hugo Pipes; we don't use 0.92.x only functionality, yet) */ -}}
{{- $finalDestination = $destination -}}
{{- else if $base64 -}}
{{- $finalSrc = $destination -}}
{{- else if $destMap -}}
$imageResource = $destMap.Resource
$link = $destMap.Destination
$url = $destMap.Destination
$specialSrc = $destMap.Destination
{{- else if $external -}}{{- /* Use external URLs verbatim (not as a resource so no Hugo Pipes; we don't use 0.92.x only functionality, yet) */ -}}
{{- $finalDestination = $destination -}}
{{- end -}}
{{- $image := (dict "imageResource" $imageResource "link" $finalDestination "url" $finalDestination "specialSrc" $finalSrc) -}}
{{- $image := (dict
"imageResource" $imageResource
"link" $finalDestination
"url" $finalDestination
"specialSrc" $finalSrc
) -}}
{{- with $image.imageResource -}}
{{- if partial "helpers/lib/image-handling/is-processable" . -}}
{{- $image = $image | merge (dict "width" .Width "height" .Height) -}}
Expand Down
129 changes: 129 additions & 0 deletions layouts/partials/image-handler.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{{- /* Set default values. */}}
{{- $markdownImageLinkClass := .Page.Params.imageMarkdownLinkClass | default .Page.Site.Params.imageMarkdownLinkClass -}}
{{- $markdownImageClass := .Page.Params.imageMarkdownClass | default .Page.Site.Params.imageMarkdownClass -}}
{{- $markdownImageWrapper := .Page.Params.imageMarkdownAddWrapper | default .Page.Site.Params.imageMarkdownAddWrapper -}}
{{- $markdownImageWrapperType := .Page.Params.imageMarkdownWrapperType | default .Page.Site.Params.imageMarkdownWrapperType -}}
{{- $markdownImageOverlayImage := .Page.Params.imageMarkdownOverlayImage | default .Page.Site.Params.imageMarkdownOverlayImage -}}
{{- $markdownImageOverlayText := .Page.Params.imageMarkdownOverlayText | default .Page.Site.Params.imageMarkdownOverlayText -}}
{{- $height := 0 }}
{{- $width := 0 }}
{{- $anchor := "smart" }}
{{- $format := .Page.Site.Params.imageConvertTo | default "webp" }}
{{- $loading := .Page.Params.imageMarkdownLoading | default .Page.Site.Params.imageMarkdownLoading | default "lazy" }}
{{- $method := .Page.Params.imageMarkdownMethod | default .Page.Site.Params.imageMarkdownMethod | default "Resize" }}
{{- $hint := .Page.Params.imageMarkdownHint| default .Page.Site.Params.imageMarkdownHint | default "photo" }}
{{- $quality := .Page.Params.imageMarkdownQuality | default .Page.Site.Params.imageMarkdownQuality | default 90 }}
{{- $rotation := 0 }}
{{- $imageClass := "" }}
{{- $dictionary := "" }}

{{- /* Define allowable values. */}}
{{- $validAnchors := slice "bottom" "bottomleft" "bottomright" "center" "left" "right" "smart" "top" "topleft" "topright" }}
{{- $validFormats := slice "bmp" "gif" "jpg" "jpeg" "png" "tif" "tiff" "webp" }}
{{- $validMethods := slice "Crop" "Fill" "Fit" "Resize" }}
{{- $validHints := slice "drawing" "icon" "photo" "picture" "text" }}
{{- $validLoading := slice "eager" "lazy" }}
{{- $validWrapperType := slice "div" "picture" "figure" }}


{{- /* Parse Query options */}}
{{- $u := urls.Parse .destMap.Destination }}
{{- with $u.Query }}
{{- with .Get "h" }}
{{- $height = int . }}
{{- end }}
{{- with .Get "w" }}
{{- $width = int . }}
{{- end }}
{{- with .Get "a" | lower }}
{{- if in $validAnchors . }}
{{- $anchor = . }}
{{- else }}
{{- errorf "Unable to render image. %q is not a valid anchor. See %s" . $u }}
{{- end }}
{{- end }}
{{- with .Get "f" | lower }}
{{- if in $validFormats . }}
{{- $format = . }}
{{- else }}
{{- errorf "Unable to render image. %q is not a valid format. See %s" . $u }}
{{- end }}
{{- end }}
{{- with .Get "l" | lower }}
{{- if in $validLoading . }}
{{- $loading = . }}
{{- else }}
{{- errorf "Unable to render image. %q is not a valid loading. See %s" . $u }}
{{- end }}
{{- end }}
{{- with .Get "m" | humanize }}
{{- if in $validMethods . }}
{{- $method = . }}
{{- else }}
{{- errorf "Unable to render image. %q is not a valid method. See %s" . $u }}
{{- end }}
{{- end }}
{{- with .Get "r" }}
{{- $rotation = int . }}
{{- end }}
{{- with .Get "wr" | lower -}}
{{- if in $validWrapperType . }}
{{- $markdownImageWrapperType = . -}}
{{- $markdownImageWrapper = true -}}
{{- else }}
{{- errorf "Unable to render image. %q is not a valid wrapper. See %s" . $u }}
{{- end }}
{{- end -}}
{{- if .Has "c" }}
{{- $markdownImageClass = delimit (index . "c") " " | lower }}
{{- end }}
{{- if .Has "i" }}
{{- $imageClass = delimit (index . "i") " " | lower }}
{{- end }}
{{- with .Get "q" }}
{{- $quality = int . -}}
{{- end }}
{{- with .Get "hi" | lower }}
{{- if in $validHints . }}
{{- $hint = . }}
{{- else }}
{{- errorf "Unable to render image. %q is not a valid hint. See %s" . $u }}
{{- end }}
{{- end }}
{{- end }}


{{- $image := partial "helpers/lib/image-handling/find-image-src" (dict "destMap" .destMap "page" .Page "getRelative" true "ignoreBundleAssets" false) -}}
{{- $dictionary = (dict "alt" .Text "altRendered" true "title" .Title "image" $image "page" .Page "rotation" $rotation "noImageWrapper" (not $markdownImageWrapper) "linkClass" $markdownImageLinkClass "class" $markdownImageClass "imageOverlay" $markdownImageOverlayImage "textOverlay" $markdownImageOverlayText "convertTo" $format "loading" $loading "imageConvertMethod" $method "quality" $quality) -}}
{{- /* Adding width and height */ -}}
{{- if and $width $height }}
{{- $dictionary = merge $dictionary (dict "width" $width "height" $height) -}}
{{- else if and $width (not $height) }}
{{- $dictionary = merge $dictionary (dict "width" $width) -}}
{{- else if and $height (not $width) }}
{{- $dictionary = merge $dictionary (dict "height" $height ) -}}
{{- else }}
{{- $dictionary = merge $dictionary (dict "width" $image.Width "height" $image.Height) }}
{{- end }}
{{- /* Adding anchor */ -}}
{{- if $anchor }}
{{- if or (eq $method "Crop") (eq $method "Fill")}}
{{- $dictionary = merge $dictionary (dict "anchor" $anchor) -}}
{{- end -}}
{{- end }}
{{- /* Adding image wrapper */ -}}
{{- if ne $markdownImageWrapperType "" }}
{{- $dictionary = merge $dictionary (dict "imageWrapper" $markdownImageWrapperType) -}}
{{- end }}
{{- /* Adding image class */ -}}
{{- if ne $imageClass "" }}
{{- $dictionary = merge $dictionary (dict "imageClass" $imageClass) -}}
{{- end }}
{{- /* Adding convert preset */ -}}
{{- if $hint }}
{{- $dictionary = merge $dictionary (dict "hint" $hint) -}}
{{- end }}
{{- /* Calling image wrapper */ -}}
{{- partial "helpers/wrapped-image" $dictionary -}}

{{- /* Remove trailing newlines */ -}}
8 changes: 4 additions & 4 deletions tests/scripts/html-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ set -o pipefail

SITEROOT="$(pwd)"

if [ -d exampleSite ]; then
SITESRC=exampleSite/
fi
#if [ -d exampleSite ]; then
# SITESRC=exampleSite/
#fi

if echo y | npx html-validate -c .htmlvalidate.json \
"${SITEROOT}"/${SITESRC}public/** 2>&1 | tee html-validate.log; then
"${SITEROOT}"/${SITESRC}public/**.html "${SITEROOT}"/${SITESRC}public/**/*.html 2>&1 | tee html-validate.log; then
echo "ok"
exit 0
else
Expand Down

0 comments on commit 2ef03f4

Please sign in to comment.