wjdp / htmltest

:white_check_mark: Test generated HTML for problems
MIT License
323 stars 54 forks source link

Allow testing of sites published to subfolders #215

Open theunrepentantgeek opened 1 year ago

theunrepentantgeek commented 1 year ago

All our documentation for the Azure Service Operator project gets published into the subfolder azure-service-operator and we'd like to use htmltest to catch our broken links.

This PR adds support for this scenario, allowing verification of websites that aren't published to the root of a server.

New configuration BaseURL allows specifying the final URL to which the site will be published.

Any trailing folder that is a part of this URL will be trimmed from absolute URLs before checking to see if the file exists. For example, given BaseURL: http://www.example.com/blog, an absolute reference to /blog/post/2023-05-24.html will have /blog/ trimmed from the start, leaving the filepath post/2023-05-24.html for testing.

New configuration CheckSelfReferencesAsInternal (default: false) allows checking of self-external references as though they are internal.

If you have BaseURL: http://www.example.com/blog and a reference to http://www.example.com/blog/post/2023-05-24.html, instead of failing as a broken link (since the file hasn't yet been published), it will now be converted into the internal reference /blog/post/2023-05-24.html and checked.

Full tests are included.

Closes #45 Closes #47 Closes #184

Some background: We've previously been using different tools to try and verify our markdown prior to rendering by Hugo, but we've had multiple issues with broken links making it through to our live website.

wjdp commented 1 year ago

@theunrepentantgeek Nice, thanks for the PR. Will take a look at this

arusahni commented 5 months ago

Hi @wjdp! I hate comment-bumping, but I was wondering if you had a chance to take a look at this PR. I just encountered a need for this.

theunrepentantgeek commented 4 months ago

@wjdp Is there anything I can do (as the PR author) to make this easier for you to review and merge?

And while I'm here - many thanks for htmltest. I know that often it's a thankless job doing the hard work maintaining an open source tool, and that it can be difficult to find the time it deserves. So, once again, thanks.