theme: add new source output format #1001

This commit is contained in:
Sören Weber 2025-01-29 14:19:21 +01:00
parent c6cec2de3e
commit 44f7ff47ee
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
46 changed files with 201 additions and 20 deletions

View file

@ -141,7 +141,13 @@ disableBreadcrumb = false
# This can be overridden in the page's frontmatter.
disableMarkdownButton = false
# Hide the print button.
# Hide the Source button.
# Default: false
# This hides the Source button if you activated the Source output format.
# This can be overridden in the page's frontmatter.
disableSourceButton = false
# Hide the Print button.
# Default: false
# This hides the print button if you activated the print output format.
# This can be overridden in the page's frontmatter.

View file

@ -58,7 +58,13 @@ disableBreadcrumb = false
# If not set, the set value of your site's hugo.toml is used.
disableMarkdownButton = false
# Hide the print button.
# Hide the Source button.
# Default: false
# This hides the Source button if you activated the Source output format.
# If not set, the set value of your site's hugo.toml is used.
disableSourceButton = false
# Hide the Print button.
# Default: false
# This hides the print button if you activated the print output format.
# If not set, the set value of your site's hugo.toml is used.

View file

@ -1,9 +1,9 @@
+++
categories = ["howto"]
description = "Configure the topbar"
frontmatter = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"]
options = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"]
outputs = ["html", "rss", "print", "markdown"]
frontmatter = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disableSourceButton", "disablePrintButton", "disableToc", "editURL"]
options = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disableSourceButton", "disablePrintButton", "disableToc", "editURL"]
outputs = ["html", "rss", "print", "markdown", "source"]
title = "Topbar"
weight = 4
+++
@ -16,6 +16,7 @@ Your topbar contains the following elements. Some of them are configuarable:
- {{% button style="transparent" icon="list-alt" %}}{{% /button %}} **toc**: [opens the table of contents in an overlay](#table-of-contents)
- {{% button style="transparent" icon="empty" %}}{{% /button %}} **breadcrumb**: shows the clickable [breadcrumbs](#breadcrumbs)
- {{% button style="transparent" icon="pen" %}}{{% /button %}} **edit**: browses to the editable page if the `editURL` [parameter is set](#edit-button)
- {{% button style="transparent" icon="file-code" %}}{{% /button %}} **source**: browses to the [chapters source code](#source-button) if [source support](configuration/sitemanagement/outputformats#source-support) was activated
- {{% button style="transparent" icon="fa-fw fab fa-markdown" %}}{{% /button %}} **markdown**: browses to the [chapters Markdown source](#markdown-button) if [markdown support](configuration/sitemanagement/outputformats#markdown-support) was activated
- {{% button style="transparent" icon="print" %}}{{% /button %}} **print**: browses to the [chapters printable page](#print-button) if [print support](configuration/sitemanagement/outputformats#print-support) was activated
- {{% button style="transparent" icon="chevron-left" %}}{{% /button %}} **prev**: browses to the [previous page](#arrow-navigation) if there is one
@ -58,6 +59,14 @@ editURL = 'https://github.com/McShelby/hugo-theme-relearn/edit/main/exampleSite/
disableMarkdownButton = true
{{< /multiconfig >}}
## Source Button
{{% badge style="cyan" icon="gears" title=" " %}}Option{{% /badge %}} {{% badge style="green" icon="fa-fw fab fa-markdown" title=" " %}}Front Matter{{% /badge %}} You can hide the Source button if the [Source output format](configuration/sitemanagement/outputformats/#source-support) is active by setting `disableSourceButton=true`.
{{< multiconfig >}}
disableSourceButton = true
{{< /multiconfig >}}
## Print Button
{{% badge style="cyan" icon="gears" title=" " %}}Option{{% /badge %}} {{% badge style="green" icon="fa-fw fab fa-markdown" title=" " %}}Front Matter{{% /badge %}} You can hide the print button if the [print output format](configuration/sitemanagement/outputformats/#print-support) is active by setting `disablePrintButton=true`.

View file

@ -1,9 +1,9 @@
+++
categories = ["howto"]
description = "Configure the topbar"
frontmatter = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"]
options = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"]
outputs = ["html", "rss", "print", "markdown"]
frontmatter = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disableSourceButton", "disablePrintButton", "disableToc", "editURL"]
options = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disableSourceButton", "disablePrintButton", "disableToc", "editURL"]
outputs = ["html", "rss", "print", "markdown", "source"]
title = "Topbarrr"
weight = 4
+++

View file

@ -2,7 +2,7 @@
categories = ["explanation", "reference"]
description = "How to extend the topbar"
options = ["editURL"]
outputs = ["html", "rss", "print", "markdown"]
outputs = ["html", "rss", "print", "markdown", "source"]
title = "Topbar"
weight = 4
+++
@ -36,6 +36,7 @@ The theme ships with the following predefined buttons (from left to right in the
- {{% button style="transparent" icon="bars" %}}{{% /button %}} [**sidebar**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/sidebar.html): opens the sidebar flyout if in mobile layout
- {{% button style="transparent" icon="list-alt" %}}{{% /button %}} [**toc**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/toc.html): [opens the table of contents in an overlay](authoring/frontmatter/topbar#table-of-contents)
- {{% button style="transparent" icon="pen" %}}{{% /button %}} [**edit**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/edit.html): browses to the editable page if the `editURL` [parameter is set](authoring/frontmatter/topbar#edit-button)
- {{% button style="transparent" icon="file-code" %}}{{% /button %}} **source**: [**source**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/markdown.html): browses to the chapter's source code if [markdown support](configuration/sitemanagement/outputformats#source-support) was activated
- {{% button style="transparent" icon="fa-fw fab fa-markdown" %}}{{% /button %}} [**markdown**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/markdown.html): browses to the chapter's markdown source if [markdown support](configuration/sitemanagement/outputformats#markdown-support) was activated
- {{% button style="transparent" icon="print" %}}{{% /button %}} [**print**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/print.html): browses to the chapter's printable page if [print support](configuration/sitemanagement/outputformats#print-support) was activated
- {{% button style="transparent" icon="chevron-left" %}}{{% /button %}} [**prev**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/prev.html): browses to the [previous page](authoring/frontmatter/topbar#arrow-navigation) if there is one

View file

@ -2,7 +2,7 @@
categories = ["explanation", "reference"]
description = "How to extend the topbar"
options = ["editURL"]
outputs = ["html", "rss", "print", "markdown"]
outputs = ["html", "rss", "print", "markdown", "source"]
title = "Topbarrr"
weight = 4
+++

View file

@ -1,7 +1,7 @@
+++
categories = ["howto"]
description = "What formats can a page be displayed in"
outputs = ["html", "rss", "print", "markdown"]
outputs = ["html", "rss", "print", "markdown", "source"]
title = "Available Output Formats"
weight = 5
+++
@ -42,7 +42,7 @@ If you don't like the URLs, you can reconfigure `outputFormats.print` in your `h
## Markdown Support
Enable support to show the Markdown source of a page . Add the `markdown` output format to your home, section, and page in `hugo.toml`:
Enable support to show the Markdown source of a page. Add the `markdown` output format to your home, section, and page in `hugo.toml`:
{{< multiconfig file=hugo >}}
[outputs]
@ -51,6 +51,36 @@ Enable support to show the Markdown source of a page . Add the `markdown` output
page = ['html', 'rss', 'markdown']
{{< /multiconfig >}}
By default this adds a Markdown icon in the topbar but [can be deactived](authoring/frontmatter/topbar/#markdown-button). Clicking it switches to the Markdown source of the page.
By default this adds a Markdown icon in the topbar but [can be deactived](authoring/frontmatter/topbar/#markdown-button). Clicking it switches to the Markdown source including the title of the page.
The `markdown` output format configuration is [provided by Hugo](https://gohugo.io/templates/output-formats/#output-format-definitions).
## Source Support
Enable support to show the source code of a page if it was generated from a file. Add the `source` output format to your home, section, and page in `hugo.toml`:
{{< multiconfig file=hugo >}}
[outputs]
home = ['html', 'rss', 'source']
section = ['html', 'rss', 'source']
page = ['html', 'rss', 'source']
{{< /multiconfig >}}
By default this adds a Source icon in the topbar but [can be deactived](authoring/frontmatter/topbar/#source-button). Clicking it switches to the source code of the page.
The Source output format differs from the Markdown format, as it prints the source code _as is_ including the front matter.
The URL won't be [configured ugly](https://gohugo.io/templates/output-formats/#configure-output-formats) for [Hugo's URL handling](https://gohugo.io/content-management/urls/#ugly-urls), even with `uglyURLs=true` in `hugo.toml`. This is because each mime type can only have one suffix.
If you don't like the URLs, you can reconfigure `outputFormats.source` in your `hugo.toml` to something other than the default of:
{{< multiconfig file=hugo >}}
[outputFormats]
[outputFormats.source]
name= 'source'
baseName = 'index.source'
isHTML = false
mediaType = 'text/markdown'
permalinkable = false
noUgly = true
{{< /multiconfig >}}

View file

@ -1,7 +1,7 @@
+++
categories = ["howto"]
description = "What formats can a page be displayed in"
outputs = ["html", "rss", "print", "markdown"]
outputs = ["html", "rss", "print", "markdown", "source"]
title = "Available Output Formats"
weight = 5
+++

View file

@ -14,9 +14,9 @@ weight = -3
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The topbar button for the print format [can now be hidden](authoring/frontmatter/topbar/#print-button) if the print output format is active by setting `disablePrintButton=true` in your `hugo.toml` or Front Matter.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme supports the new [`markdown` output format](configuration/sitemanagement/outputformats/#markdown-support) which behaves similar in configuration as the `print` output format but allows the original Markdown source of a page to be viewed.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme supports the new [`markdown` output format](configuration/sitemanagement/outputformats/#markdown-support) which behaves similar in configuration as the `print` output format but allows the Markdown source of a page to be viewed.
You can see this in action on the above linked page, accessible by clikcking the topbar button.
You can see this in action on the above linked page, accessible by clicking the topbar button.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Keyboard support for code blocks was improved so the _copy to clipboard_ button is now reachable by <kbd>TAB</kbd> if `disableHoverBlockCopyToClipBoard=false` was set in the `hugo.toml`.

View file

@ -11,3 +11,7 @@ weight = -4
### New
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Table headers are sticky now.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme supports the new [`source` output format](configuration/sitemanagement/outputformats/#source-support) which behaves similar in configuration as the `markdown` output format but allows the original Markdown source including the front matter of a page to be viewed.
You can see this in action on the above linked page, accessible by clicking the topbar button.

View file

@ -43,6 +43,9 @@ other = "Edit"
[Show-Markdown]
other = "Show Marrrkd'n"
[Show-source]
other = "Show source code"
[Print-this-chapter]
other = "Prrrint whole chapterrr"

View file

@ -15,6 +15,14 @@
permalinkable = false
noUgly = true
[outputFormats.source]
name= 'source'
baseName = 'index.source'
isHTML = false
mediaType = 'text/markdown'
permalinkable = false
noUgly = true
# unused since 7.0.0 but left in here to generate warnings
[outputFormats.search]
name= 'search'

View file

@ -43,6 +43,9 @@ other = "حرر"
[Show-Markdown]
other = "إظهار Markdown"
[Show-source]
other = "إظهار شفرة المصدر"
[Print-this-chapter]
other = "طباعة الفصل بأكمله"

View file

@ -43,6 +43,9 @@ other = "Upravit"
[Show-Markdown]
other = "Zobrazit Markdown"
[Show-source]
other = "Zobrazit zdrojový kód"
[Print-this-chapter]
other = "Vytisknout kapitolu"

View file

@ -43,6 +43,9 @@ other = "Bearbeiten"
[Show-Markdown]
other = "Markdown anzeigen"
[Show-source]
other = "Quelldatei anzeigen"
[Print-this-chapter]
other = "Ganzes Kapitel drucken"

View file

@ -43,6 +43,9 @@ other = "Edit"
[Show-Markdown]
other = "Show Markdown"
[Show-source]
other = "Show source code"
[Print-this-chapter]
other = "Print whole chapter"

View file

@ -43,6 +43,9 @@ other = "Editar"
[Show-Markdown]
other = "Mostrar Markdown"
[Show-source]
other = "Mostrar código fuente"
[Print-this-chapter]
other = "Imprimir todo el capítulo"

View file

@ -43,6 +43,9 @@ other = "ویرایش"
[Show-Markdown]
other = "نمایش Markdown"
[Show-source]
other = "نمایش کد منبع"
[Print-this-chapter]
other = "چاپ کل فصل"

View file

@ -43,6 +43,9 @@ other = "Muokkaa"
[Show-Markdown]
other = "Näytä Markdown"
[Show-source]
other = "Näytä lähdekoodi"
[Print-this-chapter]
other = "Tulosta koko luku"

View file

@ -43,6 +43,9 @@ other = "Éditer"
[Show-Markdown]
other = "Afficher Markdown"
[Show-source]
other = "Afficher le code source"
[Print-this-chapter]
other = "Imprimer le chapitre entier"

View file

@ -43,6 +43,9 @@ other = "संपादन करना"
[Show-Markdown]
other = "मार्कडाउन दिखाएं"
[Show-source]
other = "स्रोत कोड दिखाएं"
[Print-this-chapter]
other = "पूरा अध्याय मुद्रित करें"

View file

@ -43,6 +43,9 @@ other = "Szerkesztés"
[Show-Markdown]
other = "Markdown megjelenítése"
[Show-source]
other = "Forráskód megjelenítése"
[Print-this-chapter]
other = "Teljes fejezet nyomtatása"

View file

@ -43,6 +43,9 @@ other = "Mengedit"
[Show-Markdown]
other = "Tampilkan Markdown"
[Show-source]
other = "Tampilkan kode sumber"
[Print-this-chapter]
other = "Mencetak seluruh bab"

View file

@ -43,6 +43,9 @@ other = "Modifica"
[Show-Markdown]
other = "Mostra Markdown"
[Show-source]
other = "Mostra il codice sorgente"
[Print-this-chapter]
other = "Stampa l'intero capitolo"

View file

@ -43,6 +43,9 @@ other = "編集"
[Show-Markdown]
other = "マークダウンを表示"
[Show-source]
other = "ソースコードを表示"
[Print-this-chapter]
other = "章全体を印刷する"

View file

@ -43,6 +43,9 @@ other = "편집"
[Show-Markdown]
other = "마크다운 표시"
[Show-source]
other = "소스 코드 표시"
[Print-this-chapter]
other = "전체 장 인쇄"

View file

@ -43,6 +43,9 @@ other = "Bewerken"
[Show-Markdown]
other = "Afprijzing weergeven"
[Show-source]
other = "Broncode weergeven"
[Print-this-chapter]
other = "Het hele hoofdstuk afdrukken"

View file

@ -43,6 +43,9 @@ other = "Edycja"
[Show-Markdown]
other = "Pokaż język Markdown"
[Show-source]
other = "Pokaż kod źródłowy"
[Print-this-chapter]
other = "Drukowanie całego rozdziału"

View file

@ -43,6 +43,9 @@ other = "Editar"
[Show-Markdown]
other = "Mostrar Markdown"
[Show-source]
other = "Mostrar código-fonte"
[Print-this-chapter]
other = "Imprimir capítulo inteiro"

View file

@ -43,6 +43,9 @@ other = "Editează"
[Show-Markdown]
other = "Afișează Markdown"
[Show-source]
other = "Afișați codul sursă"
[Print-this-chapter]
other = "Tipărește întregul capitol"

View file

@ -43,6 +43,9 @@ other = "редактировать"
[Show-Markdown]
other = "Показать Markdown"
[Show-source]
other = "Показать исходный код"
[Print-this-chapter]
other = "Печать всей главы"

View file

@ -43,6 +43,9 @@ other = "Hariri"
[Show-Markdown]
other = "Onyesha Alama"
[Show-source]
other = "Onyesha msimbo wa chanzo"
[Print-this-chapter]
other = "Chapisha sura nzima"

View file

@ -43,6 +43,9 @@ other = "Düzenlemek"
[Show-Markdown]
other = "Markdown'ı Göster"
[Show-source]
other = "Kaynak kodunu göster"
[Print-this-chapter]
other = "Bölümün tamamını yazdır"

View file

@ -43,6 +43,9 @@ other = "Biên tập"
[Show-Markdown]
other = "Hiển thị Markdown"
[Show-source]
other = "Hiển thị mã nguồn"
[Print-this-chapter]
other = "In toàn bộ chương"

View file

@ -43,6 +43,9 @@ other = "编辑"
[Show-Markdown]
other = "显示 Markdown"
[Show-source]
other = "显示源代码"
[Print-this-chapter]
other = "打印整章"

View file

@ -43,6 +43,9 @@ other = "编辑"
[Show-Markdown]
other = "显示 Markdown"
[Show-source]
other = "显示源代码"
[Print-this-chapter]
other = "打印整章"

View file

@ -43,6 +43,9 @@ other = "編輯網頁"
[Show-Markdown]
other = "顯示 Markdown"
[Show-source]
other = "顯示原始程式碼"
[Print-this-chapter]
other = "列印整章"

View file

@ -43,6 +43,9 @@ other = "編輯網頁"
[Show-Markdown]
other = "顯示 Markdown"
[Show-source]
other = "顯示原始程式碼"
[Print-this-chapter]
other = "列印整章"

View file

@ -43,6 +43,9 @@ other = "编辑"
[Show-Markdown]
other = "显示 Markdown"
[Show-source]
other = "显示源代码"
[Print-this-chapter]
other = "打印整章"

View file

@ -1,4 +1,6 @@
{{/* the following check avoids to print out content of headless bundles if called from nestedContent.gotmpl */}}
{{- if .RelPermalink }}
{{- .RawContent }}
{{- end }}
{{- if .RelPermalink -}}
# {{ .Title }}
{{ strings.TrimLeft "\n\r\t " .RawContent }}
{{- end }}

View file

@ -0,0 +1,4 @@
{{/* the following check avoids to print out content of headless bundles if called from nestedContent.gotmpl */}}
{{- if and .File .File.Filename -}}
{{ readFile .File.Filename | safeHTML }}
{{- end }}

View file

@ -0,0 +1 @@
{{ define "_empty" }}{{ end }}

View file

@ -0,0 +1 @@
{{ define "_empty" }}{{ end }}

View file

@ -1,6 +1,9 @@
{{- partial "topbar/button/edit.html" (dict
"page" .
)}}
{{- partial "topbar/button/source.html" (dict
"page" .
)}}
{{- partial "topbar/button/markdown.html" (dict
"page" .
)}}

View file

@ -0,0 +1,22 @@
{{- $onwidths := cond (isset . "onwidths") .onwidths "area-more" }}
{{- $onwidthm := cond (isset . "onwidthm") .onwidthm "show" }}
{{- $onwidthl := cond (isset . "onwidthl") .onwidthl "show" }}
{{- with .page }}
{{- $format := .OutputFormats.Get "source" }}
{{- $show := and $format (not (.Param "disableSourceButton")) }}
{{- if $show }}
{{- $show = and (not (partial "_relearn/pageIsSpecial.gotmpl" .)) .File .File.Filename }}
{{- end }}
{{- if $show }}
{{- partial "topbar/func/button.html" (dict
"page" .
"class" "topbar-button-source"
"href" $format.RelPermalink
"icon" "file-code"
"onwidths" $onwidths
"onwidthm" $onwidthm
"onwidthl" $onwidthl
"hint" (T "Show-source")
)}}
{{- end }}
{{- end }}

View file

@ -1 +1 @@
7.3.2+7b470298046df2c96c0da9da07a54572b7c4e1b0
7.3.2+c6cec2de3e4f3649e19d152e7a1231a66d68c474