-
Notifications
You must be signed in to change notification settings - Fork 184
Fix: Disable edit links for unreleased versions #1066
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this overridig docsy's existing template?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this overrides Docsy's existing page-meta-links.html template. Hugo's theme override mechanism allows placing a file at the same relative path in themes/docsy-overrides/ to replace the original. The only modification from the original Docsy template is lines 8-11, which dynamically sets $gh_branch to GITHUB_SHA (GitHub Actions) or HEAD (Netlify) when running in CI environments. This ensures edit links point to the correct commit/branch for new files introduced in PRs, preventing 404 errors during link checking
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chalin tried very hard to avoid unnecessary theme overrides, especially for relatively complex templates. I would rather just keep the ignore instruction, except that the regex seems wrong and we could make it more precise |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| {{/* 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 */ -}} | ||
|
|
||
| {{ 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" -}} | ||
| {{ $is_unreleased := in $path "_dev" -}} | ||
yurishkuro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <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/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" $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 -}} | ||
|
|
||
| {{ if not $is_unreleased -}} | ||
| <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> | ||
| {{ end -}} | ||
| <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 -}} | ||
| {{ 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 }} | ||
| </div> | ||
| {{ end -}} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the ignore rule for Docsy GitHub
new|editlinks will make htmltest fail on pull requests that add new documentation files outside_dev(notably the automated release PR, which adds a newcontent/docs/v2/<version>/tree). Those pages will still emit GitHub URLs targetingmain, which 404 until after merge. Either keep ignoring these GitHub URLs in PR builds, or change the generated URLs to point at the current PR branch/commit for CI link-check runs.