hugo-theme-stack/layouts/partials/head/opengraph/provider/base.html
MofuMoca 900e683872
Add og tag option to show site name.
增加 og tag 可以選擇是否要包含網站名稱,用於某些預覽連結只顯示 og:title 而不顯示 og:site_name 時,可以直接在預覽上查看到網站名稱。
預設為 false,維持原本此 theme 的設定,若需要在本 commit 之中也有設定好 params 設定為 false,在 partials/head/opengraph/provider/base.html 有設定 default 值,以防使用者沒有設定時不會出錯。

Add og tag options to set 'og:title' as 'title - sitename' or just 'Title' for some website link preview just show title not includ sitename.
The defautl value is 'false' in example config.yaml and in partials/head/opengraph/provider/base.html set default vaule to 'false' via code.
2023-10-13 15:24:05 +08:00

49 lines
1.7 KiB
HTML

{{- $title := partialCached "data/title" . .RelPermalink -}}
{{- $description := partialCached "data/description" . .RelPermalink -}}
<meta property='og:title' content='
{{- if (default false .Site.Params.opengraph.title_include_site_name) -}}
{{ $title }} - {{ .Site.Title }}
{{- else -}}
{{ $title }}
{{- end -}}
'>
<meta property='og:description' content='{{ $description }}'>
<meta property='og:url' content='{{ .Permalink }}'>
<meta property='og:site_name' content='{{ .Site.Title }}'>
<meta property='og:type' content='
{{- if .IsPage -}}
article
{{- else -}}
website
{{- end -}}
'>
{{- with .Params.locale -}}
<meta property='og:locale' content='{{ . }}'>
{{- end -}}
{{- if .IsPage -}}
<meta property='article:section' content='{{ .Section | title }}' />
{{- range .Params.tags -}}
<meta property='article:tag' content='{{ . }}' />
{{- end -}}
{{- end -}}
{{- if .IsPage -}}
{{- if not .Date.IsZero -}}
<meta property='article:published_time' content='{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/>
{{- end -}}
{{- if not .Lastmod.IsZero -}}
<meta property='article:modified_time' content='{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/>
{{- end -}}
{{- else -}}
{{- if not .Site.LastChange.IsZero -}}
<meta property='og:updated_time' content='{{ .Site.LastChange.Format " 2006-01-02T15:04:05-07:00 " | safeHTML }}'/>
{{- end -}}
{{- end -}}
{{ $image := partialCached "helper/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }}
{{- if $image.exists -}}
<meta property='og:image' content='{{ absURL $image.permalink }}' />
{{- end -}}