Skip to content

docs: Use relative links to site pages #3657

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
Mar 4, 2025

Conversation

blake
Copy link
Contributor

@blake blake commented Mar 3, 2025

What type of PR is this?
/kind documentation

Background:

Currently when running mkdocs build or mkdocs serve, a flood of informational – and some warnings – are logged to the CLI. For example,

INFO    -  Doc file 'index.md' contains an absolute link '/concepts/roles-and-personas', it was left as is. Did you mean 'concepts/roles-and-personas.md'?
WARNING -  Doc file 'geps/gep-1323/index.md' contains a link '../reference/policy-attachment.md', but the target 'geps/reference/policy-attachment.md' is not found among documentation files.
INFO    -  Doc file 'geps/gep-1619/index.md' contains a link '#BackendLBPolicy-api', but there is no such anchor on this page.

This is because MkDocs recommends that relative paths be used when linking to pages instead of absolute URLs. Linking to relative paths allows MkDocs to identify and warn about broken links to non-existent pages and headings when it is building the site. MkDocs even has this warning about using absolute URLs.

Warning

Using absolute paths with links is not officially supported. Relative paths are adjusted by MkDocs to ensure they are always relative to the page. Absolute paths are not modified at all. This means that your links using absolute paths might work fine in your local environment but they might break once you deploy them to your production server.

A number of PRs have recently been submitted to this project to resolve several broken links or issues where links were not being properly rendered.

Theoretically these issues could've been identified earlier if MkDocs's validation rules were configured to warn upon finding broken links, and strict was enabled.

What this PR does / why we need it:

This commit modifies the documentation to use relative links between pages on the site instead of absolute URLs in order to quell the messages in the logs, and set up the site for potentially using strict mode in the future.

This is a large PR with changes across many files. In order to ensure that the all links were correctly updated and nothing was fat fingered, I wrote a small GNU Awk (gawk) script to assist with modifying the Markdown files. https://gist.github.com/blake/78b166792cd262b6897b784a2dedccfa.

The changes were validated by comparing HTML output of the site when generated from the main branch to the output generated after the Markdown files had been modified by the aforementioned script. For example:

$ mkdocs build --site-dir site
<lots of output>
…

$ find geps/ site-src/ -name '*.md' -prune -not -path "site-src/geps/*" -type f -exec gawk -f modify-urls.awk -i inplace {} \;
<some warnings about non-existent files>

# Output the site into a different directory so that it can be
# compared to the site output prior these changes
$ mkdocs build --site-dir site2
<lots of output>
...

$ diff --recursive -u site site2

The diff is rather large, but much like the diff for this PR, it primarily consists of the generated URLs changing from absolute to relative.

Its important to note that this PR is strictly focused on rewriting internal URLs to align with the format recommended by MkDocs so that broken links and anchors can be easily detected. It is not intended to fix all of the existing broken URLs or broken anchors. Those will be addressed in a subsequent PR.

Which issue(s) this PR fixes:

Does this PR introduce a user-facing change?:

NONE

This commit modifies the documentation to use relative links between
pages on the site instead of absolute URLs.

Linking to a page's relative file path allows MKDocs to ensure that page
exists and/or linked heading actually exists when building the site.

The URLs in the generated HTML files will be relative or absolute,
depending on the location of the linked file relative to a given page.
@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/documentation Categorizes issue or PR as related to documentation. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 3, 2025
@k8s-ci-robot k8s-ci-robot requested review from candita and mlavacca March 3, 2025 08:30
@k8s-ci-robot k8s-ci-robot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/gep PRs related to Gateway Enhancement Proposal(GEP) size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 3, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @blake. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@blake blake marked this pull request as draft March 3, 2025 08:32
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 3, 2025
@blake blake marked this pull request as ready for review March 3, 2025 18:44
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 3, 2025
@robscott
Copy link
Member

robscott commented Mar 4, 2025

This is awesome, thanks for the work on this! Very cool to see the script behind this.

/ok-to-test
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 4, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: blake, robscott

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 4, 2025
@robscott
Copy link
Member

robscott commented Mar 4, 2025

No meaningful changes to GEPs, just fixing links. Removing the auto-hold.

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 4, 2025
@k8s-ci-robot k8s-ci-robot merged commit c31f7c2 into kubernetes-sigs:main Mar 4, 2025
13 checks passed
@blake blake deleted the blake/use-relative-urls branch March 5, 2025 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/documentation Categorizes issue or PR as related to documentation. kind/gep PRs related to Gateway Enhancement Proposal(GEP) lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants