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 <me@wangchucheng.com>2021-04-09 18:59:09 +0300
committerWang Chucheng <me@wangchucheng.com>2021-04-09 18:59:09 +0300
commit8e31cae0e4c5b7cc85ff7a79f7c5a9881d11c540 (patch)
treebe8621db7bcd6ea5cc0db6d4ed4375e93a9b2620 /layouts
parent8d0808eb8d3cc0464794de9f88d0b2e8995f4efa (diff)
refactor: improve repoEditURL
BREAKING CHANGES: Param 'repoURL' in params.yaml is deprecated.
Diffstat (limited to 'layouts')
-rw-r--r--layouts/_default/single.html2
-rw-r--r--layouts/partials/components/doc-layout.html2
-rw-r--r--layouts/partials/components/post-edit.html59
-rw-r--r--layouts/partials/components/schema.html2
-rw-r--r--layouts/partials/head.html16
-rw-r--r--layouts/partials/utils/get-bundles.html7
6 files changed, 55 insertions, 33 deletions
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 8656069..1d1245d 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -21,9 +21,7 @@
{{ partial "components/post-tags" . }}
{{ end }}
- {{ if or .Site.Params.repoURL .Site.Params.repoEditURL }}
{{ partial "components/post-edit" . }}
- {{ end }}
{{ with .GetTerms "authors" }}
{{ partial "components/post-author" . }}
diff --git a/layouts/partials/components/doc-layout.html b/layouts/partials/components/doc-layout.html
index 7217030..34b8227 100644
--- a/layouts/partials/components/doc-layout.html
+++ b/layouts/partials/components/doc-layout.html
@@ -31,9 +31,7 @@
{{ partial "components/post-author" . }}
{{ end }}
- {{ if or .Site.Params.repoURL .Site.Params.repoEditURL }}
{{ partial "components/post-edit" . }}
- {{ end }}
{{ partial "components/post-footer" . }}
{{ partial "comment" . }}
diff --git a/layouts/partials/components/post-edit.html b/layouts/partials/components/post-edit.html
index 14c07af..09cbec8 100644
--- a/layouts/partials/components/post-edit.html
+++ b/layouts/partials/components/post-edit.html
@@ -1,24 +1,51 @@
-<div class="flex md:justify-end my-4">
- {{ $repoEditURL := partial "get-edit-url" . }}
+{{- $editMap := partial "get-edit-url" . }}
+{{- if or .Site.Params.repoEditURL $editMap.repoEditURL }}
+ <div class="flex md:justify-end my-4">
+ {{- $contentDir := cond .Site.IsMultiLingual .Site.Params.contentDir "/content/" }}
+ {{- $filePath := ""}}
+ {{- if $editMap.fileDir }}
+ {{- $filePath = strings.TrimPrefix $editMap.fileDir .File.Path }}
+ {{- else }}
+ {{- $filePath = path.Join $contentDir .File.Path }}
+ {{- end }}
+
+ {{- $repoEditURL := cond (ne $editMap.repoEditURL "") $editMap.repoEditURL .Site.Params.repoEditURL }}
+ {{- $path := path.Join $repoEditURL $filePath }}
+ {{- $path = replace $path "http:/" "http://" 1 }}
+ {{- $path = replace $path "https:/" "https://" 1 }}
+
+ <a href="{{ $path }}" title="Edit this page">
+ <i class="fas fa-edit mr-1"></i>
+ <span>{{ i18n "editThisPage" }}</span>
+ </a>
+ </div>
+{{/* Deprecation warning(v1.0.0) starts */}}
+{{- else if .Site.Params.repoURL }}
+ {{ warnf "Param 'repoURL' in params.yaml is deprecated and will be removed in Eureka v1.0.0. See https://www.wangchucheng.com/en/docs/hugo-eureka/customization/" }}
+ <div class="flex md:justify-end my-4">
+ {{- $repoEditURL := path.Join .Site.Params.repoURL "/blob/master/" }}
{{ $contentDir := cond .Site.IsMultiLingual .Site.Params.contentDir "/content/" }}
{{ $path := path.Join $repoEditURL $contentDir .File.Path }}
- {{ $path := replace $path "http:/" "http://" 1 }}
- {{ $path := replace $path "https:/" "https://" 1 }}
-
+ {{ $path = replace $path "http:/" "http://" 1 }}
+ {{ $path = replace $path "https:/" "https://" 1 }}
+
<a href="{{ $path }}" title="Edit this page">
- <i class="fas fa-edit mr-1"></i>
- <span>{{ i18n "editThisPage" }}</span>
+ <i class="fas fa-edit mr-1"></i>
+ <span>{{ i18n "editThisPage" }}</span>
</a>
-</div>
+ </div>
+{{/* Deprecation warning(v1.0.0) ends */}}
+{{- end }}
{{ define "partials/get-edit-url" }}
-{{ with .Site.Params.repoEditURL }}
-{{ $.Scratch.Set "repoEditURL" . }}
-{{ else }}
-{{ $repoEditURL := path.Join .Site.Params.repoURL "/blob/master/"}}
-{{ $.Scratch.Set "repoEditURL" $repoEditURL }}
+{{ $repoEditURL := "" }}
+{{ $fileDir := "" }}
+{{ $bundles := partial "utils/get-bundles" . }}
+{{ range $bundles.Reverse }}
+ {{ if .Params.repoEditURL }}
+ {{ $repoEditURL = .Params.repoEditURL }}
+ {{ $fileDir = .File.Dir }}
+ {{ end }}
{{ end }}
-{{ $repoEditURL := .Scratch.Get "repoEditURL" }}
-{{ .Scratch.Delete "repoEditURL" }}
-{{ return $repoEditURL }}
+{{ return (dict "repoEditURL" $repoEditURL "fileDir" $fileDir) }}
{{ end }} \ No newline at end of file
diff --git a/layouts/partials/components/schema.html b/layouts/partials/components/schema.html
index 001138b..bc3147f 100644
--- a/layouts/partials/components/schema.html
+++ b/layouts/partials/components/schema.html
@@ -1,7 +1,7 @@
<meta name="description"
content="{{ if .Description }}{{ .Description }}{{ else if .Summary }}{{ .Summary }}{{ else if .Site.Params.Description }}{{ .Site.Params.Description }}{{ end }}">
-{{- $bundles := partial "get-bundles" . }}
+{{- $bundles := partial "utils/get-bundles" . }}
{{- if gt (len $bundles) 1 }}
<script type="application/ld+json">
{
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index f85393d..fb3d569 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -19,7 +19,7 @@
{{/* Deprecation warning(v1.0.0) ends */}}
{{ if and (eq .Type "docs") (ne $layout "doc-list") }}
{{ $docTitle := "" }}
-{{ $bundles := partial "get-bundles" . }}
+{{ $bundles := partial "utils/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) }}
{{/* Deprecation warning(v1.0.0) starts */}}
@@ -52,6 +52,8 @@
{{ end }}
<title>{{ partial "get-title" . }}</title>
+<meta name="generator" content="Hugo Eureka {{ .Site.Data.eureka.version }}" />
+
{{- $eurekaCSS := resources.Get "css/eureka.css" | postCSS (dict "config" "./assets/css/postcss.config.js") }}
{{- $eurekaCSS := $eurekaCSS | minify }}
<link rel="stylesheet" href="{{ $eurekaCSS.Permalink }}">
@@ -78,19 +80,9 @@
<script defer src="{{ printf $assets.fontawesome.js.url $assets.fontawesome.version }}"
{{ with $assets.fontawesome.js.sri }} integrity="{{ . }}" {{ end }} crossorigin></script>
-{{ define "partials/get-bundles" }}
-{{ $currentPage := . }}
-{{ $bundles := slice $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 }}
-{{ end }}
-
{{- $enableMath := false }}
{{- if .Site.Params.math.handler }}
-{{- $bundles := partial "get-bundles" . }}
+{{- $bundles := partial "utils/get-bundles" . }}
{{- $enableMath = true }}
{{- range $bundles.Reverse }}
{{- if and (ne .Params.math nil) (ne .Params.math "") }}
diff --git a/layouts/partials/utils/get-bundles.html b/layouts/partials/utils/get-bundles.html
new file mode 100644
index 0000000..059b954
--- /dev/null
+++ b/layouts/partials/utils/get-bundles.html
@@ -0,0 +1,7 @@
+{{ $currentPage := . }}
+{{ $bundles := slice $currentPage }}
+{{ if and (ne $currentPage.Kind "taxonomy") (or (ne $currentPage $currentPage.FirstSection) (eq $currentPage.Kind "term")) }}
+{{ $currentBundles := partial "utils/get-bundles" $currentPage.Parent }}
+{{ $bundles = $bundles | append $currentBundles }}
+{{ end }}
+{{ return $bundles }} \ No newline at end of file