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
+15 -15
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) -}}
<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>
{{ 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>
{{ end }}
{{ if and .File .Site.Params.BookRepo .Site.Params.BookEditPath }}
<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>
{{ 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>
{{ 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 -}}