add tags for SEO

This commit is contained in:
leafee98 2023-06-29 22:22:37 +08:00
parent 97c892077a
commit e4e2844c3e
3 changed files with 32 additions and 1 deletions

View file

@ -22,6 +22,7 @@ style = 'monokailight'
tabWidth = 4
[params]
description = "Example site for hugo-theme-flat"
mainSections = ['posts']
## uncomment belows and set proper values to enable remark42

View file

@ -1,7 +1,6 @@
<!DOCTYPE html>
<html>
<head>
<title>{{ with .Params.Title }}{{ . }} | {{ end }}{{ .Site.Title }}</title>
{{ partial "head.html" . }}
</head>

View file

@ -1,6 +1,37 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1">
{{ $title := .Site.Title -}}
{{ if .Params.Title -}}
{{ $title = printf "%s | %s" .Params.Title $title -}}
{{ end -}}
{{ $description := "" -}}
{{ if .IsHome -}}
{{ with .Site.Params.description }}{{ $description = . }}{{ end -}}
{{ else if .IsPage -}}
{{ if .Description -}}
{{ $description = .Description -}}
{{ else -}}
{{ $description = .Summary -}}
{{ end -}}
{{ end }}
<title>{{ $title }}</title>
<link rel="canonical" href="{{ .Permalink }}">
{{ if $description -}}
<meta name="description" content="{{ $description }}" />
{{ end -}}
<meta property="og:type" content="article" />
<meta property="og:title" content="{{ $title }}" />
<meta property="og:url" content="{{ .Permalink }}" />
{{ if $description -}}
<meta property="og:description" content="{{ $description }}" />
{{ end -}}
{{ range .AlternativeOutputFormats -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{ end -}}