diff options
author | Wang Chucheng <me@wangchucheng.com> | 2021-04-09 18:59:09 +0300 |
---|---|---|
committer | Wang Chucheng <me@wangchucheng.com> | 2021-04-09 18:59:09 +0300 |
commit | 8e31cae0e4c5b7cc85ff7a79f7c5a9881d11c540 (patch) | |
tree | be8621db7bcd6ea5cc0db6d4ed4375e93a9b2620 | |
parent | 8d0808eb8d3cc0464794de9f88d0b2e8995f4efa (diff) |
refactor: improve repoEditURL
BREAKING CHANGES: Param 'repoURL' in params.yaml is deprecated.
-rw-r--r-- | data/eureka.yaml | 2 | ||||
-rw-r--r-- | exampleSite/config/_default/params.yaml | 2 | ||||
-rw-r--r-- | layouts/_default/single.html | 2 | ||||
-rw-r--r-- | layouts/partials/components/doc-layout.html | 2 | ||||
-rw-r--r-- | layouts/partials/components/post-edit.html | 59 | ||||
-rw-r--r-- | layouts/partials/components/schema.html | 2 | ||||
-rw-r--r-- | layouts/partials/head.html | 16 | ||||
-rw-r--r-- | layouts/partials/utils/get-bundles.html | 7 | ||||
-rw-r--r-- | package-lock.json | 2 | ||||
-rw-r--r-- | package.json | 9 |
10 files changed, 59 insertions, 44 deletions
diff --git a/data/eureka.yaml b/data/eureka.yaml index 4a66f57..0f115e9 100644 --- a/data/eureka.yaml +++ b/data/eureka.yaml @@ -1 +1 @@ -version: 0.5.0
\ No newline at end of file +version: 0.7.1-dev
\ No newline at end of file diff --git a/exampleSite/config/_default/params.yaml b/exampleSite/config/_default/params.yaml index 77f9704..d7771f1 100644 --- a/exampleSite/config/_default/params.yaml +++ b/exampleSite/config/_default/params.yaml @@ -2,8 +2,6 @@ mainSections: - posts description: Eureka is a elegant and powerful theme for Hugo. -repoURL: -# If it is a Github repo, leave blank repoEditURL: dateFormat: 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 diff --git a/package-lock.json b/package-lock.json index f89205b..8b540bb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "hugo-eureka", - "version": "0.3.1", + "version": "0.7.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d213263..b5e8ea8 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,9 @@ { "name": "hugo-eureka", - "version": "0.3.1", - "description": "Starter files for the eureka theme for hugo.", - "main": "index.js", + "version": "0.7.1-dev", + "description": "Eureka is a feature-rich and highly customizable Hugo theme.", "repository": "https://github.com/wangchucheng/hugo-eureka", "author": "C. Wang <me@wangchucheng.com>", - "license": "MIT", - "scripts": { - "start": "hugo --gc" - }, "devDependencies": { "@fullhuman/postcss-purgecss": "^4.0.3", "autoprefixer": "^10.2.5", |