Skip to content
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

Repo links improvements #1941

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 15 additions & 1 deletion layouts/partials/page-meta-lastmod.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{ if and .GitInfo .Site.Params.github_repo -}}
{{ if and .GitInfo .Site.Params.github_repo -}}
{{ warnf "Warning: use of `github_repo` is deprecated, use `repo.url` instead " -}}
<div class="td-page-meta__lastmod">
{{ T "post_last_mod" }} {{ .Lastmod.Format .Site.Params.time_format_default -}}
{{ with .GitInfo }}: {{/* Trim WS */ -}}
Expand All @@ -8,3 +9,16 @@
{{- end }}
</div>
{{ end -}}

{{/* Looks like all repo types have the same frmat for the commit link */}}
{{ if and .GitInfo .Site.Params.repo.type -}}
<div class="td-page-meta__lastmod">
{{ T "post_last_mod" }} {{ .Lastmod.Format .Site.Params.time_format_default -}}
{{ with .GitInfo }}: {{/* Trim WS */ -}}
<a href="{{ $.Site.Params.repo.url }}/commit/{{ .Hash }}">
{{- .Subject }} ({{ .AbbreviatedHash }}) {{- /* Trim WS */ -}}
</a>
{{- end }}
</div>
{{ end -}}

62 changes: 24 additions & 38 deletions layouts/partials/page-meta-links.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,34 @@
{{/* Class names ending with `--KIND` are deprecated in favor of `__KIND`, but we're keeping them for a few releases after 0.9.0 */ -}}

{{ 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_project_repo := $.Param "github_project_repo" -}}
{{ $gh_branch := $.Param "github_branch" | default "main" -}}
<div class="td-page-meta ms-2 pb-1 pt-2 mb-0">
{{ 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 -}}
{{ $file_path := strings.TrimPrefix hugo.WorkingDir $.File.Filename -}}
{{ $file_path := strings.TrimPrefix "/" $file_path -}}

{{/* 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 -}}
{{ $git_repo := $.Param "repo.url" -}}
{{ $git_branch := $.Param "repo.branch" | default "main" -}}
{{ $git_subdir := $.Param "repo.subdir" | default "" -}}
{{ $git_project_repo := $.Param "repo.project_repo" -}}
<div class="td-page-meta ms-2 pb-1 pt-2 mb-0">
{{ partial "repo-links-github-deprecated.html" . -}}
{{- /* Adjust $file_path based on path_base_for_subdir */ -}}
{{ $git_path_replace_from := $.Param "repo.path_base_for_subdir" -}}
{{ $git_path_replace_to := "" -}}
{{ if reflect.IsMap $git_path_replace_from -}}
{{ $git_path_replace_to = $git_path_replace_from.to -}}
{{ $git_path_replace_from = $git_path_replace_from.from -}}
{{ 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" $gh_repo (safeURL $.Title ) -}}
{{ $newPageStub := resources.Get "stubs/new-page-template.md" -}}
{{ $newPageQS := querify "value" $newPageStub.Content "filename" "change-me.md" | safeURL -}}
{{ $newPageURL := printf "%s/new/%s?%s" $gh_repo (path.Dir $gh_repo_path) $newPageQS -}}

<a href="{{ $viewURL }}" class="td-page-meta--view td-page-meta__view" target="_blank" rel="noopener"><i class="fa-solid fa-file-lines fa-fw"></i> {{ T "post_view_this" }}</a>
<a href="{{ $editURL }}" class="td-page-meta--edit td-page-meta__edit" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_edit_this" }}</a>
<a href="{{ $newPageURL }}" class="td-page-meta--child td-page-meta__child" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_create_child_page" }}</a>
<a href="{{ $issuesURL }}" class="td-page-meta--issue td-page-meta__issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_issue" }}</a>
{{ with $gh_project_repo -}}
{{ $project_issueURL := printf "%s/issues/new" . -}}
<a href="{{ $project_issueURL }}" class="td-page-meta--project td-page-meta__project-issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_project_issue" }}</a>
{{ $git_path := $file_path }}
{{ with $git_path_replace_from -}}
{{ $git_path = replaceRE . $git_path_replace_to $file_path -}}
{{ end -}}
{{ $git_repo_path := path.Join $git_subdir $file_path -}}

{{ $repo := (dict "repo_branch" $git_branch
"repo_path" $git_repo_path
"repo" ($.Param "repo")
"context" .) -}}
{{ with $.Param "repo.type" -}}
{{ partial ( printf "repo-links-%s.html" . ) $repo -}}
{{ 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>
Expand Down
12 changes: 12 additions & 0 deletions layouts/partials/repo-links-azure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ $baseUrl := replaceRE "/_git/.+$" "" .repo.url }}
{{ $viewURL := printf "%s?path=%s&version=GB%s&_a=contents" .repo.url .repo_path .repo_branch -}}
{{ $issuesURL := printf "%s/_workitems/create/Bug?[title]=%s" $baseUrl (safeURL $.context.Title ) -}}
{{ if .repo.azure.issue_area -}}
{{ $issuesURL = printf "%s/_workitems/create/Bug?[title]=%s&[Area Path]=%s" $baseUrl (safeURL $.context.Title) (safeURL .repo.azure.issue_area) -}}
{{ end -}}
<a href="{{ $viewURL }}" class="td-page-meta--edit td-page-meta__edit" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_view_this" }}</a>
<a href="{{ $issuesURL }}" class="td-page-meta--issue td-page-meta__issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_issue" }}</a>
{{ with .repo.project_url -}}
{{ $project_issueURL := printf "%s/_workitems/create/Bug" (replaceRE "/_git.+$" "" .) -}}
<a href="{{ $project_issueURL }}" class="td-page-meta--project-issue td-page-meta__project-issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_project_issue" }}</a>
{{ end -}}
20 changes: 20 additions & 0 deletions layouts/partials/repo-links-gitea.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{/* 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 */ -}}

{{ $viewURL := path.Join .repo.url "/src/branch/" .repo_branch .repo_path -}}
{{ $editURL := path.Join .repo.url "_edit/" .repo_branch .repo_path -}}
{{ $issuesQS := printf "title=%s" (safeURL $.context.Title )}}
{{ $issuesURL := path.Join .repo.url "/issues/new" -}}
{{ $issuesURL = printf "%s?%s" $issuesURL $issuesQS -}}
{{ $newPageStub := resources.Get "stubs/new-page-template.md" -}}
{{ $newPageQS := querify "value" $newPageStub.Content "filename" "change-me.md" | safeURL -}}
{{ $newPageURL := path.Join .repo.url "/_new/" .repo_branch (path.Dir .repo_path) -}}
{{ $newPageURL = printf "%s?%s" $newPageURL $newPageQS -}}
<a href="{{ $viewURL }}" class="td-page-meta--view td-page-meta__view" target="_blank" rel="noopener"><i class="fa-solid fa-file-lines fa-fw"></i> {{ T "post_view_this" }}</a>
<a href="{{ $editURL }}" class="td-page-meta--edit td-page-meta__edit" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_edit_this" }}</a>
<a href="{{ $newPageURL }}" class="td-page-meta--child td-page-meta__child" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_create_child_page" }}</a>
<a href="{{ $issuesURL }}" class="td-page-meta--issue td-page-meta__issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_issue" }}</a>
{{ with .repo.project_url -}}
{{ $project_issueURL := printf "%s/issues/new" . -}}
<a href="{{ $project_issueURL }}" class="td-page-meta--project td-page-meta__project-issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_project_issue" }}</a>
{{ end -}}
62 changes: 62 additions & 0 deletions layouts/partials/repo-links-github-deprecated.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/* 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 */ -}}

{{ $path := strings.TrimPrefix hugo.WorkingDir $.File.Filename -}}
{{ $path := strings.TrimPrefix "/" $path -}}

{{ $gh_repo := $.Param "github_repo" -}}
{{ $gh_url := $.Param "github_url" -}}
{{ $gh_subdir := $.Param "github_subdir" | default "" -}}
{{ $gh_project_repo := $.Param "github_project_repo" -}}
{{ $gh_branch := $.Param "github_branch" | default "main" -}}

{{ with $.Param "github_repo" -}}
{{ warnf "Warning: use of `github_repo` is deprecated, use `repo.url` instead " -}}
{{ end -}}
{{ with $.Param "github_subdir" -}}
{{ warnf "Warning: use of `github_subdir` is deprecated, use `repo.subdir` instead " -}}
{{ end -}}
{{ with $.Param "github_branch" -}}
{{ warnf "Warning: use of `github_branch` is deprecated, use `repo.branch` instead " -}}
{{ end -}}
{{ with $.Param "github_project_repo" -}}
{{ warnf "Warning: use of `github_project_repo` is deprecated, use `repo.project_repo` instead " -}}
{{ end -}}

{{ 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 -}}
{{ warnf "Warning: use of `path_base_for_github_subdir` is deprecated, use `repo.path_base_for_subdir` instead " -}}
{{ $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" $gh_repo (safeURL $.Title ) -}}
{{ $newPageStub := resources.Get "stubs/new-page-template.md" -}}
{{ $newPageQS := querify "value" $newPageStub.Content "filename" "change-me.md" | safeURL -}}
{{ $newPageURL := printf "%s/new/%s?%s" $gh_repo (path.Dir $gh_repo_path) $newPageQS -}}

<a href="{{ $viewURL }}" class="td-page-meta--view td-page-meta__view" target="_blank" rel="noopener"><i class="fa-solid fa-file-lines fa-fw"></i> {{ T "post_view_this" }}</a>
<a href="{{ $editURL }}" class="td-page-meta--edit td-page-meta__edit" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_edit_this" }}</a>
<a href="{{ $newPageURL }}" class="td-page-meta--child td-page-meta__child" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_create_child_page" }}</a>
<a href="{{ $issuesURL }}" class="td-page-meta--issue td-page-meta__issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_issue" }}</a>
{{ with $gh_project_repo -}}
{{ $project_issueURL := printf "%s/issues/new" . -}}
<a href="{{ $project_issueURL }}" class="td-page-meta--project td-page-meta__project-issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_project_issue" }}</a>
{{ end -}}

{{ end -}}
20 changes: 20 additions & 0 deletions layouts/partials/repo-links-github.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{/* 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 */ -}}

{{ $viewURL := path.Join .repo.url "/tree" .repo_branch .repo_path -}}
{{ $editURL := path.Join .repo.url "/edit" .repo_branch .repo_path -}}
{{ $issuesQS := printf "title=%s" (safeURL $.context.Title) -}}
{{ $issuesURL := path.Join .repo.url "/issues/new" -}}
{{ $issuesURL = printf "%s?%s" $issuesURL $issuesQS -}}
{{ $newPageStub := resources.Get "stubs/new-page-template.md" -}}
{{ $newPageQS := querify "value" $newPageStub.Content "filename" "change-me.md" | safeURL -}}
{{ $newPageURL := path.Join .repo.url "/new" .repo_branch (path.Dir .repo_path) -}}
{{ $newPageURL = printf "%s?%s" $newPageURL $newPageQS -}}
<a href="{{ $viewURL }}" class="td-page-meta--view td-page-meta__view" target="_blank" rel="noopener"><i class="fa-solid fa-file-lines fa-fw"></i> {{ T "post_view_this" }}</a>
<a href="{{ $editURL }}" class="td-page-meta--edit td-page-meta__edit" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_edit_this" }}</a>
<a href="{{ $newPageURL }}" class="td-page-meta--child td-page-meta__child" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_create_child_page" }}</a>
<a href="{{ $issuesURL }}" class="td-page-meta--issue td-page-meta__issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_issue" }}</a>
{{ with .repo.project_url -}}
{{ $project_issueURL := printf "%s/issues/new" . -}}
<a href="{{ $project_issueURL }}" class="td-page-meta--project td-page-meta__project-issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_project_issue" }}</a>
{{ end -}}
20 changes: 20 additions & 0 deletions layouts/partials/repo-links-gitlab.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{/* 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 */ -}}

{{ $viewURL := path.Join .repo.url "/tree" .repo_branch .repo_path -}}
{{ $editURL := path.Join .repo.url "/edit" .repo_branch .repo_path -}}
{{ $issuesQS := printf "issue[title]=%s" (safeURL $.context.Title) -}}
{{ $issuesURL := path.Join .repo.url "/issues/new" -}}
{{ $issuesURL = printf "%s?%" $issuesURL $issuesQS -}}
{{ $newPageStub := resources.Get "stubs/new-page-template.md" -}}
{{ $newPageQS := querify "value" $newPageStub.Content "filename" "change-me.md" | safeURL -}}
{{ $newPageURL := path.Join .repo.url "/new" .repo_branch (path.Dir .repo_path) -}}
{{ $newPageURL = printf "%s?%s" $newPageURL $newPageQS -}}
<a href="{{ $viewURL }}" class="td-page-meta--view td-page-meta__view" target="_blank" rel="noopener"><i class="fa-solid fa-file-lines fa-fw"></i> {{ T "post_view_this" }}</a>
<a href="{{ $editURL }}" class="td-page-meta--edit td-page-meta__edit" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_edit_this" }}</a>
<a href="{{ $newPageURL }}" class="td-page-meta--child td-page-meta__child" target="_blank" rel="noopener"><i class="fa-solid fa-pen-to-square fa-fw"></i> {{ T "post_create_child_page" }}</a>
<a href="{{ $issuesURL }}" class="td-page-meta--issue td-page-meta__issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_issue" }}</a>
{{ with .repo.project_url -}}
{{ $project_issueURL := printf "%s/issues/new" . -}}
<a href="{{ $project_issueURL }}" class="td-page-meta--project td-page-meta__project-issue" target="_blank" rel="noopener"><i class="fa-solid fa-list-check fa-fw"></i> {{ T "post_create_project_issue" }}</a>
{{ end -}}
Loading