From fbec3905ed0a2578c4a8763c90d9fe58909004fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Tue, 31 Dec 2024 14:32:43 +0100 Subject: [PATCH] markdown: support new output format #979 --- exampleSite/config/_default/params.toml | 6 +++++ .../frontmatter/reference/frontmatter.toml | 6 +++++ .../authoring/frontmatter/topbar/_index.en.md | 15 ++++++++++--- .../frontmatter/topbar/_index.pir.md | 4 ++-- .../customization/topbar/_index.en.md | 1 + .../sitemanagement/outputformats/_index.en.md | 17 +++++++++++++- .../introduction/releasenotes/7/3.en.md | 2 ++ layouts/_default/baseof.md | 4 ++++ layouts/_default/list.md | 1 + layouts/_default/single.md | 1 + layouts/partials/topbar/area/end.html | 3 +++ layouts/partials/topbar/button/markdown.html | 22 +++++++++++++++++++ layouts/partials/version.txt | 2 +- 13 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 layouts/_default/baseof.md create mode 100644 layouts/_default/list.md create mode 100644 layouts/_default/single.md create mode 100644 layouts/partials/topbar/button/markdown.html diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index 72f406018c..40080ccbc9 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -135,6 +135,12 @@ disableToc = false # shown in the topbar. disableBreadcrumb = false +# Hide the Markdown button. +# Default: false +# This hides the Markdown button if you activated the Markdown output format. +# This can be overridden in the page's frontmatter. +disableMarkdownButton = false + # Hide the print button. # Default: false # This hides the print button if you activated the print output format. diff --git a/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml b/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml index ed056b78ec..2b5c2ed11a 100644 --- a/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml +++ b/exampleSite/content/authoring/frontmatter/reference/frontmatter.toml @@ -52,6 +52,12 @@ disableToc = false # shown in the topbar. disableBreadcrumb = false +# Hide the Markdown button. +# Default: false +# This hides the Markdown button if you activated the Markdown output format. +# If not set, the set value of your site's hugo.toml is used. +disableMarkdownButton = false + # Hide the print button. # Default: false # This hides the print button if you activated the print output format. diff --git a/exampleSite/content/authoring/frontmatter/topbar/_index.en.md b/exampleSite/content/authoring/frontmatter/topbar/_index.en.md index 2cee6ead55..7e0a7cfa33 100644 --- a/exampleSite/content/authoring/frontmatter/topbar/_index.en.md +++ b/exampleSite/content/authoring/frontmatter/topbar/_index.en.md @@ -1,8 +1,8 @@ +++ categories = ["howto"] description = "Configure the topbar" -frontmatter = ["disableBreadcrumb", "disableNextPrev", "disablePrintButton", "disableToc", "editURL"] -options = ["disableBreadcrumb", "disableNextPrev", "disablePrintButton", "disableToc", "editURL"] +frontmatter = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"] +options = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"] title = "Topbar" weight = 4 +++ @@ -15,7 +15,8 @@ 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="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="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 - {{% button style="transparent" icon="chevron-right" %}}{{% /button %}} **next**: browses to the [next page](#arrow-navigation) if there is one - {{% button style="transparent" icon="ellipsis-v" %}}{{% /button %}} **more**: opens the overlay if screen space is limited @@ -48,6 +49,14 @@ The value can contain the macro `${FilePath}` which will be replaced by the file editURL = 'https://github.com/McShelby/hugo-theme-relearn/edit/main/exampleSite/content/${FilePath}' {{< /multiconfig >}} +## Markdown 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 Markdown button if the [Markdown output format](configuration/sitemanagement/outputformats/#markdown-support) is active by setting `disableMarkdownButton=true`. + +{{< multiconfig >}} +disableMarkdownButton = 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`. diff --git a/exampleSite/content/authoring/frontmatter/topbar/_index.pir.md b/exampleSite/content/authoring/frontmatter/topbar/_index.pir.md index 4fc06c5747..ef5da03e54 100644 --- a/exampleSite/content/authoring/frontmatter/topbar/_index.pir.md +++ b/exampleSite/content/authoring/frontmatter/topbar/_index.pir.md @@ -1,8 +1,8 @@ +++ categories = ["howto"] description = "Configure the topbar" -frontmatter = ["disableBreadcrumb", "disableNextPrev", "disablePrintButton", "disableToc", "editURL"] -options = ["disableBreadcrumb", "disableNextPrev", "disablePrintButton", "disableToc", "editURL"] +frontmatter = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"] +options = ["disableBreadcrumb", "disableNextPrev", "disableMarkdownButton", "disablePrintButton", "disableToc", "editURL"] title = "Topbarrr" weight = 4 +++ diff --git a/exampleSite/content/configuration/customization/topbar/_index.en.md b/exampleSite/content/configuration/customization/topbar/_index.en.md index c5c89bdf30..cf726de629 100644 --- a/exampleSite/content/configuration/customization/topbar/_index.en.md +++ b/exampleSite/content/configuration/customization/topbar/_index.en.md @@ -35,6 +35,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="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 - {{% button style="transparent" icon="chevron-right" %}}{{% /button %}} [**next**](https://github.com/McShelby/hugo-theme-relearn/blob/main/layouts/partials/topbar/button/next.html): browses to the [next page]authoring/frontmatter/topbar(#arrow-navigation) if there is one diff --git a/exampleSite/content/configuration/sitemanagement/outputformats/_index.en.md b/exampleSite/content/configuration/sitemanagement/outputformats/_index.en.md index d3f7e0f846..caf89646a8 100644 --- a/exampleSite/content/configuration/sitemanagement/outputformats/_index.en.md +++ b/exampleSite/content/configuration/sitemanagement/outputformats/_index.en.md @@ -16,7 +16,7 @@ Enable print support to print entire chapters or the whole site. Add the `print` page = ['html', 'rss', 'print'] {{< /multiconfig >}} -By default this adds a printer icon in the topbar by can be [deactived](authoring/frontmatter/topbar/#print-button). Clicking it switches to print preview, showing the page and its [visible subpages](configuration/content/hidden) in a printer-friendly format. Use your browser's print function to print or save as PDF. +By default this adds a printer icon in the topbar but [can be deactived](authoring/frontmatter/topbar/#print-button). Clicking it switches to print preview, showing the page and its [visible subpages](configuration/content/hidden) in a printer-friendly format. Use your browser's print function to print or save as PDF. 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. @@ -32,3 +32,18 @@ If you don't like the URLs, you can reconfigure `outputFormats.print` in your `h permalinkable = false noUgly = true {{< /multiconfig >}} + +## 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`: + +{{< multiconfig file=hugo >}} +[outputs] + home = ['html', 'rss', 'markdown'] + section = ['html', 'rss', 'markdown'] + 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. + +The `markdown` output format configuration is [provided by Hugo](https://gohugo.io/templates/output-formats/#output-format-definitions). diff --git a/exampleSite/content/introduction/releasenotes/7/3.en.md b/exampleSite/content/introduction/releasenotes/7/3.en.md index 1fe8178ddb..9197df19a9 100644 --- a/exampleSite/content/introduction/releasenotes/7/3.en.md +++ b/exampleSite/content/introduction/releasenotes/7/3.en.md @@ -13,3 +13,5 @@ weight = -3 - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Support for Hugo’s built-in [`details` shortcode](https://gohugo.io/content-management/shortcodes/#details) by mapping it to the theme's [`expand` shortcode](shortcodes/expand). - {{% 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. diff --git a/layouts/_default/baseof.md b/layouts/_default/baseof.md new file mode 100644 index 0000000000..33cee1f948 --- /dev/null +++ b/layouts/_default/baseof.md @@ -0,0 +1,4 @@ +{{/* the following check avoids to print out content of headless bundles if called from nestedContent.gotmpl */}} +{{- if .RelPermalink }} +{{- .RawContent }} +{{- end }} diff --git a/layouts/_default/list.md b/layouts/_default/list.md new file mode 100644 index 0000000000..8712006618 --- /dev/null +++ b/layouts/_default/list.md @@ -0,0 +1 @@ +{{ define "_empty" }}{{ end }} \ No newline at end of file diff --git a/layouts/_default/single.md b/layouts/_default/single.md new file mode 100644 index 0000000000..8712006618 --- /dev/null +++ b/layouts/_default/single.md @@ -0,0 +1 @@ +{{ define "_empty" }}{{ end }} \ No newline at end of file diff --git a/layouts/partials/topbar/area/end.html b/layouts/partials/topbar/area/end.html index 6d79cc35b4..2c88ae1b41 100644 --- a/layouts/partials/topbar/area/end.html +++ b/layouts/partials/topbar/area/end.html @@ -1,6 +1,9 @@ {{- partial "topbar/button/edit.html" (dict "page" . )}} +{{- partial "topbar/button/markdown.html" (dict + "page" . +)}} {{- partial "topbar/button/print.html" (dict "page" . )}} diff --git a/layouts/partials/topbar/button/markdown.html b/layouts/partials/topbar/button/markdown.html new file mode 100644 index 0000000000..b583262919 --- /dev/null +++ b/layouts/partials/topbar/button/markdown.html @@ -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 "markdown" }} + {{- $show := and $format (not (.Param "disableMarkdownButton")) }} + {{- if $show }} + {{- $show = not (partial "_relearn/pageIsSpecial.gotmpl" .) }} + {{- end }} + {{- if $show }} + {{- partial "topbar/func/button.html" (dict + "page" . + "class" "topbar-button-markdown" + "href" $format.RelPermalink + "icon" "fa-fw fab fa-markdown" + "onwidths" $onwidths + "onwidthm" $onwidthm + "onwidthl" $onwidthl + "hint" (T "Show-Markdown") + )}} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/layouts/partials/version.txt b/layouts/partials/version.txt index 53b47a6da9..cef9a23a1d 100644 --- a/layouts/partials/version.txt +++ b/layouts/partials/version.txt @@ -1 +1 @@ -7.2.1+2cd8baa02f811124d580c519d95b3f977a1972f6 \ No newline at end of file +7.2.1+780744552727654e03983918f0ad49ccae2a696b \ No newline at end of file