fix: Correct Lastmod field access in OpenGraph meta tags

- Updated the OpenGraph meta tags to correctly access the Lastmod field.
- For pages, use .Lastmod instead of .Site.Lastmod.
- For non-pages, use .Site.LastChange instead of .Site.Lastmod.
- Ensured proper formatting for published and modified times in OpenGraph meta tags.

The original content caused issues on Cloudflare Pages due to incorrect access of the Lastmod field, leading to build failures.
This commit is contained in:
LSweetSour 2024-09-28 13:53:59 +08:00 committed by GitHub
parent 048a000f17
commit 2d6f7c84c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -32,12 +32,12 @@
<meta property='article:modified_time' content='{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/> <meta property='article:modified_time' content='{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/>
{{- end -}} {{- end -}}
{{- else -}} {{- else -}}
{{- if not .Site.Lastmod.IsZero -}} {{- if not .Site.LastChange.IsZero -}}
<meta property='og:updated_time' content='{{ .Site.Lastmod.Format " 2006-01-02T15:04:05-07:00 " | safeHTML }}'/> <meta property='og:updated_time' content='{{ .Site.LastChange.Format "2006-01-02T15:04:05-07:00" | safeHTML }}'/>
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{ $image := partialCached "helper/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }} {{ $image := partialCached "helper/image" (dict "Context" . "Type" "opengraph") .RelPermalink "opengraph" }}
{{- if $image.exists -}} {{- if $image.exists -}}
<meta property='og:image' content='{{ absURL $image.permalink }}' /> <meta property='og:image' content='{{ absURL $image.permalink }}' />
{{- end -}} {{- end -}}