lychee icon indicating copy to clipboard operation
lychee copied to clipboard

Preserve original URLs when `--remap` is used

Open oponomarov-tu opened this issue 1 year ago • 1 comments

I'm using the --remap feature to validate links pointing to private GitHub repositories containing documentation.

$ lychee . --remap 'https://github.com/<my org>/(?P<repo>[^/]+)/(?:blob|tree)/(?P<revision>[^/]+)/(?P<path>[^#]+) https://api.github.com/repos/<my org>/$repo/contents/$path?ref=$revision' --header "Authorization=token $GITHUB_TOKEN" -v

Since there's no straightforward way to verify if a link to a private GitHub repository is broken, I'm mitigating this by using both the --github-token argument and setting the --header "Authorization=token $GITHUB_TOKEN".

With this setup, the --remap feature substitutes links like:

[`sre-design-docs/use-conventional-commit-messages.md`](https://github.com/<my org>/<my private repo>/blob/master/docs/design/docs/non-existint-document.md)

With their API equivalent:

✗ [404] https://api.github.com/repos/<my org>/<my private repo>/contents/docs/design/docs/non-existint-document.md?ref=master | Failed: Network error: Not Found

This approach works as expected, but I’m wondering if there's a way to convert the output link back to its original Markdown format. The goal is to prevent confusion when users search for the broken link in the document. Ideally, I’d like this validation to occur "in the background" to maintain a seamless user experience.

Thank you for considering this feature request. I hope others find this workaround helpful as well.

oponomarov-tu avatar Sep 02 '24 10:09 oponomarov-tu