From 754bee9fab7ef2176ab1cb2e9ae01db94d2d17fb Mon Sep 17 00:00:00 2001 From: Miguel Garcia Date: Sat, 27 May 2023 18:54:04 +0200 Subject: [PATCH] linkchecker: detect absolute links with missing leading slash When an absolute link is missing the leading slash (it starts with "docs/foo" instead of "/docs/foo/"), print a more specific error instead of the generic catch-all warning. Without the leading slash, these are treated as relative paths and so lead to non-existing pages. Also, while we're at it, fix the instance it detects. --- .../setup/production-environment/container-runtimes.md | 2 +- scripts/README.md | 4 ++++ scripts/linkchecker.py | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/content/en/docs/setup/production-environment/container-runtimes.md b/content/en/docs/setup/production-environment/container-runtimes.md index 9c3074a867..46ffce3bb9 100644 --- a/content/en/docs/setup/production-environment/container-runtimes.md +++ b/content/en/docs/setup/production-environment/container-runtimes.md @@ -113,7 +113,7 @@ There are two cgroup drivers available: ### cgroupfs driver {#cgroupfs-cgroup-driver} -The `cgroupfs` driver is the [default cgroup driver in the kubelet](docs/reference/config-api/kubelet-config.v1beta1). +The `cgroupfs` driver is the [default cgroup driver in the kubelet](/docs/reference/config-api/kubelet-config.v1beta1). When the `cgroupfs` driver is used, the kubelet and the container runtime directly interface with the cgroup filesystem to configure cgroups. diff --git a/scripts/README.md b/scripts/README.md index a33b87a61f..42e1afcfcd 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -140,6 +140,10 @@ Cases handled: + /docs/bar : is a redirect entry, or + /docs/bar : is something we don't understand ++ [foo](/docs/bar/...) : leading slash missing for absolute path + ++ [foo](docs/bar/...) : leading slash missing for absolute path + ``` ## lsync.sh diff --git a/scripts/linkchecker.py b/scripts/linkchecker.py index ece90b5c98..3f719b26c3 100755 --- a/scripts/linkchecker.py +++ b/scripts/linkchecker.py @@ -34,6 +34,10 @@ # + /docs/bar : is a redirect entry, or # + /docs/bar : is something we don't understand # +# + [foo](/docs/bar/...) : leading slash missing for absolute path +# +# + [foo](docs/bar/...) : leading slash missing for absolute path +# # + {{ < api-reference page="" anchor="" ... > }} # + {{ < api-reference page="" > }} @@ -334,6 +338,11 @@ def check_target(page, anchor, target): return new_record("WARNING", msg, target) return new_record("ERROR", "Missing link for [%s]" % anchor, target) + # absolute link missing leading slash + if (target.startswith("docs/") or target.startswith(LANG + "/docs/")): + return new_record("ERROR", "Missing leading slash. Try \"/%s\"" % + target, target) + msg = "Link may be wrong for the anchor [%s]" % anchor return new_record("WARNING", msg, target)