Преглед изворни кода

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.*
George Cushen пре 4 година
родитељ
комит
1d58e5e819

+ 3 - 3
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:

+ 0 - 0
wowchemy/assets/images/icon.png → wowchemy/assets/media/icon.png


+ 1 - 1
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 "<img src=\"%s\" alt=\"%s\" class=\"svg-icon svg-baseline pr-1\">" $svg_icon.RelPermalink . }}
         {{- end -}}

+ 1 - 1
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 }}

+ 2 - 2
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))) }}

+ 1 - 1
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 }}

+ 1 - 1
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)) }}

+ 4 - 3
wowchemy/layouts/partials/site_head.html

@@ -203,9 +203,10 @@
   <link rel="canonical" href="{{ .Permalink }}" />
 
   {{/* 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" }}

+ 1 - 1
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 -}}<img src="{{ $svg_icon.RelPermalink }}" alt="{{.}}" class="svg-icon svg-baseline">{{- end -}}
       {{- else -}}
         <i class="{{ $pack }} {{ $pack_prefix }}-{{ . }}"></i>

+ 2 - 2
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 -}}
 
 <figure {{ with .Get "class" }}class="{{.}}"{{ end }} {{ with $id }}id="figure-{{ . }}"{{ end }}>