Skip to content

Support relative paths for --root-dir  #1606

@mre

Description

@mre

In #1576, we added support for the --root-dir parameter.
It is useful for checking absolute links, especially when the rendered documents are located in a subdirectory.

Common usage scenarios for --root-dir

  • Static site builds in a public or dist directory
  • Documentation sites with absolute links
  • Any project where links start with /

Here's a usage example

# Assuming the output html files get rendered into the `public` directory
lychee --root-dir "$(pwd)/public" "**/*.html"

Full documentation here.

Proposal

Add support for relative paths, e.g. . or ./public.

That would be very convenient and relatively easy to implement.
We could apply std::fs::canonicalize when we handle the root-dir:

use std::fs::canonicalize;
use std::path::PathBuf;

fn main() {
        let path = PathBuf::from(".");
        println!("{:?}", canonicalize(path));
}

Our argumentation for not doing that in the first place was that we wanted to be conservative and avoid running into edge-cases. However, after playing with the feature a bit, I'm beginning to think there is no downside to supporting that.

The above example would be simplified to

lychee --root-dir public "**/*.html"

FYI @trask, since you worked on the initial implementation.

Edit: Removed my other proposal of making --root-dir . the default. I'm no longer confident that this is a good idea.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions