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

Rework and clean up page-meta-links.html + CHANGELOG entry #1807

Merged
merged 1 commit into from
Feb 1, 2024
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
2 changes: 1 addition & 1 deletion .vscode/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{
"version": "0.2",
"caseSensitive": true,
"words": ["Docsy", "shortcode", "shortcodes"]
"words": ["Docsy", "hugo", "shortcode", "shortcodes", "warnf"]
}
20 changes: 18 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
cSpell:ignore deining docsy gtag lookandfeel navs
cSpell:ignore deining docsy gitmodules gtag lookandfeel mhchem navs tabpane
-->

# Changelog
Expand All @@ -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

Expand Down
26 changes: 13 additions & 13 deletions layouts/partials/page-meta-links.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{{/* 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" -}}
<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" -}}
{{ 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 -}}
{{ $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 -}}
{{ $ghs_rename = $ghs_base.to -}}
{{ $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 ) -}}
Expand Down