feat: automatically detect logo image

Simplify the process of adding a logo to a site.

BREAKING CHANGE:
Removes param for logo from params.toml. Instead, move logo image to `assets/images/logo.png`, creating the folders if necessary.

See #1439
This commit is contained in:
George Cushen committed 2019-12-29 22:00:38 +00:00
1 parent 577eeeaca2
commit 0cc80f90ee
4 files changed
+23 -8

No files matched your search

-4
View File
@@ -46,10 +46,6 @@ org_name = ""
# Description for social sharing and search engines. If undefined, superuser role is used in place.
description = ""
# Display a logo in navigation bar rather than title (optional).
# To enable, place an image in `static/img/` and reference its filename below. To disable, set the value to "".
logo = ""
############################
## Site Features
############################
+16
View File
@@ -0,0 +1,16 @@
{{/* Function to get logo image. */}}
{{/* Inputs: constraint: max_height/fit (str); size (int) */}}
{{/* Output: resource (obj) */}}
{{ $logo := resources.Get "images/logo.png" }}
{{ $logo_proc := $logo }}
{{ if eq .constraint "max_height" }}
{{/* Resize logo to fit specified max height. */}}
{{ $logo_proc = ($logo.Resize (printf "x%s" (string .size))) }}
{{ else }}
{{/* Constrain logo to fit within specified dimensions. */}}
{{ $logo_proc = ($logo.Fit (printf "%sx%s" (string .size) (string .size))) }}
{{ end }}
{{ return $logo_proc }}
+4 -2
View File
@@ -4,10 +4,12 @@
<div class="container">
{{if $show_logo}}
{{ $has_logo := fileExists "assets/images/logo.png" }}
<div class="d-none d-lg-inline-flex">
<a class="navbar-brand" href="{{ "/" | relLangURL }}">
{{- if site.Params.logo -}}
<img src="{{ printf "/img/%s" site.Params.logo | relURL }}" alt="{{ site.Title }}">
{{- if $has_logo -}}
{{ $logo := (partial "functions/get_logo" (dict "constraint" "max_height" "size" 70)) }}
<img src="{{ $logo.RelPermalink }}" alt="{{ site.Title }}">
{{- else -}}
{{- site.Title -}}
{{- end -}}
+3 -2
View File
@@ -148,6 +148,7 @@
<link rel="canonical" href="{{ .Permalink }}">
{{ $featured_image := (.Resources.ByType "image").GetMatch "*featured*" }}
{{ $has_logo := fileExists "assets/images/logo.png" }}
{{ $og_image := "" }}
{{ $twitter_card := "summary_large_image" }}
{{ if $featured_image }}
@@ -156,8 +157,8 @@
{{ $og_image = printf "img/%s" .Params.header.image | absURL }}
{{ else if site.Params.sharing_image }}
{{ $og_image = printf "img/%s" site.Params.sharing_image | absURL }}
{{ else if site.Params.logo }}
{{ $og_image = (printf "img/%s" site.Params.logo) | absURL }}
{{ else if $has_logo }}
{{ $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }}
{{ $twitter_card = "summary" }}
{{ else if site.Params.avatar }}
{{ $og_image = (printf "img/%s" site.Params.avatar) | absURL }}