Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wangchucheng/hugo-eureka.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWang Chucheng <wangchucheng@outlook.com>2020-12-12 19:19:04 +0300
committerWang Chucheng <wangchucheng@outlook.com>2020-12-12 19:19:04 +0300
commit69af104e562b4a2d86aff01cb9187f64a475f948 (patch)
tree5b8722d7fae1fb96cf87915537e9ea84431843d6 /layouts
parent6638e3a102cb8e678dfed77c926f2498cc05d583 (diff)
feat: customize title separator
Diffstat (limited to 'layouts')
-rw-r--r--layouts/partials/doc_layout.html2
-rw-r--r--layouts/partials/head.html60
-rw-r--r--layouts/partials/opengraph.html2
-rw-r--r--layouts/partials/schema_page.html2
4 files changed, 53 insertions, 13 deletions
diff --git a/layouts/partials/doc_layout.html b/layouts/partials/doc_layout.html
index 4d36fc5..beffa65 100644
--- a/layouts/partials/doc_layout.html
+++ b/layouts/partials/doc_layout.html
@@ -95,7 +95,7 @@
{{ range $index, $value := $versions }}
{{ if eq $index 0 }}
<div class="ml-2 mr-8 my-1">
- <a class="" href="{{ $.context.Permalink }}">latest</a>
+ <a class="" href="{{ $.context.Parent.Permalink }}">latest</a>
</div>
{{ end }}
{{ $version := findRE "v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?" . }}
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 1eb4794..8a831a5 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -1,6 +1,46 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
-<title>{{- with .Params.Title -}}{{- . -}} | {{- end -}}{{- .Site.Title -}}</title>
+
+{{ define "partials/get_title" }}
+{{ $separator := .Site.Params.titleSeparator | default "|" }}
+{{ $primarySep := $separator }}
+{{ $secondarySep := $separator }}
+{{ if reflect.IsSlice $separator }}
+{{ $primarySep = index $separator 0 }}
+{{ $secondarySep = index $separator 1 | default (index $separator 0) }}
+{{ end }}
+{{ $title := .Site.Title }}
+{{/* Generate prefix */}}
+{{ $prefix := "" }}
+{{ if .Params.Title }}
+{{ $prefix = .Params.Title }}
+{{ if and (eq .Type "docs") (ne .Layout "doc_list") }}
+{{ $docTitle := "" }}
+{{ $bundles := partial "get_bundles" . }}
+{{ range $bundles.Reverse }}
+{{ $version := findRE "v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?" (path.Base .Permalink) }}
+{{ if and (eq .Parent.Layout "doc_list") (ne .Layout "doc_list") }}
+{{ $docTitle = .Title }}
+{{ else if $version }}
+{{ $docTitle = .Title }}
+{{ end }}
+{{ end }}
+{{/* Doc title */}}
+{{ $version := findRE "v?(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?" (path.Base .Permalink) }}
+{{ if or (eq .Parent.Layout "doc_list") $version }}
+{{ $prefix = $docTitle }}
+{{ else }}
+{{ $prefix = print $prefix " " $secondarySep " " $docTitle }}
+{{ end }}
+{{ end }}
+{{ end }}
+{{/* Add prefix */}}
+{{ with $prefix }}
+{{ $title = print . " " $primarySep " " $title }}
+{{ end }}
+{{ return $title }}
+{{ end }}
+<title>{{ partial "get_title" . }}</title>
{{- $eurekaCSS := resources.Get "css/eureka.css" | postCSS (dict "config" "./assets/css/postcss.config.js") }}
{{- $eurekaCSS := $eurekaCSS | minify }}
@@ -16,12 +56,12 @@
{{- $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"
+ {{ with $assets.highlightjs.css.sri }} integrity="{{ . }}" {{ end }} media="print"
onload="this.media='all';this.onload=null" crossorigin>
<script defer src="{{ printf $assets.highlightjs.js.url $assets.highlightjs.version }}"
- {{- with $assets.highlightjs.js.sri -}} integrity="{{- . -}}" {{- end -}} crossorigin></script>
+ {{ with $assets.highlightjs.js.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
<script defer src="{{ printf $assets.fontawesome.js.url $assets.fontawesome.version }}"
- {{- with $assets.fontawesome.js.sri -}} integrity="{{- . -}}" {{- end -}} crossorigin></script>
+ {{ with $assets.fontawesome.js.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
{{ define "partials/get_bundles" }}
{{ $currentPage := . }}
@@ -46,12 +86,12 @@
{{- 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"
+ {{ with $assets.katex.css.sri }} integrity="{{ . }}" {{ end }} media="print"
onload="this.media='all';this.onload=null" crossorigin>
-<script defer src="{{ printf $assets.katex.js.url $assets.katex.version }}" {{- with $assets.katex.js.sri -}}
- integrity="{{ . }}" {{- end -}} crossorigin></script>
+<script defer src="{{ printf $assets.katex.js.url $assets.katex.version }}" {{ with $assets.katex.js.sri }}
+ integrity="{{ . }}" {{ end }} crossorigin></script>
<script defer src="{{ printf $assets.katex.autoRender.url $assets.katex.version }}"
- {{- with $assets.katex.autoRender.sri -}} integrity="{{- . -}}" {{- end -}} crossorigin></script>
+ {{ with $assets.katex.autoRender.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
renderMathInElement(document.body, {
@@ -85,8 +125,8 @@
{{ partial "custom_head.html" . }}
{{- 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 -}}">
+<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 }}
{{ define "partials/get_icon" }}
diff --git a/layouts/partials/opengraph.html b/layouts/partials/opengraph.html
index eb556bb..6065b98 100644
--- a/layouts/partials/opengraph.html
+++ b/layouts/partials/opengraph.html
@@ -1,4 +1,4 @@
-<meta property="og:title" content="{{ with .Params.Title }}{{ . }} | {{ end }}{{ .Site.Title }}" />
+<meta property="og:title" content="{{ partial "get_title" . }}" />
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
{{ $icon := partial "get_image.html" (dict "context" . "url" .Site.Params.icon) }}
{{ with $icon }}
diff --git a/layouts/partials/schema_page.html b/layouts/partials/schema_page.html
index 438b2cc..b231b0a 100644
--- a/layouts/partials/schema_page.html
+++ b/layouts/partials/schema_page.html
@@ -6,7 +6,7 @@
"@type": "WebPage",
"@id": {{ .Permalink }}
},
- "headline": "{{ with .Params.Title }}{{ . }} | {{ end }}{{ .Site.Title }}",
+ "headline": "{{ partial "get_title" . }}",
{{- $img := partial "get_image.html" (dict "context" . "url" .Params.featuredImage "keyword" "*featured*") }}
{{- with $img }}
"image": {{ . }},