From 1d58e5e8198864a6c651fc0427150b3c846135e2 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sat, 20 Feb 2021 17:28:11 +0000 Subject: [PATCH] feat: rename assets/images/ to assets/media/ and auto detect sharing image The file uploader in Wowchemy CMS has also been updated to reflect the change. BREAKING CHANGES: - rename assets/images/ to assets/media/ - move default social sharing image (if any) to assets/media/sharing.* --- wowchemy-cms/data/wowchemy_cms_tpl.yaml | 6 +++--- wowchemy/assets/{images => media}/icon.png | Bin wowchemy/layouts/partials/book_menu.html | 2 +- wowchemy/layouts/partials/functions/get_icon.html | 2 +- wowchemy/layouts/partials/functions/get_logo.html | 4 ++-- .../layouts/partials/functions/get_logo_url.html | 2 +- wowchemy/layouts/partials/navbar.html | 2 +- wowchemy/layouts/partials/site_head.html | 7 ++++--- wowchemy/layouts/partials/widgets/featurette.html | 2 +- wowchemy/layouts/shortcodes/figure.html | 4 ++-- 10 files changed, 16 insertions(+), 15 deletions(-) rename wowchemy/assets/{images => media}/icon.png (100%) diff --git a/wowchemy-cms/data/wowchemy_cms_tpl.yaml b/wowchemy-cms/data/wowchemy_cms_tpl.yaml index 221d8cf9..e04ebc30 100644 --- a/wowchemy-cms/data/wowchemy_cms_tpl.yaml +++ b/wowchemy-cms/data/wowchemy_cms_tpl.yaml @@ -2,7 +2,7 @@ backend: name: git-gateway branch: main squash_merges: true -media_folder: 'static/media' +media_folder: 'assets/media' public_folder: '/media' collections: - name: home @@ -10,7 +10,7 @@ collections: folder: 'content/home' path: '{{slug}}' # When specifying a path on a folder collection, media_folder defaults to an empty string, so make it explicit. - media_folder: '/static/media' + media_folder: '/assets/media' public_folder: '' summary: "{{filename}}: {{title}}" identifier_field: "widget_id" @@ -58,7 +58,7 @@ collections: widget: "image" required: false # When specifying a path on a folder collection, media_folder defaults to an empty string, so make it explicit. - media_folder: '/static/media' + media_folder: '/assets/media' public_folder: '' media_library: config: diff --git a/wowchemy/assets/images/icon.png b/wowchemy/assets/media/icon.png similarity index 100% rename from wowchemy/assets/images/icon.png rename to wowchemy/assets/media/icon.png diff --git a/wowchemy/layouts/partials/book_menu.html b/wowchemy/layouts/partials/book_menu.html index 384d1cca..967ef89c 100644 --- a/wowchemy/layouts/partials/book_menu.html +++ b/wowchemy/layouts/partials/book_menu.html @@ -24,7 +24,7 @@ {{- if eq $pack "emoji" -}} {{- . | emojify -}} {{- else if eq $pack "custom" -}} - {{- $svg_icon := resources.Get (printf "images/icon-pack/%s.svg" .) -}} + {{- $svg_icon := resources.Get (printf "media/icon-pack/%s.svg" .) -}} {{- if $svg_icon -}} {{ $icon = printf "\"%s\"" $svg_icon.RelPermalink . }} {{- end -}} diff --git a/wowchemy/layouts/partials/functions/get_icon.html b/wowchemy/layouts/partials/functions/get_icon.html index fce30d4e..03a047d5 100644 --- a/wowchemy/layouts/partials/functions/get_icon.html +++ b/wowchemy/layouts/partials/functions/get_icon.html @@ -2,6 +2,6 @@ {{/* Input: size (int) */}} {{/* Output: resource (obj) */}} -{{ $icon := resources.GetMatch "images/icon.png" }} +{{ $icon := resources.GetMatch "media/icon.png" }} {{ $icon_resized := $icon.Fill (printf "%sx%s Center" (string .) (string .)) }} {{ return $icon_resized }} diff --git a/wowchemy/layouts/partials/functions/get_logo.html b/wowchemy/layouts/partials/functions/get_logo.html index b4e11c1d..747d1d01 100644 --- a/wowchemy/layouts/partials/functions/get_logo.html +++ b/wowchemy/layouts/partials/functions/get_logo.html @@ -4,11 +4,11 @@ {{/* Workaround fact Hugo does not support GetMatch in assets dir */}} {{/* Hugo doesn't support image ops on SVG: https://discourse.gohugo.io/t/ho-do-i-convert-a-generic-resource-to-image-resource/22570/4 */}} -{{ $logo := resources.Get "images/logo.png" | default (resources.Get "images/logo.svg") }} +{{ $logo := resources.Get "media/logo.png" | default (resources.Get "media/logo.svg") }} {{ $logo_proc := $logo }} {{/* If the type of image can be resized by Hugo, resize it given a `.size` argument to the function. */}} -{{ if resources.Get "images/logo.png" }} +{{ if resources.Get "media/logo.png" }} {{ if eq .constraint "max_height" }} {{/* Resize logo to fit specified max height. */}} {{ $logo_proc = ($logo.Resize (printf "x%s" (string .size))) }} diff --git a/wowchemy/layouts/partials/functions/get_logo_url.html b/wowchemy/layouts/partials/functions/get_logo_url.html index 0f2c23d5..e51e0af4 100644 --- a/wowchemy/layouts/partials/functions/get_logo_url.html +++ b/wowchemy/layouts/partials/functions/get_logo_url.html @@ -3,7 +3,7 @@ {{/* Output: logo URL (URL) */}} {{ $logo_url := "" }} -{{ if resources.Get "images/logo.png" | or (resources.Get "images/logo.svg") }} +{{ if resources.Get "media/logo.png" | or (resources.Get "media/logo.svg") }} {{ $logo_url = (partial "functions/get_logo" (dict "constraint" "fit" "size" 192)).Permalink }} {{ else }} {{ $logo_url = (partial "functions/get_icon" 192).Permalink }} diff --git a/wowchemy/layouts/partials/navbar.html b/wowchemy/layouts/partials/navbar.html index 3e49e752..e7cadf89 100644 --- a/wowchemy/layouts/partials/navbar.html +++ b/wowchemy/layouts/partials/navbar.html @@ -7,7 +7,7 @@ {{/* Get site logo. */}} {{ $show_logo := site.Params.main_menu.show_logo | default true }} -{{ $has_logo := fileExists "assets/images/logo.png" | or (fileExists "assets/images/logo.svg") }} +{{ $has_logo := fileExists "assets/media/logo.png" | or (fileExists "assets/media/logo.svg") }} {{ $logo := "" }} {{ if $has_logo }} {{ $logo = (partial "functions/get_logo" (dict "constraint" "max_height" "size" 70)) }} diff --git a/wowchemy/layouts/partials/site_head.html b/wowchemy/layouts/partials/site_head.html index 7a6e5ee8..7756601c 100644 --- a/wowchemy/layouts/partials/site_head.html +++ b/wowchemy/layouts/partials/site_head.html @@ -203,9 +203,10 @@ {{/* Get page image for sharing. */}} + {{ $sharing_image := resources.GetMatch (path.Join "media" "sharing.*") }} {{ $featured_image := (.Resources.ByType "image").GetMatch "*featured*" }} {{ $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" }} - {{ $has_logo := fileExists "assets/images/logo.png" | or (fileExists "assets/images/logo.svg") }} + {{ $has_logo := fileExists "assets/media/logo.png" | or (fileExists "assets/media/logo.svg") }} {{ $og_image := "" }} {{ $twitter_card := "summary_large_image" }} {{ if (and (eq .Kind "term") $avatar_image) }} @@ -216,8 +217,8 @@ {{ $og_image = $featured_image.Permalink }} {{ else if .Params.header.image }} {{ $og_image = printf "%s/%s" $media_dir .Params.header.image | absURL }} - {{ else if site.Params.sharing_image }} - {{ $og_image = printf "%s/%s" $media_dir site.Params.sharing_image | absURL }} + {{ else if $sharing_image }} + {{ $og_image = $sharing_image.Permalink }} {{ else if $has_logo }} {{ $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }} {{ $twitter_card = "summary" }} diff --git a/wowchemy/layouts/partials/widgets/featurette.html b/wowchemy/layouts/partials/widgets/featurette.html index 0b9b9a65..8e3c7b70 100644 --- a/wowchemy/layouts/partials/widgets/featurette.html +++ b/wowchemy/layouts/partials/widgets/featurette.html @@ -27,7 +27,7 @@ {{- if eq $pack "emoji" -}} {{- . | emojify -}} {{- else if eq $pack "custom" -}} - {{- $svg_icon := resources.Get (printf "images/icon-pack/%s.svg" .) -}} + {{- $svg_icon := resources.Get (printf "media/icon-pack/%s.svg" .) -}} {{- if $svg_icon -}}{{.}}{{- end -}} {{- else -}} diff --git a/wowchemy/layouts/shortcodes/figure.html b/wowchemy/layouts/shortcodes/figure.html index 0fe0309e..ad90c873 100644 --- a/wowchemy/layouts/shortcodes/figure.html +++ b/wowchemy/layouts/shortcodes/figure.html @@ -1,5 +1,5 @@ {{/* Figure Shortcode for Wowchemy. */}} -{{/* Load image from page dir falling back to media library at `assets/images/` and then to remote URI. */}} +{{/* Load image from page dir falling back to media library at `assets/media/` and then to remote URI. */}} {{ $destination := .Get "src" }} {{ $caption := .Get "caption" | default (.Get "title") | default "" }}{{/* Support legacy `title` option. */}} @@ -9,7 +9,7 @@ {{- $img := (.Page.Resources.ByType "image").GetMatch $destination -}} {{- if not $img -}} - {{- $img = resources.Get (path.Join "images" $destination) -}} + {{- $img = resources.Get (path.Join "media" $destination) -}} {{- end -}}