Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
- `where` > `location`
- Edit link > in a partial
  • Loading branch information
davlgd committed Apr 1, 2024
1 parent 3166be3 commit 4e2dc7c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
2 changes: 1 addition & 1 deletion exampleSite/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ params:

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

blog:
Expand Down
21 changes: 21 additions & 0 deletions layouts/partials/components/edit-url.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- $editThisPage := (T "editThisPage") | default "Edit this page"}}
{{- $linkClass := "mb-4 block text-xs text-gray-500 ltr:text-right rtl:text-left dark:text-gray-400" -}}
{{- if and (site.Params.editURL.enable) (eq site.Params.editURL.location .source) -}}
{{- $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 -}}
{{- if eq site.Params.editURL.location "toc" -}}
{{- $linkClass = "text-xs font-medium text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 contrast-more:text-gray-800 contrast-more:dark:text-gray-50" -}}
{{- end -}}
<a class="{{ $linkClass}}" href="{{ $editURL }}" target="_blank" rel="noreferer">{{ $editThisPage }}</a>
{{- end -}}
19 changes: 2 additions & 17 deletions layouts/partials/components/last-updated.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,8 @@
{{- $editThisPage := (T "editThisPage") | default "Edit this page"}}

{{- if site.Params.displayUpdatedDate -}}
<div class="mt-12 mb-8 block text-xs text-gray-500 ltr:text-right rtl:text-left dark: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 -}}
<div class="mt-12 mb-8 block text-xs text-gray-500 ltr:text-right rtl:text-left dark:text-gray-400">
{{ partial "components/edit-url.html" (dict "source" "single") }}
{{- with .Lastmod -}}
{{ $datetime := (time.Format "2006-01-02T15:04:05.000Z" .) }}
{{ $lastUpdated }} <time datetime="{{ $datetime }}">{{ partial "utils/format-date" . }}</time></div>
Expand Down
17 changes: 1 addition & 16 deletions layouts/partials/toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,7 @@

{{/* TOC bottom part */}}
<div class="{{ $borderClass }} sticky bottom-0 flex flex-col items-start gap-2 pb-8 dark:border-neutral-800 contrast-more:border-t contrast-more:border-neutral-400 contrast-more:shadow-none contrast-more:dark:border-neutral-400">
{{- 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 */}}
{{- $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="text-xs font-medium text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 contrast-more:text-gray-800 contrast-more:dark:text-gray-50" href="{{ $editURL }}" target="_blank" rel="noreferer">{{ $editThisPage }}</a>
{{- end -}}
{{ partial "components/edit-url.html" (dict "source" "toc") }}
{{/* Scroll To Top */}}
<button aria-hidden="true" id="backToTop" onClick="scrollUp();" class="transition-all transition duration-75 opacity-0 text-xs font-medium text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 contrast-more:text-gray-800 contrast-more:dark:text-gray-50">
<span>
Expand Down

0 comments on commit 4e2dc7c

Please sign in to comment.