Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Research Best Practices on Accessing Source Content from Hugo #7840

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prepare image JSON shortcode to be migratable to Drupal. Added new so…
…urce-url field, dont load image if it doesnt have a uid or format, and reformat to read more easily.
  • Loading branch information
mattsqd committed Aug 5, 2024
commit 45909915eed2d8cf93c4f4b30c48d8bf6ba4c0b8
17 changes: 16 additions & 1 deletion themes/digital.gov/layouts/shortcodes/api-images.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
{{- $.Scratch.Add "index" slice -}}
{{- range $image := sort $.Site.Data.images ".date" "desc" -}}
{{- $.Scratch.Add "index" (dict "uid" $image.uid "date" $image.date "height" $image.height "width" $image.width "format" $image.format "alt" ($image.alt | default "" | plainify) "caption" ($image.caption | default "" | plainify) "credit" ($image.credit | default "" | plainify)) -}}
<!-- Only process images with a non-empty uid and image format -->
{{- if (and .uid $image.format) }}
{{- $sourceURL := printf "https://s3.amazonaws.com/digitalgov/%s.%s" $image.uid $image.format -}}
{{- $.Scratch.Add "index" (dict
"uid" $image.uid
"date" $image.date
"height" $image.height
"width" $image.width
"format" $image.format
"alt" ($image.alt | default "" | plainify)
"caption" ($image.caption | default "" | plainify)
"credit" ($image.credit | default "" | plainify)
"source-url" $sourceURL
)
-}}
{{- end }}
{{- end -}}
{{- $.Scratch.Get "index" | jsonify -}}