Local File Checking with --root-dir
What Does —root-dir Do?
The --root-dir
parameter tells lychee where to look for files that start with /
. Let’s see an example:
These links start with /
, meaning they’re absolute paths.
If the site is built in a public
directory, the files will be in public/about.html
and public/docs/guide.html
. To check these links, you’d run:
lychee will look for:
./public/about.html
./public/docs/guide.html
When Do You Need —root-dir?
You need --root-dir
when:
- Your HTML contains links starting with
/
- You want to check these links against files on your computer
Common scenarios:
- Static site builds in a
public
ordist
directory - Documentation sites with absolute links
- Any project where links start with
/
Examples
Static Site Builder
If you use Hugo, Jekyll, or similar tools, they often generate sites in a public
directory:
To check the links:
Documentation Site
Many documentation sites use absolute paths for links:
To check these links:
The Difference Between —root-dir and —base
These parameters serve different purposes:
-
--root-dir
is for finding files on your computer- Only affects links that start with
/
- Must be an absolute filesystem path
- Used when checking local files
- Only affects links that start with
-
--base
is for resolving URLs- Must be a URL (like
https://example.com/docs/
) - Used when checking how links will work once deployed
- Affects relative links (like
./guide.html
)
- Must be a URL (like
Using Both Together
Sometimes you need both:
This tells lychee:
- Look for
/
-prefixed files in./public/
- Resolve relative links against
https://example.com/
Troubleshooting
If your links aren’t being found:
- Make sure you’re using an absolute path:
- Check that the files exist in the location you expect:
- Use
--verbose
to see how lychee is resolving paths: