Static Site Link Checks: Stop Broken Internal Links at Build Time (Hugo, Astro, Next.js and More)
Rename a post on a static site and every link to its old URL breaks, usually without a warning. In my tests, Hugo, Astro and Eleventy all built a page with a link to a missing page and finished cleanly. This free folder makes a broken internal link fail the build or the pull request instead: the native setting for each generator where one exists, and a tested lychee check of the built HTML everywhere else.
The build is the cheapest moment to catch a broken link: every page is there, the HTML is exactly what readers and crawlers will receive, and a failed check costs one fix before anything goes live. The offline check runs in milliseconds and makes no network requests.
Who it’s for
Anyone who publishes with Hugo, Astro (with or without Starlight), Eleventy, Next.js, Gatsby, Docusaurus or MkDocs and wants internal links checked automatically, before readers or crawlers hit a 404. Most of it is copy and paste; the workflow needs a GitHub repository.
How to use it
- Find your generator in the README table and copy its setting: the Hugo render hook, the Starlight plugin line, the Docusaurus options or the MkDocs
strictandvalidationblock. - Install lychee, build your site, and run
scripts/check-built-site.shon the output folder. Try it on the included fixture first: it has two broken links on purpose. - Copy
lychee.tomlto your repository andworkflows/link-check.ymlto.github/workflows/, then change the output folder and build command. - Optional: add the weekly external-link workflow, which opens an issue instead of blocking merges.
What you get
- A Hugo link render hook that fails the build on unresolved Markdown links, which Hugo’s built-in hook passes through silently
- Tested settings for Starlight, Next.js (
typedRoutes), Docusaurus and MkDocs, with what each one does and doesn’t catch - A lychee config for offline internal-link and
#fragmentchecks, a one-command script and a broken-link fixture - GitHub Actions workflows: internal links on every pull request, external links weekly
- A linkinator config with a skip pattern that works on linkinator 8, and a note on the common pattern that silently checks nothing
- A README table of what was tested, on which version, and what happened
Limits
Offline checks cover internal links only. Links added by JavaScript after the page loads aren’t in the built HTML, so no file-based checker sees them. Gatsby and the workflows themselves weren’t run in testing; the same lychee version and arguments were tested locally. Everything here is free and open source.
Read the full write-up in stop broken internal links at build time. The course AI-powered Internal Linking Audit and Automation covers shipping links on headless and static sites end to end in Lesson 5.7.
What’s included
- Tested settings for 7 generators, with what each one catches on its own
- Hugo render hook that fails the build on broken Markdown links
- lychee config for offline internal link and #fragment checks, plus a one-command script
- GitHub Actions: internal links on every pull request, external links weekly
- linkinator config with a skip pattern that actually checks links on linkinator 8
Where this resource is used on MLforSEO
Walkthroughs on the blog
Concepts behind it
More internal linking resources
- Coding Script or NotebookLink Blocks for WordPress: Related Posts, Topic Cards, Siblings and Mentions
- Coding Script or NotebookLink Menu to Linking Rules: Python Script for Auto-linking Plugins
- ChecklistBefore You Build: A Checklist for Internal Linking Tools
- Coding Script or NotebookInternal Linking QA and Holdout Group Notebook
- Visualization TemplateInternal Linking Impact Dashboard (Data Studio Template) with Setup Guide
- Coding Script or NotebookInternal Link Menu Notebook: Priority Score and Versioned Recommendations
See all 26 internal linking resources →See all 8 site migrations resources →See all 73 coding script or notebook resources →
