diff --git a/.vscode/cspell.json b/.vscode/cspell.json index d3389d0e02..3e4a324385 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -2,5 +2,5 @@ { "version": "0.2", "caseSensitive": true, - "words": ["Docsy", "shortcode", "shortcodes"] + "words": ["Docsy", "hugo", "shortcode", "shortcodes", "warnf"] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 0196561edf..9e1a15358a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog @@ -25,13 +25,29 @@ For the full list of changes, see the [0.x.y] release notes. **Breaking changes**: -- ... +- [Repository Links] now work for [multi-language] sites ([#1744]). + + For any given page, repository links are now computed from a page's _resolved_ + `File` path, as resolved _through_ mount points, if any. That is, the path + used is the one that refers to the file's actual location on disk, not it's + logical path in Hugo's [union file system]. + + This is a breaking change pages of sites that use mounts and + [path_base_for_github_subdir]. Projects will need to adjust the value of + [path_base_for_github_subdir] to be relative to the file's physical location. **New**: **Other changes**: [0.x.y]: https://github.com/google/docsy/releases/latest?FIXME=v0.X.Y +[#1744]: https://github.com/google/docsy/pull/1744 +[multi-language]: https://www.docsy.dev/docs/language/ +[path_base_for_github_subdir]: + https://www.docsy.dev/docs/adding-content/repository-links/#path_base_for_github_subdir-optional +[Repository Links]: https://www.docsy.dev/docs/adding-content/repository-links/ +[union file system]: + https://gohugo.io/getting-started/directory-structure/#union-file-system ## 0.8.0 diff --git a/layouts/partials/page-meta-links.html b/layouts/partials/page-meta-links.html index 165e5a9f02..f34b6ebbbd 100644 --- a/layouts/partials/page-meta-links.html +++ b/layouts/partials/page-meta-links.html @@ -1,21 +1,18 @@ +{{/* cSpell:ignore querify subdir */ -}} {{ if .File -}} -{{ $pathFormatted := strings.TrimPrefix hugo.WorkingDir $.File.Filename -}} -{{ $gh_repo := ($.Param "github_repo") -}} -{{ $gh_url := ($.Param "github_url") -}} -{{ $gh_subdir := ($.Param "github_subdir") -}} -{{ $gh_project_repo := ($.Param "github_project_repo") -}} -{{ $gh_branch := (default "main" ($.Param "github_branch")) -}} +{{ $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" -}}
{{ 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" -}} + {{ warnf "Warning: use of `github_url` is deprecated. For details, see https://www.docsy.dev/docs/adding-content/repository-links/#github_url-optional" -}} {{ T "post_edit_this" }} {{ else if $gh_repo -}} - {{ $gh_repo_path := printf "%s%s" $gh_branch $pathFormatted -}} - {{ if $gh_subdir -}} - {{ $gh_repo_path = printf "%s/%s%s" $gh_branch $gh_subdir $pathFormatted -}} - {{ end -}} - {{/* Adjust $gh_repo_path based on path_base_for_github_subdir */ -}} + {{/* Adjust $path based on path_base_for_github_subdir */ -}} {{ $ghs_base := $.Param "path_base_for_github_subdir" -}} {{ $ghs_rename := "" -}} {{ if reflect.IsMap $ghs_base -}} @@ -23,9 +20,12 @@ {{ $ghs_base = $ghs_base.from -}} {{ end -}} {{ with $ghs_base -}} - {{ $gh_repo_path = replaceRE . $ghs_rename $gh_repo_path -}} + {{ $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 ) -}}