Breaking Change: replace BookEditPath with BookLastChangeLink and BookEditLink tempaltes

This commit is contained in:
Alex Shpak
2025-08-03 21:40:26 +02:00
parent 7bd4d673cc
commit 2b0d7ffa26
8 changed files with 76 additions and 74 deletions
+16 -20
View File
@@ -149,26 +149,21 @@ disableKinds = ['taxonomy', 'taxonomyTerm']
# You can also set value to "*" to render all sections to menu
BookSection = 'docs'
# Set source repository location.
# Used for 'Last Modified' and 'Edit this page' links.
BookRepo = 'https://github.com/alex-shpak/hugo-book'
# (Optional, default none) Set template for commit link for the page. Requires enableGitInfo.
# When set enabled 'Last Modified' and a link to the commit in the footer of the page.
# Param is executed as template using .Site, .Page and .GitInfo as context.
BookLastChangeLink = 'https://github.com/alex-shpak/hugo-book/commit/{{ .GitInfo.Hash }}'
# Specifies commit portion of the link to the page's last modified commit hash for 'doc' page
# type.
# Required if 'BookRepo' param is set.
# Value used to construct a URL consisting of BookRepo/BookCommitPath/<commit-hash>
# Github uses 'commit', Bitbucket uses 'commits'
BookCommitPath = 'commit'
# (Optional, default none) Set template for edit page link.
# When set enabled 'Edit this page' link in the footer of the page.
# Param is executed as template using .Site, .Page and .Path as context.
BookEditLink = 'https://github.com/alex-shpak/hugo-book/edit/main/exampleSite/{{ .Path }}'
# Enable 'Edit this page' links for 'doc' page type.
# Disabled by default. Uncomment to enable. Requires 'BookRepo' param.
# Path must point to the site directory.
BookEditPath = 'edit/master/exampleSite'
# (Optional, default January 2, 2006) Configure the date format used on the pages
# (Optional, default 'January 2, 2006') Configure the date format used on the pages
# - In git information
# - In blog posts
BookDateFormat = 'Jan 2, 2006'
# https://gohugo.io/functions/time/format/
BookDateFormat = 'January 2, 2006'
# (Optional, default true) Enables search function with flexsearch,
# Index is built on fly, therefore it might slowdown your website.
@@ -222,8 +217,8 @@ bookToC = true
# (Optional) If you have enabled BookComments for the site, you can disable it for specific pages.
bookComments = true
# (Optional) Set to 'false' to exclude page from search index.
bookSearchExclude = true
# (Optional) Set to 'true' to exclude page from search index.
bookSearchExclude = false
# (Optional) Set explicit href attribute for this page in a menu.
bookHref = ''
@@ -256,6 +251,7 @@ In addition to this, there are several empty partials you can override to easily
| `assets/_variables.scss` | Override default SCSS variables |
| `assets/_fonts.scss` | Replace default font with custom fonts (e.g. local files or remote like google fonts) |
| `assets/mermaid.json` | Replace Mermaid initialization config |
| `assets/katex.json` | Replace KaTeX initialization config |
### Plugins
@@ -275,7 +271,7 @@ There are a few hugo templates inserted in `<head>`
- [Google Analytics](https://gohugo.io/templates/internal/#google-analytics)
- [Open Graph](https://gohugo.io/templates/internal/#open-graph)
To disable Open Graph inclusion you can create your own empty file `\layouts\_internal\opengraph.html`.
To disable Open Graph inclusion you can create your own empty file `/layouts/_internal/opengraph.html`.
In fact almost empty not quite empty because an empty file looks like absent for HUGO. For example:
```
<!-- -->
@@ -287,9 +283,9 @@ In fact almost empty not quite empty because an empty file looks like absent for
- [Columns](https://hugo-book-demo.netlify.app/docs/shortcodes/columns/)
- [Details](https://hugo-book-demo.netlify.app/docs/shortcodes/details/)
- [Hints](https://hugo-book-demo.netlify.app/docs/shortcodes/hints/)
- [KaTeX](https://hugo-book-demo.netlify.app/docs/shortcodes/katex/)
- [Mermaid](https://hugo-book-demo.netlify.app/docs/shortcodes/mermaid/)
- [Tabs](https://hugo-book-demo.netlify.app/docs/shortcodes/tabs/)
- [KaTeX](https://hugo-book-demo.netlify.app/docs/shortcodes/katex/)
By default, Goldmark trims unsafe outputs which might prevent some shortcodes from rendering. It is recommended to set `markup.goldmark.renderer.unsafe=true` if you encounter problems.
+1
View File
@@ -7,4 +7,5 @@ weight: 1
# bookCollapseSection: false
# bookComments: false
# bookSearchExclude: false
# bookHref: ''
---
+13 -18
View File
@@ -1,6 +1,6 @@
# hugo server --minify --themesDir ../.. --baseURL=http://0.0.0.0:1313/theme/hugo-book/
# hugo server --minify --themesDir ../..
baseURL = 'https://example.com/'
baseURL = 'http://0.0.0.0:1313/hugo-book/'
title = 'Hugo Book'
theme = 'hugo-book'
@@ -72,28 +72,23 @@ enableGitInfo = true
# For backward compatibility you can set '*' to render all sections to menu. Acts same as '/'
BookSection = 'docs'
# Set source repository location.
# Used for 'Last Modified' and 'Edit this page' links.
BookRepo = 'https://github.com/alex-shpak/hugo-book'
# (Optional, default none) Set template for commit link for the page. Requires enableGitInfo.
# When set enabled 'Last Modified' and a link to the commit in the footer of the page.
# Param is executed as template using .Site, .Page and .GitInfo as context.
BookLastChangeLink = 'https://github.com/alex-shpak/hugo-book/commit/{{ .GitInfo.Hash }}'
# (Optional, default 'commit') Specifies commit portion of the link to the page's last modified
# commit hash for 'doc' page type.
# Requires 'BookRepo' param.
# Value used to construct a URL consisting of BookRepo/BookCommitPath/<commit-hash>
# Github uses 'commit', Bitbucket uses 'commits'
# BookCommitPath = 'commit'
# (Optional, default none) Set template for edit page link.
# When set enabled 'Edit this page' link in the footer of the page.
# Param is executed as template using .Site, .Page and .Path as context.
BookEditLink = 'https://github.com/alex-shpak/hugo-book/edit/main/exampleSite/{{ .Path }}'
# Enable "Edit this page" links for 'doc' page type.
# Disabled by default. Uncomment to enable. Requires 'BookRepo' param.
# Edit path must point to root directory of repo.
BookEditPath = 'edit/main/exampleSite'
# Configure the date format used on the pages
# (Optional, default 'January 2, 2006') Configure the date format used on the pages
# - In git information
# - In blog posts
# https://gohugo.io/functions/time/format/
BookDateFormat = 'January 2, 2006'
# (Optional, default true) Enables search function with flexsearch,
# (Optional, default true) Enables search function with fuse.js.,
# Index is built on fly, therefore it might slowdown your website.
# Configuration for indexing can be adjusted in i18n folder per language.
BookSearch = true
+12 -17
View File
@@ -1,6 +1,6 @@
# hugo server --minify --themesDir ../.. --baseURL=http://0.0.0.0:1313/theme/hugo-book/
# hugo server --minify --themesDir ../..
baseURL: https://example.com/
baseURL: http://0.0.0.0:1313/hugo-book/
title: Hugo Book
theme: hugo-book
@@ -68,25 +68,20 @@ params:
# For backward compatibility you can set '*' to render all sections to menu. Acts same as '/'
BookSection: docs
# Set source repository location.
# Used for 'Last Modified' and 'Edit this page' links.
BookRepo: https://github.com/alex-shpak/hugo-book
# (Optional, default none) Set template for commit link for the page. Requires enableGitInfo.
# When set enabled 'Last Modified' and a link to the commit in the footer of the page.
# Param is executed as template using .Site, .Page and .GitInfo as context.
BookLastChangeLink: 'https://github.com/alex-shpak/hugo-book/commit/{{ .GitInfo.Hash }}'
# (Optional, default 'commit') Specifies commit portion of the link to the page's last modified
# commit hash for 'doc' page type.
# Requires 'BookRepo' param.
# Value used to construct a URL consisting of BookRepo/BookCommitPath/<commit-hash>
# Github uses 'commit', Bitbucket uses 'commits'
# BookCommitPath: commit
# (Optional, default none) Set template for edit page link.
# When set enabled 'Edit this page' link in the footer of the page.
# Param is executed as template using .Site, .Page and .Path as context.
BookEditLink: 'https://github.com/alex-shpak/hugo-book/edit/main/exampleSite/{{ .Path }}'
# Enable "Edit this page" links for 'doc' page type.
# Disabled by default. Uncomment to enable. Requires 'BookRepo' param.
# Edit path must point to root directory of repo.
BookEditPath: edit/main/exampleSite
# Configure the date format used on the pages
# (Optional, default 'January 2, 2006') Configure the date format used on the pages
# - In git information
# - In blog posts
# https://gohugo.io/functions/time/format/
BookDateFormat: "January 2, 2006"
# (Optional, default true) Enables search function with flexsearch,
+7 -7
View File
@@ -1,22 +1,22 @@
<div class="flex flex-wrap justify-between">
{{ if and .GitInfo .Site.Params.BookRepo }}
<div>
{{- $date := partial "docs/date" (dict "Date" .GitInfo.AuthorDate.Local "Format" .Site.Params.BookDateFormat) -}}
{{ if and .GitInfo .Site.Params.BookLastChangeLink }}
<div>
{{- $date := partial "docs/date" (dict "Date" .Lastmod "Format" .Site.Params.BookDateFormat) -}}
<a class="flex align-center" href="{{ partial "docs/links/commit" . }}" title='{{ i18n "Last modified by" }} {{ .GitInfo.AuthorName }} | {{ $date }}' target="_blank" rel="noopener">
<img src="{{ "svg/calendar.svg" | relURL }}" class="book-icon" alt="" />
<span>{{ $date }}</span>
</a>
</div>
</div>
{{ end }}
{{ if and .File .Site.Params.BookRepo .Site.Params.BookEditPath }}
<div>
{{ if and .File .Site.Params.BookEditLink }}
<div>
<a class="flex align-center" href="{{ partial "docs/links/edit" . }}" target="_blank" rel="noopener">
<img src="{{ "svg/edit.svg" | relURL }}" class="book-icon" alt="" />
<span>{{ i18n "Edit this page" }}</span>
</a>
</div>
</div>
{{ end }}
</div>
+5 -2
View File
@@ -1,2 +1,5 @@
{{- $commitPath := default "commit" .Site.Params.BookCommitPath -}}
{{- .Site.Params.BookRepo }}/{{ $commitPath }}/{{ .GitInfo.Hash -}}
{{- return partial "docs/text/template" (dict "Template" .Site.Params.BookLastChangeLink "Context" (dict
"Site" .Site
"Page" .Page
"GitInfo" .GitInfo
)) -}}
+5 -2
View File
@@ -1,2 +1,5 @@
{{- $bookFilePath := (strings.TrimPrefix hugo.WorkingDir .Page.File.Filename | path.Join) -}}
{{- .Site.Params.BookRepo }}/{{ .Site.Params.BookEditPath }}{{ ($bookFilePath) -}}
{{- return partial "docs/text/template" (dict "Template" .Site.Params.BookEditLink "Context" (dict
"Site" .Site
"Page" .Page
"Path" (strings.TrimPrefix hugo.WorkingDir .Page.File.Filename)
)) -}}
@@ -0,0 +1,9 @@
<!--
Returns rendered string from template and context.
Usage: partial "docs/string-template" (dict "Template" "param={{ . }}" "Context" "Input")
-->
{{- $checksum := . | encoding.Jsonify | crypto.SHA1 | printf "book-%s" -}}
{{- $template := resources.FromString $checksum .Template -}}
{{- $template = $template | resources.ExecuteAsTemplate $checksum .Context -}}
{{- return $template.Content -}}