Skip to content

Commit 2eb6ab1

Browse files
Tim Bannistercelestehorgan
authored andcommitted
Add a link checker
Signed-off-by: Celeste Horgan <[email protected]>
1 parent 7a3d98a commit 2eb6ab1

File tree

14 files changed

+131
-27
lines changed

14 files changed

+131
-27
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ resources/
3333
# Netlify Functions build output
3434
package-lock.json
3535
functions/
36-
node_modules/
36+
node_modules/

.htmltest.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
DirectoryPath: public/docs
2+
IgnoreDirectoryMissingTrailingSlash: true
3+
CheckExternal: false
4+
IgnoreAltMissing: true
5+
CheckImages: false
6+
CheckScripts: false
7+
CheckMeta: false
8+
CheckMetaRefresh: false
9+
CheckLinks: false
10+
EnforceHTML5: false
11+
EnforceHTTPS: false
12+
IgnoreDirectoryMissingTrailingSlash: false
13+
IgnoreInternalEmptyHash: true
14+
IgnoreEmptyHref: true
15+
IgnoreDirs:
16+
- "reference/generated/kubernetes-api"

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,11 @@ docker-serve:
5050
test-examples:
5151
scripts/test_examples.sh install
5252
scripts/test_examples.sh run
53+
54+
.PHONY: link-checker-setup
55+
link-checker-image-pull:
56+
docker pull wjdp/htmltest
57+
58+
docker-internal-linkcheck: link-checker-image-pull
59+
$(DOCKER_RUN) $(DOCKER_IMAGE) hugo --config config.toml,linkcheck-config.toml --buildFuture
60+
$(DOCKER) run --mount type=bind,source=$(CURDIR),target=/test --rm wjdp/htmltest htmltest

config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,4 +313,4 @@ contentDir = "content/uk"
313313
[languages.uk.params]
314314
time_format_blog = "02.01.2006"
315315
# A list of language codes to look for untranslated content, ordered from left to right.
316-
language_alternatives = ["en"]
316+
language_alternatives = ["en"]

content/en/docs/concepts/architecture/cloud-controller.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,4 @@ The cloud controller manager uses Go interfaces to allow implementations from an
212212
The implementation of the shared controllers highlighted in this document (Node, Route, and Service), and some scaffolding along with the shared cloudprovider interface, is part of the Kubernetes core. Implementations specific to cloud providers are outside the core of Kubernetes and implement the `CloudProvider` interface.
213213

214214
For more information about developing plugins, see [Developing Cloud Controller Manager](/docs/tasks/administer-cluster/developing-cloud-controller-manager/).
215-
{{% /capture %}}
215+
{{% /capture %}}

content/en/docs/contribute/new-content/overview.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ was wrong, you (and only you, the submitter) can change it.
5454

5555
Limit pull requests to one language per PR. If you need to make an identical change to the same code sample in multiple languages, open a separate PR for each language.
5656

57+
## Tools for contributors
58+
59+
The [doc contributors tools](https://github.com/kubernetes/website/tree/master/content/en/docs/doc-contributor-tools) directory in the `kubernetes/website` repository contains tools to help your contribution journey go more smoothly.
5760

5861
{{% /capture %}}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Internal link checking tool
2+
3+
You can use [htmltest](https://github.com/wjdp/htmltest) to check for broken links in [`/content/en/`](https://git.k8s.io/website/content/en/). This is useful when refactoring sections of content, moving pages around, or renaming files or page headers.
4+
5+
## How the tool works
6+
7+
`htmltest` scans links in the generated HTML files of the kubernetes website repository. It runs using a `make` command which does the following:
8+
9+
- Builds the site and generates output HTML in the `/public` directory of your local `kubernetes/website` repository
10+
- Pulls the `wdjp/htmltest` Docker image
11+
- Mounts your local `kubernetes/website` repository to the Docker image
12+
- Scans the files generated in the `/public` directory and provides command line output when it encounters broken internal links
13+
14+
## What it does and doesn't check
15+
16+
The link checker scans generated HTML files, not raw Markdown. The htmltest tool depends on a configuration file, [`.htmltest.yml`](https://git.k8s.io/website/.htmltest.yml), to determine which content to examine.
17+
18+
The link checker scans the following:
19+
20+
- All content generated from Markdown in [`/content/en/docs`](https://git.k8s.io/website/content/en/docs/) directory, excluding:
21+
- Generated API references, for example https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/
22+
- All internal links, excluding:
23+
- Empty hashes (`<a href="#">` or `[title](#)`) and empty hrefs (`<a href="">` or `[title]()`)
24+
- Internal links to images and other media files
25+
26+
The link checker does not scan the following:
27+
28+
- Links included in the top and side nav bars, footer links, or links in a page's `<head>` section, such as links to CSS stylesheets, scripts, and meta information
29+
- Top level pages and their children, for example: `/training`, `/community`, `/case-studies/adidas`
30+
- Blog posts
31+
- API Reference documentation, for example: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/
32+
- Localizations
33+
34+
## Prerequisites and installation
35+
36+
You must install
37+
* [Docker](https://docs.docker.com/get-docker/)
38+
* [make](https://www.gnu.org/software/make/)
39+
40+
## Running the link checker
41+
42+
To run the link checker:
43+
44+
1. Navigate to the root directory of your local `kubernetes/website` repository.
45+
46+
2. Run the following command:
47+
48+
```
49+
make docker-internal-linkcheck
50+
```
51+
52+
## Understanding the output
53+
54+
If the link checker finds broken links, the output is similar to the following:
55+
56+
```
57+
tasks/access-kubernetes-api/custom-resources/index.html
58+
hash does not exist --- tasks/access-kubernetes-api/custom-resources/index.html --> #preserving-unknown-fields
59+
hash does not exist --- tasks/access-kubernetes-api/custom-resources/index.html --> #preserving-unknown-fields
60+
```
61+
62+
This is one set of broken links. The log adds an output for each page with broken links.
63+
64+
In this output, the file with broken links is `tasks/access-kubernetes-api/custom-resources.md`.
65+
66+
The tool gives a reason: `hash does not exist`. In most cases, you can ignore this.
67+
68+
The target URL is `#preserving-unknown-fields`.
69+
70+
One way to fix this is to:
71+
72+
1. Navigate to the Markdown file with a broken link.
73+
2. Using a text editor, do a full-text search (usually Ctrl+F or Command+F) for the broken link's URL, `#preserving-unknown-fields`.
74+
3. Fix the link. For a broken page hash (or _anchor_) link, check whether the topic was renamed or removed.
75+
76+
Run htmltest to verify that broken links are fixed.

content/en/docs/home/_index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ menu:
1515
title: "Documentation"
1616
weight: 20
1717
post: >
18-
<p>Learn how to use Kubernetes with conceptual, tutorial, and reference documentation. You can even <a href="/editdocs/" data-auto-burger-exclude>help contribute to the docs</a>!</p>
18+
<p>Learn how to use Kubernetes with conceptual, tutorial, and reference documentation. You can even <a href="/editdocs/" data-auto-burger-exclude data-proofer-ignore>help contribute to the docs</a>!</p>
1919
description: >
2020
Kubernetes is an open source container orchestration engine for automating deployment, scaling, and management of containerized applications. The open source project is hosted by the Cloud Native Computing Foundation.
2121
overview: >
@@ -38,7 +38,7 @@ cards:
3838
button_path: "/docs/setup"
3939
- name: tasks
4040
title: "Learn how to use Kubernetes"
41-
description: "Look up common tasks and how to perform them using a short sequence of steps."
41+
description: "Look up common tasks and how to perform them using a short sequence of steps."
4242
button: "View Tasks"
4343
button_path: "/docs/tasks"
4444
- name: training
@@ -62,4 +62,4 @@ cards:
6262
- name: about
6363
title: About the documentation
6464
description: This website contains documentation for the current and previous 4 versions of Kubernetes.
65-
---
65+
---

layouts/partials/docs/content-page.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{- $filepath := .page.File.Path }}
22
{{- $editLink := printf "https://github.com/kubernetes/website/edit/master/content/%s/%s" .page.Language.Lang $filepath }}
33
<p>
4-
<a href="{{ $editLink }}" id="editPageButton" target="_blank">
4+
<a href="{{ $editLink }}" id="editPageButton" target="_blank" data-proofer-ignore>
55
Edit This Page
66
</a>
77
</p>
@@ -15,4 +15,4 @@ <h1>{{ .page.Title }}</h1>
1515
{{ .page.TableOfContents }}
1616
{{ end }}
1717
{{ .page.Content }}
18-
{{ end }}
18+
{{ end }}

layouts/partials/docs/top-menu.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ <h5>{{ .Params.abstract }}</h5>
1212
<ul>
1313
{{ range $menuSections }}
1414
{{ $yah := $p.IsDescendant . }}
15-
<li><a href="{{ .RelPermalink }}"{{ if $yah }} class="YAH"{{ end }}>{{ .LinkTitle | upper }}</a></li>
15+
<li><a href="{{ .RelPermalink }}"{{ if $yah }} class="YAH"{{ end }} data-proofer-ignore>{{ .LinkTitle | upper }}</a></li>
1616
{{ end }}
1717
</ul>
1818
<form id="searchBox" action="/docs/search/" role="search">
1919
<input type="text" id="search" name="q" placeholder="{{ T "ui_search_placeholder" }}" aria-label="Search">
2020
</form>
21-
</div>
21+
</div>

0 commit comments

Comments
 (0)