|
| 1 | +<!-- |
| 2 | +# Internal link checking tool |
| 3 | + --> |
| 4 | +# 内置链接检查工具 |
| 5 | + |
| 6 | +<!-- |
| 7 | +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. |
| 8 | + --> |
| 9 | +你可以使用 [htmltest](https://github.com/wjdp/htmltest) 来检查 [`/content/en/`](https://git.k8s.io/website/content/en/) 下面的失效链接。这在重构章节内容、移动页面或者重命名文件或页眉时非常有用。 |
| 10 | + |
| 11 | +<!-- |
| 12 | +## How the tool works |
| 13 | + --> |
| 14 | +## 工作原理 |
| 15 | + |
| 16 | +<!-- |
| 17 | +`htmltest` scans links in the generated HTML files of the kubernetes website repository. It runs using a `make` command which does the following: |
| 18 | + --> |
| 19 | +`htmltest` 会扫描 kubernetes website 仓库构建生成的 HTML 文件。通过执行 `make` 命令进行了下列操作: |
| 20 | + |
| 21 | +<!-- |
| 22 | +- Builds the site and generates output HTML in the `/public` directory of your local `kubernetes/website` repository |
| 23 | +- Pulls the `wdjp/htmltest` Docker image |
| 24 | +- Mounts your local `kubernetes/website` repository to the Docker image |
| 25 | +- Scans the files generated in the `/public` directory and provides command line output when it encounters broken internal links |
| 26 | +--> |
| 27 | +- 构建站点并输出 HTML 到本地 `kubernetes/website` 仓库下的 `/public` 目录中 |
| 28 | +- 拉取 Docker 镜像 `wdjp/htmltest` |
| 29 | +- 挂载本地 `kubernetes/website` 仓库到 Docker 容器中 |
| 30 | +- 扫描 `/public` 目录下生成的文件并将遇到的失效链接通过命令行打印出来 |
| 31 | + |
| 32 | +<!-- |
| 33 | +## What it does and doesn't check |
| 34 | + --> |
| 35 | +## 哪些链接不会检查 |
| 36 | + |
| 37 | +<!-- |
| 38 | +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. |
| 39 | +
|
| 40 | +The link checker scans the following: |
| 41 | + --> |
| 42 | +该链接检查器扫描生成的 HTML 文件,而非原始的 Markdown. 该 htmltest 工具依赖于一个配置文件,[`.htmltest.yml`](https://git.k8s.io/website/.htmltest.yml),来决定检查哪些内容。 |
| 43 | + |
| 44 | +该链接检查器扫描以下内容: |
| 45 | + |
| 46 | +<!-- |
| 47 | +- All content generated from Markdown in [`/content/en/docs`](https://git.k8s.io/website/content/en/docs/) directory, excluding: |
| 48 | + - Generated API references, for example https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/ |
| 49 | +- All internal links, excluding: |
| 50 | + - Empty hashes (`<a href="#">` or `[title](#)`) and empty hrefs (`<a href="">` or `[title]()`) |
| 51 | + - Internal links to images and other media files |
| 52 | + --> |
| 53 | +- 所有由 [`/content/en/docs`](https://git.k8s.io/website/content/en/docs/) 目录下的 Markdown 文件生成的内容,但不包括: |
| 54 | + - 生成的 API 参考,例如 https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/ |
| 55 | +- 所有的内部链接,但不包括: |
| 56 | + - 空白锚点 (`<a href="#">` 或 `[title](#)`) 以及空白目标地址 (`<a href="">` 或 `[title]()`) |
| 57 | + - 指向图片或其他媒体文件的内部链接 |
| 58 | + |
| 59 | +<!-- |
| 60 | +The link checker does not scan the following: |
| 61 | + --> |
| 62 | +该链接检查器不会扫描以下内容: |
| 63 | + |
| 64 | +<!-- |
| 65 | +- 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 |
| 66 | +- Top level pages and their children, for example: `/training`, `/community`, `/case-studies/adidas` |
| 67 | +- Blog posts |
| 68 | +- API Reference documentation, for example: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/ |
| 69 | +- Localizations |
| 70 | + --> |
| 71 | +- 包含在顶部和侧边导航栏的链接,以及页脚链接或者页面的 `<head>` 部分中的链接,例如 CSS 样式表、脚本以及元信息的链接。 |
| 72 | +- 顶级页面及其子页面,例如: `/training`, `/community`, `/case-studies/adidas` |
| 73 | +- 博客文章 |
| 74 | +- API 参考文档,例如:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/ |
| 75 | +- 本地化内容 |
| 76 | + |
| 77 | +<!-- |
| 78 | +## Prerequisites and installation |
| 79 | + --> |
| 80 | +## 先决条件以及安装说明 |
| 81 | + |
| 82 | +<!-- |
| 83 | +You must install |
| 84 | + --> |
| 85 | +必须安装: |
| 86 | +* [Docker](https://docs.docker.com/get-docker/) |
| 87 | +* [make](https://www.gnu.org/software/make/) |
| 88 | + |
| 89 | +<!-- |
| 90 | +## Running the link checker |
| 91 | + --> |
| 92 | +## 运行链接检查器 |
| 93 | + |
| 94 | +<!-- |
| 95 | +To run the link checker: |
| 96 | + --> |
| 97 | +运行链接检查器需要: |
| 98 | + |
| 99 | +<!-- |
| 100 | +1. Navigate to the root directory of your local `kubernetes/website` repository. |
| 101 | +
|
| 102 | +2. Run the following command: |
| 103 | + --> |
| 104 | +1. 进入本地 `kubernetes/website` 仓库的根目录下。 |
| 105 | + |
| 106 | +2. 执行如下命令: |
| 107 | + |
| 108 | + ``` |
| 109 | + make docker-internal-linkcheck |
| 110 | + ``` |
| 111 | + |
| 112 | +<!-- |
| 113 | +## Understanding the output |
| 114 | + --> |
| 115 | +## 理解输出的内容 |
| 116 | + |
| 117 | +<!-- |
| 118 | +If the link checker finds broken links, the output is similar to the following: |
| 119 | + --> |
| 120 | +如果链接检查器发现了失效链接,则输出内容类似如下: |
| 121 | + |
| 122 | +``` |
| 123 | +tasks/access-kubernetes-api/custom-resources/index.html |
| 124 | + hash does not exist --- tasks/access-kubernetes-api/custom-resources/index.html --> #preserving-unknown-fields |
| 125 | + hash does not exist --- tasks/access-kubernetes-api/custom-resources/index.html --> #preserving-unknown-fields |
| 126 | +``` |
| 127 | + |
| 128 | +<!-- |
| 129 | +This is one set of broken links. The log adds an output for each page with broken links. |
| 130 | +
|
| 131 | +In this output, the file with broken links is `tasks/access-kubernetes-api/custom-resources.md`. |
| 132 | +
|
| 133 | +The tool gives a reason: `hash does not exist`. In most cases, you can ignore this. |
| 134 | +
|
| 135 | +The target URL is `#preserving-unknown-fields`. |
| 136 | +
|
| 137 | +One way to fix this is to: |
| 138 | + --> |
| 139 | +这是一系列失效链接。该日志附带了每个页面下的失效链接。 |
| 140 | + |
| 141 | +在这部分输出中,包含失效链接的文件是 `tasks/access-kubernetes-api/custom-resources.md`. |
| 142 | + |
| 143 | +该工具给出了一个理由:`hash does not exist`. 在大部分情况下,你可以忽略这个。 |
| 144 | + |
| 145 | +目标链接是 `#preserving-unknown-fields`. |
| 146 | + |
| 147 | +修复这个问题的一种方式是: |
| 148 | + |
| 149 | +<!-- |
| 150 | +1. Navigate to the Markdown file with a broken link. |
| 151 | +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`. |
| 152 | +3. Fix the link. For a broken page hash (or _anchor_) link, check whether the topic was renamed or removed. |
| 153 | + --> |
| 154 | +1. 转到含有失效链接的 Markdown 文件。 |
| 155 | +2. 使用文本编辑器全文搜索失效链接的 URL(通常使用 Ctrl+F 或 Command+F)`#preserving-unknown-fields`. |
| 156 | +3. 修复该链接。对于一个失效的锚点(或者 _anchor_ )链接,检查该主题是否已更名或者移除。 |
| 157 | + |
| 158 | +<!-- |
| 159 | +Run htmltest to verify that broken links are fixed. |
| 160 | + --> |
| 161 | +运行 htmltest 来验证失效链接是否已修复。 |
0 commit comments