mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
topbar: support editURL in frontmatter #764
This commit is contained in:
parent
7954509934
commit
eaabbfd6ef
4 changed files with 47 additions and 17 deletions
|
@ -157,11 +157,13 @@ disableNextPrev = false
|
|||
# The URL prefix to edit a page.
|
||||
# Default: not set
|
||||
# If set, an edit button will be shown in the topbar. If the button is hidden,
|
||||
# also the keyboard shortcuts are disabled. The given URL is prepended to the
|
||||
# relative file path of a the displayed page. The URL must end with a `/`.
|
||||
# This is useful if you wnat to give the opportunity for people to create merge
|
||||
# request for your content.
|
||||
editURL = "https://github.com/McShelby/hugo-theme-relearn/edit/main/exampleSite/content/"
|
||||
# also the keyboard shortcuts are disabled. The value can contain the macro
|
||||
# `${FilePath}` which will be replaced by the file path of your displayed page.
|
||||
# If no `${FilePath}` is given in the value, the value is treated as if the
|
||||
# `${FilePath}` was appended at the end of the value. This can be overridden
|
||||
# in the pages frontmatter. This is useful if you want to give the opportunity
|
||||
# for people to create merge request for your content.
|
||||
editURL = "https://github.com/McShelby/hugo-theme-relearn/edit/main/exampleSite/content/${FilePath}"
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
# Menu
|
||||
|
|
|
@ -40,6 +40,8 @@ This document shows you what's new in the latest release and flags it with one o
|
|||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Improvements for accessibility when tabbing thru the page for images, links and tab handles.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The `editURL` config parameter is now [overwritable in your pages frontmatter](cont/frontmatter). In addition it received more versatility by letting you control where to put the file path into the URL. This is achieved by replacing the variable `${FilePath}` in your URL by the pages file path. You don't need to change anything in your existing configuration as the old way without the replacement variable still works.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The themes [config](basics/configuration) and [frontmatter](cont/frontmatter) options received a comprehensive documentation update. In addition the theme switched from `config.toml` to `hugo.toml`.
|
||||
|
||||
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} Restored compatibility with Hugo versions {{% badge color="fuchsia" icon="fab fa-hackerrank" title=" " %}}0.121.0{{% /badge %}} or higher for the [`highlight` shortcode](shortcodes/highlight). This does not change the minimum required Hugo version.
|
||||
|
|
|
@ -61,6 +61,19 @@ disableBreadcrumb = false
|
|||
# disabled.
|
||||
disableNextPrev = false
|
||||
|
||||
# The URL prefix to edit a page.
|
||||
# Default: not set
|
||||
# If set, an edit button will be shown in the topbar. If the button is hidden,
|
||||
# also the keyboard shortcuts are disabled. The value can contain the macro
|
||||
# `${FilePath}` which will be replaced by the file path of your displayed page.
|
||||
# If not set, the set value of your site's hugo.toml is used. If the global
|
||||
# parameter is given but you want to hide the button for the displayed page,
|
||||
# you can set the value to an empty string. If instead of hiding you want to have
|
||||
# an disabled button, you can set the value to a string containing just spaces.
|
||||
# This is useful if you want to give the opportunity for people to create merge
|
||||
# request for your content.
|
||||
editURL = ""
|
||||
|
||||
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
# Menu
|
||||
# These options modify the menu apperance.
|
||||
|
|
|
@ -4,17 +4,30 @@
|
|||
{{- with .page }}
|
||||
{{- $format := partial "get-format.hugo" . }}
|
||||
{{- $outputFormat := partial "output-format.hugo" (dict "page" . "format" $format) }}
|
||||
{{- if and (eq $outputFormat "html") (or .Site.Params.editURL .Params.editURL) .File }}
|
||||
{{- $href := or .Params.editURL (printf "%s%s%s" .Site.Params.editURL (strings.TrimLeft "/" (replace .File.Dir "\\" "/")) .File.LogicalName) }}
|
||||
{{- partial "topbar/func/button.html" (dict
|
||||
"page" .
|
||||
"class" "topbar-button-edit"
|
||||
"href" $href
|
||||
"icon" "pen"
|
||||
"onwidths" $onwidths
|
||||
"onwidthm" $onwidthm
|
||||
"onwidthl" $onwidthl
|
||||
"hint" (printf "%s (CTRL+ALT+w)" (T "Edit-this-page"))
|
||||
)}}
|
||||
{{- if and (eq $outputFormat "html") .File }}
|
||||
{{- $filePath := printf "%s%s" (strings.TrimLeft "/" (replace .File.Dir "\\" "/")) .File.LogicalName }}
|
||||
{{- $href := "" }}
|
||||
{{- if .Site.Params.editURL }}
|
||||
{{- $href = .Site.Params.editURL }}
|
||||
{{- if not (strings.Contains $href "${FilePath}") }}
|
||||
{{ $href = printf "%s%s" $href "${FilePath}" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if isset .Params "editurl" }}
|
||||
{{- $href = .Params.editURL }}
|
||||
{{- end }}
|
||||
{{- $href = strings.Replace $href "${FilePath}" $filePath }}
|
||||
{{- if $href }}
|
||||
{{- partial "topbar/func/button.html" (dict
|
||||
"page" .
|
||||
"class" "topbar-button-edit"
|
||||
"href" $href
|
||||
"icon" "pen"
|
||||
"onwidths" $onwidths
|
||||
"onwidthm" $onwidthm
|
||||
"onwidthl" $onwidthl
|
||||
"hint" (printf "%s (CTRL+ALT+w)" (T "Edit-this-page"))
|
||||
)}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
Loading…
Reference in a new issue