Skip to content

Commit

Permalink
feat: add configurable edit link position
Browse files Browse the repository at this point in the history
- Add a `where` parameter to `editURL`
- Allow user to choose between `toc` (default) and `single`
- Add to single through last-updated partial
  • Loading branch information
davlgd committed Apr 1, 2024
1 parent 0d6cbba commit 795755b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions exampleSite/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ params:

editURL:
enable: true
where: "single" # single | toc
base: "https://github.com/imfing/hextra/edit/main/exampleSite/content"

blog:
Expand Down
21 changes: 20 additions & 1 deletion layouts/partials/components/last-updated.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
{{- $lastUpdated := (T "lastUpdated") | default "Last updated on" -}}
{{- $editThisPage := (T "editThisPage") | default "Edit this page"}}

{{- if site.Params.displayUpdatedDate -}}
<div class="hx-mt-12 hx-mb-8 hx-block hx-text-xs hx-text-gray-500 ltr:hx-text-right rtl:hx-text-left dark:hx-text-gray-400">
{{- if and (site.Params.editURL.enable) (eq site.Params.editURL.where "single") -}}
{{- $editURL := site.Params.editURL.base | default "" -}}
{{- with .Params.editURL -}}
{{/* if `editURL` is set in the front matter */}}
{{- $editURL = . -}}
{{- else -}}
{{- with .File -}}
{{/* `.FileInfo.Meta.SourceRoot` is a Hugo internal field, e.g. `/path/to/repo/content/en/` */}}
{{- $sourceDir := replace (strings.TrimPrefix .FileInfo.Meta.BaseDir .FileInfo.Meta.SourceRoot) "\\" "/" -}}
{{- $sourceDir = strings.TrimPrefix "/content" $sourceDir -}}
{{- $path := replace .Path "\\" "/" -}}
{{- $editURL = urls.JoinPath $editURL $sourceDir $path -}}
{{- end -}}
{{- end -}}
<a class="mb-4 block text-xs text-gray-500 ltr:text-right rtl:text-left dark:text-gray-400" href="{{ $editURL }}" target="_blank" rel="noreferer">{{ $editThisPage }}</a>
{{- end -}}
{{- with .Lastmod -}}
{{ $datetime := (time.Format "2006-01-02T15:04:05.000Z" .) }}
<div class="hx-mt-12 hx-mb-8 hx-block hx-text-xs hx-text-gray-500 ltr:hx-text-right rtl:hx-text-left dark:hx-text-gray-400">{{ $lastUpdated }} <time datetime="{{ $datetime }}">{{ partial "utils/format-date" . }}</time></div>
<div class="hx-mt-4">{{ $lastUpdated }} <time datetime="{{ $datetime }}">{{ partial "utils/format-date" . }}</time></div>
</div>
{{- else -}}
<div class="hx-mt-16"></div>
{{- end -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

{{/* TOC bottom part */}}
<div class="{{ $borderClass }} hx-sticky hx-bottom-0 hx-flex hx-flex-col hx-items-start hx-gap-2 hx-pb-8 dark:hx-border-neutral-800 contrast-more:hx-border-t contrast-more:hx-border-neutral-400 contrast-more:hx-shadow-none contrast-more:dark:hx-border-neutral-400">
{{- if site.Params.editURL.enable -}}
{{- if and (site.Params.editURL.enable) (eq site.Params.editURL.where "toc") -}}
{{- $editURL := site.Params.editURL.base | default "" -}}
{{- with .Params.editURL -}}
{{/* if `editURL` is set in the front matter */}}
Expand Down

0 comments on commit 795755b

Please sign in to comment.