Use Scratch function get global variable in partial template.

This commit is contained in:
凡梦星尘 2022-05-07 21:24:29 +08:00
parent 4755b77427
commit cf923ad102
3 changed files with 5 additions and 5 deletions

View File

@ -47,10 +47,10 @@ params:
author: NexT 主题 author: NexT 主题
subtitle: 为 Hugo 打造的主题 subtitle: 为 Hugo 打造的主题
description: 保持简单的易用性和强大的功能。 description: 保持简单的易用性和强大的功能。
# Custom logo will use in open graph image's URL # Custom logo will use in open graph image meta attribute.
# Use the "show" variable to control whether it is displayed in the sidebar # Use the "show" variable to control whether displayed in sidebar
customLogo: customLogo:
show: true show: false
url: /imgs/hugo-next-logo.png url: /imgs/hugo-next-logo.png
favicon: favicon:

View File

@ -1,5 +1,6 @@
{{- $langCode := replaceRE "-([a-z]+)" (upper (substr .Site.Language -3)) .Site.Language -}} {{- $langCode := replaceRE "-([a-z]+)" (upper (substr .Site.Language -3)) .Site.Language -}}
{{- $P := .Site.Params -}} {{- $P := .Site.Params -}}
{{- .Scratch.Set "langCode" $langCode -}}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="{{ $langCode }}"> <html lang="{{ $langCode }}">
<head> <head>

View File

@ -1,9 +1,9 @@
{{- $Site := .Site -}} {{- $Site := .Site -}}
{{- $Params := .Site.Params -}} {{- $Params := .Site.Params -}}
{{- $Page := .Page -}} {{- $Page := .Page -}}
{{- $langCode := .Scratch.Get "langCode" -}}
{{- with .Site.Params.openGraph -}} {{- with .Site.Params.openGraph -}}
{{- if .enable -}} {{- if .enable -}}
{{- $langCode := replaceRE "-([a-z]+)" (upper (substr $Site.Language -3)) $Site.Language }}
<meta property="og:type" content="website"> <meta property="og:type" content="website">
<meta property="og:title" content="{{ $Page.Title }}"> <meta property="og:title" content="{{ $Page.Title }}">
<meta property="og:description" content="{{ default $Params.description $Page.Description }}"> <meta property="og:description" content="{{ default $Params.description $Page.Description }}">
@ -12,7 +12,6 @@
<meta property="og:site_name" content="{{ $Site.Title }}"> <meta property="og:site_name" content="{{ $Site.Title }}">
<meta property="og:locale" content="{{ $langCode }}"> <meta property="og:locale" content="{{ $langCode }}">
<meta property="article:author" content="{{ default $Params.author $Page.Params.Author }}"> <meta property="article:author" content="{{ default $Params.author $Page.Params.Author }}">
{{- with .twitter -}} {{- with .twitter -}}
{{- range $attr, $val := . }} {{- range $attr, $val := . }}
<meta name="twitter:{{ $attr }}" content="{{ $val }}"> <meta name="twitter:{{ $attr }}" content="{{ $val }}">