From cf923ad102eacd4a410b7f1e55cc4807a539fc2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E6=A2=A6=E6=98=9F=E5=B0=98?= Date: Sat, 7 May 2022 21:24:29 +0800 Subject: [PATCH] Use Scratch function get global variable in partial template. --- exampleSite/config.yaml | 6 +++--- layouts/_default/baseof.html | 1 + layouts/partials/head/open_graph.html | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/exampleSite/config.yaml b/exampleSite/config.yaml index e28c761..03f533f 100644 --- a/exampleSite/config.yaml +++ b/exampleSite/config.yaml @@ -47,10 +47,10 @@ params: author: NexT 主题 subtitle: 为 Hugo 打造的主题 description: 保持简单的易用性和强大的功能。 - # Custom logo will use in open graph image's URL - # Use the "show" variable to control whether it is displayed in the sidebar + # Custom logo will use in open graph image meta attribute. + # Use the "show" variable to control whether displayed in sidebar customLogo: - show: true + show: false url: /imgs/hugo-next-logo.png favicon: diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 12d78e7..eaf5956 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,5 +1,6 @@ {{- $langCode := replaceRE "-([a-z]+)" (upper (substr .Site.Language -3)) .Site.Language -}} {{- $P := .Site.Params -}} +{{- .Scratch.Set "langCode" $langCode -}} diff --git a/layouts/partials/head/open_graph.html b/layouts/partials/head/open_graph.html index 39a1f8a..bdf0a9f 100644 --- a/layouts/partials/head/open_graph.html +++ b/layouts/partials/head/open_graph.html @@ -1,9 +1,9 @@ {{- $Site := .Site -}} {{- $Params := .Site.Params -}} {{- $Page := .Page -}} +{{- $langCode := .Scratch.Get "langCode" -}} {{- with .Site.Params.openGraph -}} {{- if .enable -}} -{{- $langCode := replaceRE "-([a-z]+)" (upper (substr $Site.Language -3)) $Site.Language }} @@ -12,7 +12,6 @@ - {{- with .twitter -}} {{- range $attr, $val := . }}