Skip to content

Commit 1c6b596

Browse files
committed
SelfService: Add page source edit and issue links
1 parent 3257d40 commit 1c6b596

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

exampleSite/hugo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
baseURL = 'https://nginx.org'
22
languageCode = 'en-us'
33
title = 'Example Site'
4+
enableGitInfo = true
45

56

67
[module]
@@ -18,4 +19,8 @@ maxAge = -1
1819
unsafe = true
1920
[markup.highlight]
2021
guessSyntax = true
21-
noClasses = false
22+
noClasses = false
23+
24+
[params]
25+
github_repo = "https://github.com/nginxinc/nginx-hugo-theme"
26+
github_subdir = "exampleSite"

layouts/_default/docs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ <h1>{{ .Title }}</h1>
3939

4040
{{ if .Page.Lastmod }}
4141
<div class="last-modified">
42-
Last modified {{ .Page.Lastmod.Format "January 2, 2006" }}
42+
{{ partial "page-meta-links" . }}
4343
</div>
4444
{{ end }}
4545

layouts/_default/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h2>
4141
<hr>
4242
{{ if .Page.Lastmod }}
4343
<div class="last-modified">
44-
Last modified {{ .Page.Lastmod.Format "January 2, 2006" }}
44+
{{ partial "page-meta-links" . }}
4545
</div>
4646
{{ end }}
4747

layouts/partials/page-meta-links.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{{/* cSpell:ignore querify subdir */ -}}
2+
{{/* Class names ending with `--KIND` are deprecated in favor of `__KIND`, but we're keeping them for a few releases after 0.9.0 */ -}}
3+
{{/* Based on https://github.com/google/docsy/blob/main/layouts/partials/page-meta-links.html */}}
4+
{{ if .File -}}
5+
{{ $path := strings.TrimPrefix (add hugo.WorkingDir "/") $.File.Filename -}}
6+
{{ $gh_repo := $.Param "github_repo" -}}
7+
{{ $gh_url := $.Param "github_url" -}}
8+
{{ $gh_subdir := $.Param "github_subdir" | default "" -}}
9+
{{ $gh_branch := $.Param "github_branch" | default "main" -}}
10+
{{ if $gh_url -}}
11+
{{ warnf "Warning: use of `github_url` is deprecated. For details, see https://www.docsy.dev/docs/adding-content/repository-links/#github_url-optional" -}}
12+
<a href="{{ $gh_url }}" target="_blank"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_edit_this" }}</a>
13+
{{ else if $gh_repo -}}
14+
15+
{{/* Adjust $path based on path_base_for_github_subdir */ -}}
16+
{{ $ghs_base := $.Param "path_base_for_github_subdir" -}}
17+
{{ $ghs_rename := "" -}}
18+
{{ if reflect.IsMap $ghs_base -}}
19+
{{ $ghs_rename = $ghs_base.to -}}
20+
{{ $ghs_base = $ghs_base.from -}}
21+
{{ end -}}
22+
{{ with $ghs_base -}}
23+
{{ $path = replaceRE . $ghs_rename $path -}}
24+
{{ end -}}
25+
26+
{{ $gh_repo_path := printf "%s/%s/%s" $gh_branch $gh_subdir $path -}}
27+
{{ $gh_repo_path = replaceRE "//+" "/" $gh_repo_path -}}
28+
29+
{{ $viewURL := printf "%s/tree/%s" $gh_repo $gh_repo_path -}}
30+
{{ $editURL := printf "%s/edit/%s" $gh_repo $gh_repo_path -}}
31+
{{ $issuesURL := printf "%s/issues/new?title=%s&template=2-bug_report.md" $gh_repo (safeURL $.Title ) -}}
32+
<div> Last modified {{ .Page.Lastmod.Format "January 2, 2006" }} </div>
33+
<div>
34+
<a href="{{ $viewURL }}" class="" target="_blank" rel="noopener"><i class="fa-solid fa-file-lines fa-fw"></i> View source</a>
35+
</div>
36+
<div>
37+
<a href="{{ $editURL }}" class="" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> Edit this page</a>
38+
</div>
39+
<div>
40+
<a href="{{ $issuesURL }}" class="" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> Create a new issue</a>
41+
</div>
42+
43+
{{ end -}}
44+
{{ with .CurrentSection.AlternativeOutputFormats.Get "print" -}}
45+
<a id="print" href="{{ .RelPermalink | safeURL }}"><i class="fa-solid fa-print fa-fw"></i> {{ T "print_entire_section" }}</a>
46+
{{ end }}
47+
{{ end -}}

0 commit comments

Comments
 (0)