From 0cc80f90eebc1fc44eb3540b05260fdce5e517a4 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 29 Dec 2019 22:00:29 +0000 Subject: [PATCH] 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 --- exampleSite/config/_default/params.toml | 4 ---- layouts/partials/functions/get_logo.html | 16 ++++++++++++++++ layouts/partials/navbar.html | 6 ++++-- layouts/partials/site_head.html | 5 +++-- 4 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 layouts/partials/functions/get_logo.html diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index b5926fd2..d7ea6025 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -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 ############################ diff --git a/layouts/partials/functions/get_logo.html b/layouts/partials/functions/get_logo.html new file mode 100644 index 00000000..4bf6b8e6 --- /dev/null +++ b/layouts/partials/functions/get_logo.html @@ -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 }} diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html index e4977fe4..ec566f11 100644 --- a/layouts/partials/navbar.html +++ b/layouts/partials/navbar.html @@ -4,10 +4,12 @@
{{if $show_logo}} + {{ $has_logo := fileExists "assets/images/logo.png" }}