feat: make media library dir configurable

Move default media library from static/img/ to static/media/ as it can now contain audio, video, and other kinds of media in addition to images.

BREAKING CHANGE:
Either rename your site's static/img/ to static/media/ (and update any references to this folder in your Markdown files);

Or, add `media_dir = "img"` to `params.toml` to continue using the legacy location.
This commit is contained in:
George Cushen 2020-07-29 18:54:28 +01:00
commit d9ff93a1c2
14 changed files with 29 additions and 14 deletions

View file

Before

Width:  |  Height:  |  Size: 227 KiB

After

Width:  |  Height:  |  Size: 227 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 304 KiB

After

Width:  |  Height:  |  Size: 304 KiB

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 6.8 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Before After
Before After

View file

@ -5,7 +5,7 @@
"@id": {{site.BaseURL}},
"name": {{site.Params.org_name | default site.Title}},
"logo": {{ partial "functions/get_logo_url" . }},
{{with site.Params.sharing_image}}"image": {{printf "img/%s" . | absURL}},{{end}}
{{with site.Params.sharing_image}}"image": {{printf "%s/%s" ($.Scratch.Get "media_dir") . | absURL}},{{end}}
{{ if (eq site.Params.site_type "LocalBusiness") | and site.Params.coordinates }}
"geo": {
"@type": "GeoCoordinates",

View file

@ -21,7 +21,8 @@
{{ if $img_src.Scheme }}
<img src="{{ .Params.header.image }}" class="article-banner" alt="">
{{ else }}
<img src="{{ (printf "/img/%s" .Params.header.image) | relURL }}" class="article-banner" alt="">
{{ $media_dir := $.Scratch.Get "media_dir" }}
<img src="{{ (printf "/%s/%s" $media_dir .Params.header.image) | relURL }}" class="article-banner" alt="">
{{ end }}
{{ with .Params.header.caption }}<span class="article-header-caption">{{ . | markdownify | emojify }}</span>{{ end }}

View file

@ -7,6 +7,9 @@
{{ $scr := .Scratch }}
{{ $media_dir := site.Params.media_dir | default "media" }}
{{ $scr.Set "media_dir" $media_dir }}
{{/* Attempt to load superuser. */}}
{{ $superuser_name := "" }}
{{ $superuser_username := "" }}
@ -173,9 +176,9 @@
{{ else if $featured_image }}
{{ $og_image = $featured_image.Permalink }}
{{ else if .Params.header.image }}
{{ $og_image = printf "img/%s" .Params.header.image | absURL }}
{{ $og_image = printf "%s/%s" $media_dir .Params.header.image | absURL }}
{{ else if site.Params.sharing_image }}
{{ $og_image = printf "img/%s" site.Params.sharing_image | absURL }}
{{ $og_image = printf "%s/%s" $media_dir site.Params.sharing_image | absURL }}
{{ else if $has_logo }}
{{ $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }}
{{ $twitter_card = "summary" }}

View file

@ -43,7 +43,8 @@
{{ $darken = printf "linear-gradient(rgba(0, 0, 0, %s), rgba(0, 0, 0, %s))," (string $bg.image_darken) (string $bg.image_darken) }}
{{ end }}
{{/* See Hugo note on linking assets in styles: https://github.com/gohugoio/hugoThemes#common-permalink-issues */}}
{{ $style = printf "%sbackground-image: %s url('%s');" $style $darken (printf "img/%s" $bg.image | absURL) }}
{{ $media_dir := $.Scratch.Get "media_dir" }}
{{ $style = printf "%sbackground-image: %s url('%s');" $style $darken (printf "%s/%s" $media_dir $bg.image | absURL) }}
{{ with $bg.image_size }}
{{/* Allow sizes: actual, cover, and contain. */}}
{{ $style = printf "%sbackground-size: %s;" $style (replace . "actual" "auto") }}

View file

@ -57,9 +57,10 @@
{{/* Hero image */}}
{{ if $page.Params.hero_media }}
{{ $media_dir := $.Scratch.Get "media_dir" }}
</div>
<div class="col-6 mx-auto col-md-6 order-md-2 hero-media">
<img src="{{ printf "img/%s" $page.Params.hero_media | relURL }}" alt="">
<img src="{{ printf "%s/%s" $media_dir $page.Params.hero_media | relURL }}" alt="">
</div>
</div>
{{ end }}

View file

@ -17,9 +17,10 @@
background-color: {{ $item.overlay_color | default "transparent" }};
{{ end }}
{{ if $item.overlay_img }}
{{ $media_dir := $.Scratch.Get "media_dir" }}
background-image:
{{ if $item.overlay_filter }}linear-gradient(rgba(0, 0, 0, {{ $item.overlay_filter }}), rgba(0, 0, 0, {{ $item.overlay_filter }})), {{ end }}
url('{{ printf "img/%s" $item.overlay_img | absURL }}');
url('{{ printf "%s/%s" $media_dir $item.overlay_img | absURL }}');
{{ end }}
;">
<div class="container" style="text-align: {{$item.align | default "left"}};">

View file

@ -3,8 +3,9 @@
{{ $path := "" }}
{{ $root_dir := "" }}
{{ $media_dir := $.Scratch.Get "media_dir" }}
{{ if .Get "library" }}
{{ $path = "media/" }}
{{ $path = printf "%s/" $media_dir }}
{{ $root_dir = "static/" }}
{{ end }}

View file

@ -1,12 +1,13 @@
{{/* Enable image to be loaded from local page dir or media library at `static/img/`. */}}
{{/* Enable image to be loaded from local page dir or media library at `static/media/`. */}}
{{ $media_dir := $.Scratch.Get "media_dir" }}
{{ $asset := (.Page.Resources.ByType "image").GetMatch (.Get "src") }}
{{ $image_src := (.Get "src") }}
{{ if $asset }}
{{ $asset2 := $asset.Fit "2000x2000" }}
{{ $image_src = $asset2.RelPermalink }}
{{ else if .Get "library" }}
{{ $image_src = printf "img/%s" $image_src | relURL }}
{{ $image_src = printf "%s/%s" $media_dir $image_src | relURL }}
{{ end }}
{{/* Disallow user from opening image in the lightbox? */}}

View file

@ -34,7 +34,7 @@
{{end}}
{{else}}
{{/* Load gallery images from the `static/img/` media library or internet */}}
{{/* Load gallery images from the `static/media/` media library or internet */}}
{{ if $.Page.Params.gallery_item }}
{{ range (where $.Page.Params.gallery_item "album" $album) }}
@ -42,7 +42,8 @@
{{ $.Scratch.Set "src" .image }}
{{ if gt (len .image) 4 }}
{{ if ne "http" (slicestr .image 0 4) }}
{{ $.Scratch.Set "src" (printf "img/%s" .image | relURL) }}
{{ $media_dir := $.Scratch.Get "media_dir" }}
{{ $.Scratch.Set "src" (printf "%s/%s" $media_dir .image | relURL) }}
{{ end }}
{{ end }}
{{/* Don't lazy load image as cannot init image size from non-Hugo asset, resulting in inaccurate anchor scrolling & active link highlighting. */}}

View file

@ -1,8 +1,10 @@
{{/* Enable video to be loaded from local page dir or media library at `static/img/`. */}}
{{/* Enable video to be loaded from local page dir or media library at `static/media/`. */}}
{{ $path := "" }}
{{ $root_dir := "" }}
{{ $media_dir := $.Scratch.Get "media_dir" }}
{{ if .Get "library" }}
{{ $path = "img/" }}
{{ $path = printf "%s/" $media_dir }}
{{ $root_dir = "static/" }}
{{ end }}

View file

@ -1,6 +1,9 @@
<!DOCTYPE html>
<html lang="{{ site.LanguageCode | default "en-us" }}">
<head>
{{ $media_dir := site.Params.media_dir | default "media" }}
{{ $scr.Set "media_dir" $media_dir }}
{{ $css := site.Data.assets.css }}
{{ $cdn_url_reveal := "https://cdnjs.cloudflare.com/ajax/libs/reveal.js/3.8.0" }}