Skip to content

SelfService: Add page source edit and issue links #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion exampleSite/hugo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
baseURL = 'https://nginx.org'
languageCode = 'en-us'
title = 'Example Site'
enableGitInfo = true


[module]
Expand All @@ -18,4 +19,8 @@ maxAge = -1
unsafe = true
[markup.highlight]
guessSyntax = true
noClasses = false
noClasses = false

[params]
github_repo = "https://github.com/nginxinc/nginx-hugo-theme"
github_subdir = "exampleSite"
2 changes: 1 addition & 1 deletion layouts/_default/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1>{{ .Title }}</h1>

{{ if .Page.Lastmod }}
<div class="last-modified">
Last modified {{ .Page.Lastmod.Format "January 2, 2006" }}
{{ partial "page-meta-links" . }}
</div>
{{ end }}

Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2>
<hr>
{{ if .Page.Lastmod }}
<div class="last-modified">
Last modified {{ .Page.Lastmod.Format "January 2, 2006" }}
{{ partial "page-meta-links" . }}
</div>
{{ end }}

Expand Down
47 changes: 47 additions & 0 deletions layouts/partials/page-meta-links.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{/* cSpell:ignore querify subdir */ -}}
{{/* Class names ending with `--KIND` are deprecated in favor of `__KIND`, but we're keeping them for a few releases after 0.9.0 */ -}}
{{/* Based on https://github.com/google/docsy/blob/main/layouts/partials/page-meta-links.html */}}
{{ if .File -}}
{{ $path := strings.TrimPrefix (add hugo.WorkingDir "/") $.File.Filename -}}
{{ $gh_repo := $.Param "github_repo" -}}
{{ $gh_url := $.Param "github_url" -}}
{{ $gh_subdir := $.Param "github_subdir" | default "" -}}
{{ $gh_branch := $.Param "github_branch" | default "main" -}}
{{ if $gh_url -}}
{{ warnf "Warning: use of `github_url` is deprecated. For details, see https://www.docsy.dev/docs/adding-content/repository-links/#github_url-optional" -}}
<a href="{{ $gh_url }}" target="_blank"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_edit_this" }}</a>
{{ else if $gh_repo -}}

{{/* Adjust $path based on path_base_for_github_subdir */ -}}
{{ $ghs_base := $.Param "path_base_for_github_subdir" -}}
{{ $ghs_rename := "" -}}
{{ if reflect.IsMap $ghs_base -}}
{{ $ghs_rename = $ghs_base.to -}}
{{ $ghs_base = $ghs_base.from -}}
{{ end -}}
{{ with $ghs_base -}}
{{ $path = replaceRE . $ghs_rename $path -}}
{{ end -}}

{{ $gh_repo_path := printf "%s/%s/%s" $gh_branch $gh_subdir $path -}}
{{ $gh_repo_path = replaceRE "//+" "/" $gh_repo_path -}}

{{ $viewURL := printf "%s/tree/%s" $gh_repo $gh_repo_path -}}
{{ $editURL := printf "%s/edit/%s" $gh_repo $gh_repo_path -}}
{{ $issuesURL := printf "%s/issues/new?title=%s&template=2-bug_report.md" $gh_repo (safeURL $.Title ) -}}
<div> Last modified {{ .Page.Lastmod.Format "January 2, 2006" }} </div>
<div>
<a href="{{ $viewURL }}" class="" target="_blank" rel="noopener"><i class="fa-solid fa-file-lines fa-fw"></i> View source</a>
</div>
<div>
<a href="{{ $editURL }}" class="" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> Edit this page</a>
</div>
<div>
<a href="{{ $issuesURL }}" class="" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> Create a new issue</a>
</div>

{{ end -}}
{{ with .CurrentSection.AlternativeOutputFormats.Get "print" -}}
<a id="print" href="{{ .RelPermalink | safeURL }}"><i class="fa-solid fa-print fa-fw"></i> {{ T "print_entire_section" }}</a>
{{ end }}
{{ end -}}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading