wjdp / htmltest

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

Missing internal file:// links #108

Open andymule opened 5 years ago

andymule commented 5 years ago

Using Hugo to generate my static site. All media etc is working on the site, but the htmltest misses broken links on internally linked static media but catches broken immages linked externally:

![Internal Static Image NOT Detected Broken](/media/angles/asd.png)
![External Image Detected Broken](www.asdd.com/asd.jpg)

This is true when either markdown or html is used for the images, and the HTML I'm generating looks fine (and does render images when they exist):

<a href="file:///C:///Source/vr-sdk-website/website/public/media/angles/asd.png" data-featherlight="image">
<img src="c:///Source/vr-sdk-website/website/public/media/angles/asd.png" alt="Internal Static Image NOT Detected Broken">
</a>
<a href="file:///C:///Source/vr-sdk-website/website/public/design/eye-behavior-and-tracking/www.asdd.com/asd.jpg" data-featherlight="image">
<img src="www.asdd.com/asd.jpg" alt="External Image Detected Broken">
</a>

I'm using these settings to generate my Hugo site to run htmltest across:

baseURL = "C:/Source/vr-sdk-website/website/public/"
canonifyURLs = true #turn all paths into truly absolute paths
relativeURLs = false #Enable this to make all relative URLs relative to content root. Note that this does not affect absolute URLs.
uglyURLs  = true
wjdp commented 5 years ago

Hi, thanks for the report.

This issue is likely because you're using file:// rather than an http based path. This isn't very common as people tend to use a local web server (hugo serve will get you one I think). Nevertheless it should be supported. We're probably also missing test cases for the file scheme as well.

If you try setting your base URL to just a slash and run Hugo's internal server to preview (should work), then run htmltest on the built output (think you need to run hugo build to get) that should also pass.

Side note: for your external links you should prefix them with http:// or https://, we should probably have a check for that as well. Not invalid but is good practice, otherwise the web browser has to guess which scheme to use.

andymule commented 5 years ago

Thanks for the response! I guess I'm confused about running htmltest in this context, then. Isn't htmltest running across the static files built by hugo on my harddrive and not the live website? Isn't this why we provide a DirectoryPath as a variable in the yml file instead of a URL or IP?

wjdp commented 5 years ago

Yep it does run across files on the filesystem. But as a tool to test sites before you push them live it's designed to run on a production build of your site (with http style links).

Because of this we take a directory path and pretend that is your site root on a web server. We then iterate over every file in that directory (impossible with a normal web server) and map all the http style paths to file system paths when we need to check a link.

This makes htmltest useful in a build pipeline where you're gonna be pushing the same build to your web server.

Hopefully that makes sense :smile: