Skip to content

Conversation

RoseWrightdev
Copy link

@RoseWrightdev RoseWrightdev commented Aug 16, 2025

Summary

/kind feature
/kind docs

This pull request introduces tooling to facilitate large-scale documentation refactoring within MkDocs. It addresses the challenge of maintaining link integrity during file reorganization.

The implementation provides a command-line utility and an automated build hook that work together to assign permanent IDs to documents, generate 301 redirects for moved files, and convert fragile relative links into a resilient, future-proof macro format.

This tool serves as the technical foundation for the documentation migration outlined in the accompanying proposal, making a safe and efficient refactor achievable.

The Problem

When restructuring a documentation site, manually updating hundreds of internal links and creating redirects is not only tedious but also highly prone to errors. This process often leads to:

  • Broken Internal Links: Resulting in a fragmented user experience.
  • Loss of SEO Rank: Caused by failing to redirect old URLs.
  • Increased Maintenance Burden: Making future reorganizations even more daunting.

The Solution

This implementation provides a comprehensive, automated workflow that addresses these issues through a powerful command-line script (linking.py) and seamless build-time integration (main.py).

Key Features & Workflow

The workflow is broken down into three simple, powerful commands:

1. Prepare (--prepare)

Assigns a unique, permanent ID to every Markdown file and creates a redirect_map.json to snapshot the site's initial structure.

python linking.py --prepare

2. Convert Links (--convert-links)

Scans all documents and replaces fragile relative links with a resilient, ID-based macro that is immune to future file moves.

python linking.py --convert-links

Before: [My Link](../../section/another-page.md)
After: [My Link]({{ internal_link('another-page-id') }})

3. Build (mkdocs build)

During the build, the on_files hook automatically compares the new file structure to the original map and injects all necessary 301 redirect rules directly into your mkdocs.yml configuration. No manual updates are needed.

What's Included

Code

  • linking.py: The core CLI tool for preparing files, converting links, and generating redirects via the MkDocs hook.
  • main.py: Provides the internal_link macro functionality to the mkdocs-macros plugin.

Testing

  • Core migration and link conversion functionality.
  • CLI argument parsing and execution.
  • Robustness against edge cases like filesystem differences, link breakage scenarios, and malformed YAML frontmatter.

How to Use

  1. Install Dependencies:
    pip install mkdocs-redirects mkdocs-macros-plugin

  2. Run the Migration Workflow:
    # Step 1: Prepare files with unique IDs
    python linking.py --prepare --docs-dir ./site-src

    # Step 2: Convert all relative links to the macro format
    python linking.py --convert-links --docs-dir ./site-src

    # Step 3: Manually move and reorganize files as needed
    git mv docs/old-path/doc.md docs/new-path/doc.md

    # Step 4: Build the site. Redirects are generated automatically.
    mkdocs build

@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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.

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Aug 16, 2025
Copy link

linux-foundation-easycla bot commented Aug 16, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: RoseWrightdev
Once this PR has been reviewed and has the lgtm label, please assign youngnick for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 16, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @RoseWrightdev!

It looks like this is your first PR to kubernetes-sigs/gateway-api 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/gateway-api has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 16, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @RoseWrightdev. 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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 16, 2025
@youngnick
Copy link
Contributor

On a very quick read, this is looking good. But it's been long enough since I programmed properly in Python that it's going to take me a bit to review the actual code. I may not be able to get to it until after I come back from PTO on the 14th of October, sorry.

I'd like to see this confirmed to work properly with the changes introduced in #4075 though, since it will also change the TOC a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants