Breaking changes, rewrite; add support for plain text output and single page mode

This commit is contained in:
Alex Shpak
2026-05-14 23:55:08 +02:00
parent 4018d4b51d
commit c6ef0a08c2
36 changed files with 165 additions and 72 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
<h2 class="book-brand">
<a class="flex align-center" href="{{ cond (not .Site.Home.File) hugo.Sites.Default.Home.RelPermalink .Site.Home.RelPermalink }}">
<a class="flex align-center" href="{{ partial "docs/links/home" . }}">
{{- with .Site.Params.BookLogo -}}
<img src="{{ . | relURL }}" alt="{{ partial "docs/text/i18n" "Logo" }}" />
{{- end -}}
+1 -1
View File
@@ -1,2 +1,2 @@
<!-- This partial can be replaced to support other commenting engines -->
{{/* This partial can be replaced to support other commenting engines */}}
{{ partial "disqus.html" . }}
+2 -2
View File
@@ -1,6 +1,6 @@
<!--
{{/*
Returns formatted date.
Usage: partial "docs/date" (dict "Date" .Date "Format" .Site.Params.BookDateFormat)
-->
*/}}
{{- $format := default "January 2, 2006" .Format -}}
{{- return (time.Format $format .Date) -}}
+9
View File
@@ -10,6 +10,15 @@
{{ end }}
</div>
<div>
{{ with .OutputFormats.Get "txt" }}
<a class="flex align-center" href="{{ .RelPermalink }}">
<img src="{{ partial "docs/icon" "markdown" }}" class="book-icon" alt="{{ partial "docs/text/i18n" "Markdown" }}" />
<span>{{ partial "docs/text/i18n" "Source" }}</span>
</a>
{{ end }}
</div>
<div>
{{ if and .File .Site.Params.BookEditLink }}
<a class="flex align-center" href="{{ partial "docs/links/edit" . }}" target="_blank" rel="noopener edit">
+2 -3
View File
@@ -47,9 +47,8 @@ https://github.com/alex-shpak/hugo-book
{{ partial "google_analytics.html" . }}
<!-- RSS -->
{{- with .OutputFormats.Get "rss" -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }}
{{- range .AlternativeOutputFormats -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Title | safeHTML }}
{{ end -}}
{{- define "integrity" -}}
+1
View File
@@ -0,0 +1 @@
{{ return cond (not .Site.Home.File) hugo.Sites.Default.Home.RelPermalink .Site.Home.RelPermalink }}
+1 -6
View File
@@ -1,9 +1,4 @@
{{ $bookSection := default "docs" .Site.Params.BookSection }}
{{ if eq $bookSection "*" }}
{{ $bookSection = "/" }}{{/* Backward compatibility */}}
{{ end }}
{{ with .Site.GetPage $bookSection }}
{{ with (partialCached "docs/menu-section" .Site) }}
{{ template "book-section-children" (dict "Section" . "CurrentPage" $) }}
{{ end }}
+2 -2
View File
@@ -1,7 +1,7 @@
<!--
{{/*
This is template for hugo menus, accepts Page and Menu as context
https://gohugo.io/variables/menus/
-->
*/}}
{{- if .Menu -}}
{{- template "book-menu-hugo" . -}}
{{- end -}}
@@ -0,0 +1,16 @@
{{/* Recursively creates a slice of pages under given page */}}
{{ define "book-menu-recurse" }}
{{ if not .Page.Params.BookHidden }}
{{ if .Page.Content }}
{{ .Scratch.Add "BookPages" (slice .Page) }}
{{ end }}
{{ range .Page.Pages }}
{{ template "book-menu-recurse" (dict "Scratch" $.Scratch "Page" .) }}
{{ end }}
{{ end }}
{{ end }}
{{ $scratch := newScratch }}
{{ template "book-menu-recurse" (dict "Scratch" $scratch "Page" .) }}
{{ return $scratch.Get "BookPages" }}
+8
View File
@@ -0,0 +1,8 @@
{{/* returns the section to be rendered as menu */}}
{{ $bookSection := default "docs" .Params.BookSection }}
{{ $section := .GetPage (cond (eq $bookSection "*") "/" $bookSection) }}
{{ if $section }}
{{ return $section }}
{{ else }}
{{ errorf "%s: Section '%s' not found, check BookSection theme parameter" $ $bookSection }}
{{ end }}
@@ -1,14 +0,0 @@
{{ $scratch := newScratch }}
{{ template "recurse" (dict "Scratch" $scratch "Sections" .) }}
{{ define "recurse" }}
{{ range .Sections }}
{{ if and .Content (not .Params.BookHidden) }}
{{ $.Scratch.Add "BookPages" (slice .) }}
{{ end }}
{{ if .IsSection }}
{{ template "recurse" (dict "Scratch" $.Scratch "Sections" .Pages) }}
{{ end }}
{{ end }}
{{ end }}
{{ return $scratch.Get "BookPages" }}
+7 -12
View File
@@ -1,14 +1,9 @@
{{ $bookSection := default "docs" .Site.Params.BookSection }}
{{ if eq $bookSection "*" }}
{{ $bookSection = "/" }}{{/* Backward compatibility */}}
{{ end }}
{{- with (partialCached "docs/menu-section" .Site) -}}
{{- $pages := partialCached "docs/menu-section-pages" . -}}
{{- $prev := $pages.Next $ -}}
{{- $next := $pages.Prev $ -}}
{{ with .Site.GetPage $bookSection }}
{{ $pages := partialCached "docs/prev-next-cache" .Pages }}
{{ $prev := $pages.Next $ }}
{{ $next := $pages.Prev $ }}
{{- if or $prev $next }}
{{- if or $prev $next -}}
<div class="flex flex-wrap justify-between">
<span>
{{ with $prev }}
@@ -27,5 +22,5 @@
{{ end }}
</span>
</div>
{{ end -}}
{{ end }}
{{- end -}}
{{- end -}}
+2 -3
View File
@@ -1,8 +1,7 @@
<!--
{{/*
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 -}}
+2 -2
View File
@@ -1,7 +1,7 @@
<!--
{{/*
Partial to generate page name from Title or File name.
Accepts Page as context
-->
*/}}
{{ $title := "" }}
{{ if .LinkTitle }}
-1
View File
@@ -1,5 +1,4 @@
{{- return and
(not (eq .Params.bookToC false))
(not (eq .Site.Params.BookToC false))
(not (eq .TableOfContents "<nav id=\"TableOfContents\"></nav>"))
-}}
+1 -1
View File
@@ -1,6 +1,6 @@
{{- $ratio := (split (.Get "ratio") ":") -}}
{{- if strings.Contains .InnerDeindent "<--->" -}}
{{- warnf "Columns shortcode separator '<--->' is deprecated, use markdown list instead." -}}
{{- warnf "{{<columns>}} shortcode separator '<--->' is deprecated, use markdown list instead." -}}
{{- $attributes := partial "docs/text/mapper" (dict
"attributes" (cond .IsNamedParams .Params dict)
"merge" (dict
+1 -1
View File
@@ -1,4 +1,4 @@
{{- warnf "Hint shortcode is deprecated, use markdown alerts format: '> [!NOTE] ...'" -}}
{{- warnf "{{<hint>}} shortcode is deprecated, use markdown alerts format: '> [!NOTE] ...'" -}}
{{- $attributes := partial "docs/text/mapper" (dict
"attributes" (cond .IsNamedParams .Params dict)
"merge" (dict
+1 -1
View File
@@ -1,4 +1,4 @@
{{- warnf "Section shortcode is deprecated and will be removed" -}}
{{- warnf "{{<section>}} shortcode is deprecated and will be removed" -}}
<dl>
{{ range .Page.Pages }}
<dt>
+7
View File
@@ -0,0 +1,7 @@
{{ .Site.Title }}
{{ $section := partialCached "docs/menu-section" .Site -}}
{{- range (partialCached "docs/menu-section-pages" $section) }}
- {{ partial "docs/title" . }}: {{ default .Permalink .Params.BookHref }}
{{- end }}
{{ .RawContent }}
-1
View File
@@ -64,7 +64,6 @@
{{ end }}
{{ define "clipboard" }}
<!-- Clipboard -->
{{ with resources.Get "clipboard.js" | resources.Minify }}
<script>{{ .Content | safeJS }}</script>
{{ end }}
+30
View File
@@ -0,0 +1,30 @@
{{ define "menu-container" }}
<!-- -->
{{ end }}
{{ define "toc" }}
{{ partial "docs/brand" . }}
<nav id="TableOfContents">
<ul>
{{- $section := partialCached "docs/menu-section" .Site -}}
{{- range (partialCached "docs/menu-section-pages" $section) }}
<li>
<a href="#{{ partial "docs/title" . | anchorize }}">{{ partial "docs/title" . }}</a>
</li>
{{ end }}
</ul>
</nav>
{{ end }}
{{ define "footer" }}
<!-- -->
{{ end }}
{{ define "main" }}
<article class="markdown">
{{- $section := partialCached "docs/menu-section" .Site -}}
{{- range partialCached "docs/menu-section-pages" $section }}
<section id="{{ partial "docs/title" . | anchorize }}">{{ .Content }}</section>
{{ end }}
</article>
{{ end }}
+10
View File
@@ -0,0 +1,10 @@
{{ .Site.Title }}
{{ $section := partialCached "docs/menu-section" .Site -}}
{{- range (partialCached "docs/menu-section-pages" $section) }}
- {{ partial "docs/title" . }}: {{ default .Permalink .Params.BookHref }}
{{- end }}
{{ $section := partialCached "docs/menu-section" .Site -}}
{{- range (partialCached "docs/menu-section-pages" $section) -}}
{{- .RawContent }}
{{ end -}}
+1 -1
View File
@@ -16,4 +16,4 @@
{{ define "footer" }}
{{ partial "docs/post-prev-next" . }}
{{ end }}
{{ end }}