Check for broken links before they're published
Rotproof checks the links on your live site every day or every week, and tells you when one breaks. The build check catches the ones a change is about to add, before anyone can follow them.
It's a GitHub Action, Rotproof link check. On each pull request it reads your site as the change would build it, and lists the broken links the change brings in, with the file and line of each. It's free on every plan, the Free plan included.
What it checks
- Links to your own pages, against the build. Is the page there, and is the section? Nothing is sent anywhere for these.
- Links to other websites, by Rotproof. Each is checked the way Rotproof checks any link: twice, about a minute apart, before it's called broken. Rotproof receives the addresses and nothing else. Your pages never leave your build.
- Only what the change adds. A link that's already on your live site keeps the answer from its regular check, so most runs take seconds. A link that was already broken is mentioned and never fails the check: the change didn't break it.
- Blocked isn't broken. Some sites turn automated checkers away. Those links are counted as not checked, never as broken.
- Pages the change removes. Other sites, search results and bookmarks link to your pages, and no check of your own links can see those. Rotproof knows which pages your live site has. If one isn't in the build and nothing redirects it, the check lists it, says where it probably moved, and gives you the redirect to add.
Before you start
- A site built on GitHub, with GitHub Actions, into a folder of HTML pages. Docusaurus, MkDocs, Sphinx, VitePress, mdBook, Hugo and Jekyll all build that way. A site whose pages are written by JavaScript in the browser has no links in its HTML for the check to read.
- A Rotproof account with the site added and verified. The free plan is enough. Sign up or sign in.
Set it up
- Create a token. In Rotproof, go to Account, then API tokens. Only an owner of your organization can create one.
- Save it in your repository. On GitHub, open the repository's Settings, then Secrets and variables, then Actions, and add a new repository secret named
ROTPROOF_TOKENwith the token as its value. - Add the check after the step that builds your site:
- name: Check links
uses: rotproof-dev/check-links@v1
with:
path: build
site: https://docs.example.com
token: ${{ secrets.ROTPROOF_TOKEN }}
path is the folder your build writes the finished site to, such as build, site, _site or book. site is the site's address as it is in Rotproof. token is the secret from step 2. Your site's page in Rotproof shows this step with its address filled in.
The next pull request runs the check. Its report is on the run's summary page.
Warn, or stop the change
The fail-on setting decides when the check fails:
none, the default, reports and never fails.newfails when the change adds a broken link.allalso fails on links that are broken inside the build itself, such as a link to a page the build doesn't have.
Start with none, and switch to new once the reports are ones you'd act on.
Pages a change removes
When a page is renamed or deleted, everything that pointed to it breaks: links on other sites, answers on forums, search results and bookmarks. The check compares your build with the pages Rotproof found on your live site in its latest check, from the site's sitemap, which most documentation tools make. A page in the build at any address, or one your build redirects, is fine.
For each page that's gone, the check looks for one new page with the same title or the same name at the end of its address, and suggests redirecting there. It's a warning and never fails the check: your host may redirect in settings the build doesn't contain.
How to add a redirect from an old page, here docs/setup, to the page that replaced it, docs/getting-started:
- Netlify, or Cloudflare Pages or Workers: a line in a
_redirectsfile, in the folder your tool copies into the site as it is. Write the301: Cloudflare otherwise uses 302./docs/setup/ /docs/getting-started/ 301 - Docusaurus: the client redirects plugin,
@docusaurus/plugin-client-redirects, indocusaurus.config.js. Leave out yourbaseUrl.plugins: [ ['@docusaurus/plugin-client-redirects', { redirects: [{ from: '/docs/setup', to: '/docs/getting-started' }], }], ], - MkDocs and Material for MkDocs: the
mkdocs-redirectsplugin inmkdocs.yml. It names the pages' source files, from your docs folder. Listing plugins replaces the default ones, so keepsearch.plugins: - search - redirects: redirect_maps: 'docs/setup.md': 'docs/getting-started.md' - Sphinx: the
sphinx-reredirectsextension inconf.py. The old page is named by its source file without the extension, and the new one is written relative to it.extensions = ["sphinx_reredirects"] redirects = {"docs/setup": "getting-started.html"} - mdBook: in
book.toml. The old page is its file in the built book, and the new one is written relative to it.[output.html.redirect] "/docs/setup.html" = "getting-started.html" - Hugo: the old address in the new page's front matter.
aliases: - /docs/setup/ - Jekyll: the
jekyll-redirect-fromplugin, and the old address in the new page's front matter.redirect_from: - /docs/setup/ - VitePress: it has no redirects of its own. Use your host's, such as a
_redirectsfile indocs/public.
When the check knows your tool, it writes these for you with the real addresses filled in: from a _redirects file in the build, Docusaurus, Hugo or Jekyll. For the others it gives the old and new addresses.
Pull requests from forks
GitHub doesn't give secrets to a pull request from a fork, so there's no token. The check then reads links to your own pages only, and its report says so.
Don't switch the workflow to pull_request_target to get round this. That runs a stranger's change with your secrets, and they can take the token.
Limits
- Up to 500 addresses a list and 10 lists a run, inside your plan's daily link checks. The Free plan has 5,000 a day.
- At most 25 new requests to any one other website a list.
- Results are kept 7 days.
- If Rotproof can't be reached, the check says so and doesn't fail your build.
- Pages a change removes are found from Rotproof's latest check of your live site: weekly on the Free plan, daily on the others. A page removed since then is listed until the next check.
What Rotproof receives
The addresses of the links in your built site, your token, and the site's address. Rotproof requests those addresses as RotproofBot, one request a second to each website, and keeps the results for 7 days. In return, it sends the check the addresses and titles of your live site's pages, which are compared with your build on GitHub's machine. See the privacy policy.
The check's code is public: rotproof-dev/check-links.