mkdocs / mkdocs-redirects

Open source plugin for Mkdocs page redirects
MIT License
176 stars 25 forks source link

Computed URLs are not taken into account when resolving target URL #46

Closed squidfunk closed 1 year ago

squidfunk commented 1 year ago

When defining redirects for Material for MkDocs' new built-in blog plugin, I stumbled upon a problem where computed URLs are not taken into account. The blog plugin recursively enumerates all Markdown files in the folder docs/blog/posts and then rewrites the File objects to have the correct dest_path and url values in the on_files hook. This is done so MkDocs and other plugins know the correct destinations for all blog posts. The result looks like this:

File(
  src_path='blog/posts/blog-support-just-landed.md', 
  dest_path='blog/2022/09/12/blog-support-just-landed/index.html', 
  name='blog-support-just-landed', 
  url='blog/2022/09/12/blog-support-just-landed/'
)

Now, when I map the old paths to the new src_path, the redirects plugin will ignore the computed, file.url and compute the target URL by itself, resulting in blog/posts/blog-support-just-landed/, which mismatches the destination URL.

Possible fix in #45.