manuzhang / mkdocs-htmlproofer-plugin

A MkDocs plugin that validates URL in rendered html files
MIT License
43 stars 16 forks source link

Provide compatibility with mkdocs-material blog plugin #72

Closed SeanTAllen closed 8 months ago

SeanTAllen commented 9 months ago

Prior to this commit, certain assumptions were made about the files seen in on_files that are not true when the mkdocs-material blog plugin is used.

The url seen at the time on_files is called is not guaranteed to be the final url that will appear in html. With the blog plugin, at the time on_files is called, the value will be something like:

blog/posts/foo.md

but at the time we are trying to get a mapping, the url will be something like:

blog/2024/01/foo.html

Due to this change, htmlproofer would fail to validate the url despite it being valid.

To address this, instead of looking up pages from a Dict where the key is set at the time of on_files, we know store a list of Files and check for the search_path for a url against the url attribute of each File to try to find the mapping.

SeanTAllen commented 9 months ago

@manuzhang should the linting errors be fixed as part of this PR?

manuzhang commented 9 months ago

Yes, please fix it

SeanTAllen commented 9 months ago

@manuzhang this particular implementation apparently has an issue with windows. I'm guessing that is a path separator issue. I'll look at it later.

SeanTAllen commented 9 months ago

I think I know what the windows issue is. Testing that out now.

SeanTAllen commented 8 months ago

@manuzhang all set. with the optimization, all the old tests continued to work unchanged. It ends up being a better change.

I tested this locally as well with a site that uses the blog as an extra level of verification.