diff options
author | Wang Chucheng <wangchucheng@outlook.com> | 2020-11-27 19:03:10 +0300 |
---|---|---|
committer | Wang Chucheng <wangchucheng@outlook.com> | 2020-11-27 19:03:10 +0300 |
commit | 68034e1009a9e9d3ae96d36b4f9f952800c1e7ef (patch) | |
tree | 5950d393e8fe31f1f5c9f0736cfb29cdf7eddd31 /layouts | |
parent | d998e9fa89455ac70270cb81ae7d6dded8e4e7db (diff) |
refactor: improve head
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/custom_head.html | 1 | ||||
-rw-r--r-- | layouts/partials/head.html | 74 | ||||
-rw-r--r-- | layouts/partials/schema.html | 74 | ||||
-rw-r--r-- | layouts/partials/schema_node.html | 10 |
4 files changed, 70 insertions, 89 deletions
diff --git a/layouts/partials/custom_head.html b/layouts/partials/custom_head.html new file mode 100644 index 0000000..f9424d4 --- /dev/null +++ b/layouts/partials/custom_head.html @@ -0,0 +1 @@ +{{/* Do not modify this file! */}}
\ No newline at end of file diff --git a/layouts/partials/head.html b/layouts/partials/head.html index f3a38b5..1eb4794 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -2,19 +2,19 @@ <meta name="viewport" content="width=device-width"> <title>{{- with .Params.Title -}}{{- . -}} | {{- end -}}{{- .Site.Title -}}</title> -{{- $eureka_css := resources.Get "css/eureka.css" | postCSS (dict "config" "./assets/css/postcss.config.js") -}} -{{- $eureka_css := $eureka_css | minify -}} -<link rel="stylesheet" href="{{ $eureka_css.Permalink }}"> +{{- $eurekaCSS := resources.Get "css/eureka.css" | postCSS (dict "config" "./assets/css/postcss.config.js") }} +{{- $eurekaCSS := $eurekaCSS | minify }} +<link rel="stylesheet" href="{{ $eurekaCSS.Permalink }}"> -{{- $eureka_js := resources.Get "js/eureka.js" | minify -}} -<script defer src="{{ $eureka_js.Permalink }}"></script> +{{- $eurekaJS := resources.Get "js/eureka.js" | minify }} +<script defer src="{{ $eurekaJS.Permalink }}"></script> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preload" href="https://fonts.googleapis.com/css2?family=Lora:wght@400;600;700&family=Noto+Serif+SC:wght@400;600;700&display=swap" as="style" onload="this.onload=null;this.rel='stylesheet'"> -{{- $assets := .Site.Data.assets -}} +{{- $assets := .Site.Data.assets }} <link rel="stylesheet" href="{{ printf $assets.highlightjs.css.url $assets.highlightjs.version }}" {{- with $assets.highlightjs.css.sri -}} integrity="{{- . -}}" {{- end -}} media="print" onload="this.media='all';this.onload=null" crossorigin> @@ -26,25 +26,25 @@ {{ define "partials/get_bundles" }} {{ $currentPage := . }} {{ $bundles := slice $currentPage }} -{{ if ne $currentPage $currentPage.FirstSection }} -{{ $currentPage = $currentPage.Parent }} -{{ $bundles = $bundles | append $currentPage }} +{{ if and (ne $currentPage.Kind "taxonomy") (or (ne $currentPage $currentPage.FirstSection) (eq $currentPage.Kind "term")) }} +{{ $currentBundles := partial "get_bundles" $currentPage.Parent }} +{{ $bundles = $bundles | append $currentBundles }} {{ end }} -{{ return $bundles.Reverse }} +{{ return $bundles }} {{ end }} {{- $enableMath := false }} -{{- if .Site.Params.math.handler -}} -{{- $bundles := partial "get_bundles" . -}} +{{- if .Site.Params.math.handler }} +{{- $bundles := partial "get_bundles" . }} {{- $enableMath = true }} -{{- range $bundles -}} -{{- if and (ne .Params.math nil) (ne .Params.math "") -}} -{{- $enableMath = .Params.math -}} -{{- end -}} -{{- end -}} -{{- end -}} +{{- range $bundles.Reverse }} +{{- if and (ne .Params.math nil) (ne .Params.math "") }} +{{- $enableMath = .Params.math }} +{{- end }} +{{- end }} +{{- end }} -{{- if and (eq .Site.Params.math.handler "katex") $enableMath -}} +{{- if and (eq .Site.Params.math.handler "katex") $enableMath }} <link rel="stylesheet" href="{{ printf $assets.katex.css.url $assets.katex.version }}" {{- with $assets.katex.css.sri -}} integrity="{{- . -}}" {{- end -}} media="print" onload="this.media='all';this.onload=null" crossorigin> @@ -61,31 +61,33 @@ { left: "\\(", right: "\\)", display: false }, { left: "\\[", right: "\\]", display: true } ], - {{- range $key, $value := .Site.Params.math.katex -}} - {{- if and (ne $value nil) (ne $value "") -}} - {{- $key | safeJS -}}: {{- $value | safeJS -}}, - {{- end -}} - {{- end -}} + {{- range $key, $value := .Site.Params.math.katex }} + {{- if and (ne $value nil) (ne $value "") }} + {{- $key | safeJS -}}: {{- $value | safeJS }}, + {{- end }} + {{- end }} }); }); </script> -{{- end -}} +{{- end }} -{{- with .Site.GoogleAnalytics -}} +{{- if and .Site.GoogleAnalytics hugo.IsProduction }} <link rel="preconnect" href="https://www.google-analytics.com" crossorigin> -<script async src="https://www.googletagmanager.com/gtag/js?id={{- . -}}"></script> +<script async src="https://www.googletagmanager.com/gtag/js?id={{ .Site.GoogleAnalytics }}"></script> <script> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); - gtag('config', '{{- . -}}'); + gtag('config', '{{ .Site.GoogleAnalytics }}'); </script> -{{ end }} +{{- end }} + +{{ partial "custom_head.html" . }} -{{- with .Site.Params.icon -}} +{{- with .Site.Params.icon }} <link rel="icon" type="image/png" sizes="32x32" href="{{- (partial "get_icon" (dict "icon" . "size" 32)).Permalink -}}"> <link rel="apple-touch-icon" sizes="180x180" href="{{- (partial "get_icon" (dict "icon" . "size" 180)).Permalink -}}"> -{{- end -}} +{{- end }} {{ define "partials/get_icon" }} {{ $icon := resources.GetMatch .icon }} @@ -93,8 +95,8 @@ {{ return $icon_resized }} {{ end }} -{{- partial "schema.html" . -}} -{{- partial "opengraph.html" . -}} -{{- range .AlternativeOutputFormats -}} -{{- printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML -}} -{{- end -}}
\ No newline at end of file +{{- partial "schema.html" . }} +{{- partial "opengraph.html" . }} +{{- range .AlternativeOutputFormats }} +{{- printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} +{{- end }}
\ No newline at end of file diff --git a/layouts/partials/schema.html b/layouts/partials/schema.html index 8521726..6be8946 100644 --- a/layouts/partials/schema.html +++ b/layouts/partials/schema.html @@ -1,57 +1,31 @@ <meta name="description" - content="{{ if .Description }}{{ .Description }}{{ else if .Summary }}{{ .Summary }}{{ else if .Site.Params.Description }}{{ .Site.Params.Description }}{{ end }}"> + content="{{ if .Description }}{{ .Description }}{{ else if .Summary }}{{ .Summary }}{{ else if .Site.Params.Description }}{{ .Site.Params.Description }}{{ end }}"> -{{ if not .IsHome }} -{{ $depth := (sub (len (split .RelPermalink "/")) 1) }} -{{ $.Scratch.Set "depth" $depth }} -{{ if .Site.Home.AllTranslations }} -{{ $depth := sub ($.Scratch.Get "depth") 1 }} -{{ $.Scratch.Set "depth" $depth }} -{{ end }} +{{- $bundles := partial "get_bundles" . }} +{{- if gt (len $bundles) 1 }} <script type="application/ld+json"> { - "@context": "https://schema.org", - "@type": "BreadcrumbList", - "itemListElement": [{{ template "breadcrumb" (dict "p1" . "p2" . "depth" ($.Scratch.Get "depth")) }}] + "@context": "https://schema.org", + "@type": "BreadcrumbList", + "itemListElement": [ + {{- range $index, $value := $bundles.Reverse -}} + {{- if gt $index 0 -}},{{- end -}} + { + "@type": "ListItem", + "position": {{- add $index 1 -}}, + "name": {{- .LinkTitle -}}, + "item": {{- .Permalink -}} + } + {{- end -}} + ] } </script> -{{ end }} +{{- end }} -{{ if and (eq .Type "docs") (ne .Params.layout "doc_list") }} -{{ partial "schema_page.html" . }} -{{ else if or (eq .Kind "section") (eq .Kind "term") }} -{{ partial "schema_node.html" . }} -{{ else if .IsPage }} -{{ partial "schema_page.html" . }} -{{ end }} - -{{- define "breadcrumb" -}} -{{ $depth := (sub .depth 1 ) -}} -{{ if .p1.Parent -}} -{{ template "breadcrumb" (dict "p1" .p1.Parent "p2" .p2 "depth" $depth) -}} -{{ else if not .p1.IsHome -}} -{{ template "breadcrumb" (dict "p1" .p1.Site.Home "p2" .p2 "depth" $depth) -}} -{{ end -}} -{{ if eq .p1 .p2 -}} -{ -"@type": "ListItem", -"position": {{ .depth }}, -"name": {{ .p1.Title }}, -"item": {{ .p1.Permalink }} -} -{{- else if eq .depth 1 -}} -{ -"@type": "ListItem", -"position": {{ .depth }}, -"name": {{ .p1.Site.Title }}, -"item": {{ .p1.Permalink }} -}, -{{- else -}} -{ -"@type": "ListItem", -"position": {{ .depth }}, -"name": {{ .p1.Title }}, -"item": {{ .p1.Permalink }} -}, -{{- end -}} -{{- end -}}
\ No newline at end of file +{{- if and (eq .Type "docs") (ne .Params.layout "doc_list") }} +{{- partial "schema_page.html" . }} +{{- else if or (eq .Kind "section") (eq .Kind "term") }} +{{- partial "schema_node.html" . }} +{{- else if .IsPage }} +{{- partial "schema_page.html" . }} +{{- end }}
\ No newline at end of file diff --git a/layouts/partials/schema_node.html b/layouts/partials/schema_node.html index 32ff222..ec4fda0 100644 --- a/layouts/partials/schema_node.html +++ b/layouts/partials/schema_node.html @@ -1,5 +1,9 @@ -{{ $paginator := .Paginate .Pages }} -{{ with .Paginator.Pages }} +{{- $paginator := .Paginate .Pages }} +{{- $pages := .Paginator.Pages }} +{{- if eq .Type "authors" }} +{{- $pages = .Pages }} +{{- end }} +{{- with $pages }} <script type="application/ld+json"> { "@context":"https://schema.org", @@ -22,4 +26,4 @@ ] } </script> -{{ end }}
\ No newline at end of file +{{- end }}
\ No newline at end of file |