diff --git a/README.md b/README.md index df5538c..36af809 100644 --- a/README.md +++ b/README.md @@ -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/ - # 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 `` - [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. diff --git a/archetypes/docs.md b/archetypes/docs.md index 17e014c..5a09ba1 100644 --- a/archetypes/docs.md +++ b/archetypes/docs.md @@ -7,4 +7,5 @@ weight: 1 # bookCollapseSection: false # bookComments: false # bookSearchExclude: false +# bookHref: '' --- diff --git a/exampleSite/hugo.toml b/exampleSite/hugo.toml index 34af293..ad0f4dd 100644 --- a/exampleSite/hugo.toml +++ b/exampleSite/hugo.toml @@ -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/ - # 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 diff --git a/exampleSite/hugo.yaml b/exampleSite/hugo.yaml index 3fd0c40..82c8c96 100644 --- a/exampleSite/hugo.yaml +++ b/exampleSite/hugo.yaml @@ -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/ - # 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, diff --git a/layouts/_partials/docs/footer.html b/layouts/_partials/docs/footer.html index 7fcc648..65dee08 100644 --- a/layouts/_partials/docs/footer.html +++ b/layouts/_partials/docs/footer.html @@ -1,22 +1,22 @@
-{{ if and .GitInfo .Site.Params.BookRepo }} -
- {{- $date := partial "docs/date" (dict "Date" .GitInfo.AuthorDate.Local "Format" .Site.Params.BookDateFormat) -}} - - - {{ $date }} - -
+{{ if and .GitInfo .Site.Params.BookLastChangeLink }} +
+ {{- $date := partial "docs/date" (dict "Date" .Lastmod "Format" .Site.Params.BookDateFormat) -}} + + + {{ $date }} + +
{{ end }} -{{ if and .File .Site.Params.BookRepo .Site.Params.BookEditPath }} -
- - - {{ i18n "Edit this page" }} - -
+{{ if and .File .Site.Params.BookEditLink }} +
+ + + {{ i18n "Edit this page" }} + +
{{ end }}
diff --git a/layouts/_partials/docs/links/commit.html b/layouts/_partials/docs/links/commit.html index 8ab9334..48deeab 100644 --- a/layouts/_partials/docs/links/commit.html +++ b/layouts/_partials/docs/links/commit.html @@ -1,2 +1,5 @@ -{{- $commitPath := default "commit" .Site.Params.BookCommitPath -}} -{{- .Site.Params.BookRepo }}/{{ $commitPath }}/{{ .GitInfo.Hash -}} \ No newline at end of file +{{- return partial "docs/text/template" (dict "Template" .Site.Params.BookLastChangeLink "Context" (dict + "Site" .Site + "Page" .Page + "GitInfo" .GitInfo +)) -}} \ No newline at end of file diff --git a/layouts/_partials/docs/links/edit.html b/layouts/_partials/docs/links/edit.html index 920affa..103bc5b 100644 --- a/layouts/_partials/docs/links/edit.html +++ b/layouts/_partials/docs/links/edit.html @@ -1,2 +1,5 @@ -{{- $bookFilePath := (strings.TrimPrefix hugo.WorkingDir .Page.File.Filename | path.Join) -}} -{{- .Site.Params.BookRepo }}/{{ .Site.Params.BookEditPath }}{{ ($bookFilePath) -}} \ No newline at end of file +{{- return partial "docs/text/template" (dict "Template" .Site.Params.BookEditLink "Context" (dict + "Site" .Site + "Page" .Page + "Path" (strings.TrimPrefix hugo.WorkingDir .Page.File.Filename) +)) -}} \ No newline at end of file diff --git a/layouts/_partials/docs/text/template.html b/layouts/_partials/docs/text/template.html new file mode 100644 index 0000000..53e535d --- /dev/null +++ b/layouts/_partials/docs/text/template.html @@ -0,0 +1,9 @@ + + +{{- $checksum := . | encoding.Jsonify | crypto.SHA1 | printf "book-%s" -}} +{{- $template := resources.FromString $checksum .Template -}} +{{- $template = $template | resources.ExecuteAsTemplate $checksum .Context -}} +{{- return $template.Content -}} \ No newline at end of file