lukasgeiter / mkdocs-awesome-pages-plugin

An MkDocs plugin that simplifies configuring page titles and their order
MIT License
452 stars 35 forks source link

Handle plugin generated content and config #79

Closed thejcannon closed 10 months ago

thejcannon commented 11 months ago

This change allows mkdocs-awesome-pages-plugin to play nicely with mkdocs-gen-files, specifically with generated content (.md) and generated config (.pages).

This is accomplished by:

  1. Defining an on_files in the plugin that synthesizes a File per config in the docs dir. This means we can later unconditionally pull from Files for both in-docs and generated configs.
  2. Passing the Files down the chain to NavigationMeta
    • We can use the Files to validate the "out-of-docs" check, so we also remove the docs_dir arg
    • Additionally, generated files aren't "in-docs", so that check would mean we did't add the generated docs. So removing it is vital to the overall change anyways
  3. Making _gather_metadata operate on a "relative file" abstraction (e.g. the path below "docs_dir)
    • For Pages, that means adding item.file.src_path instead of item.file.abs_src_path
    • For sections, the metadata loading gets tricky. We have to load the absolute path (because that's how the generated files work), but they path should be the relative path so we match correctly later.
  4. Replace Meta.try_load_from with Meta.try_load_from_files such that we always load from Files
    • But as mentioned, if we do successfully load, we need to swap the path attribute with the relative path

That summarizes the package changes, then there was a few test changes top facilitate this change:

Fixes #78

thejcannon commented 11 months ago

@lukasgeiter This is ready to review.

The je ne sais quoi is boiled down to:

thejcannon commented 11 months ago

And to report, this is working as expected on my project :tada:

lukasgeiter commented 10 months ago

Thanks for creating this PR! Before I dive into reviewing, I've noticed some formatting changes that shouldn't be there. Please make sure to format the files using black.

lukasgeiter commented 10 months ago

Please disregard the failing tests for pypy, they have nothing to do with your PR. I've actually just removed them on master so a rebase should get rid of them. The same does not apply for the failing tests on windows, that seems to be an actual issue 😉

thejcannon commented 10 months ago

Thanks for taking a look!

Yeah looks like editor ran black with a different line length (shorter) leading to some spurious reformats. I'll fix those

thejcannon commented 10 months ago

@lukasgeiter All tests are passing! Ready for review when you are.

thejcannon commented 10 months ago

@lukasgeiter I think that should cover those comments. Happy for another look

lukasgeiter commented 10 months ago

Released with version 2.9.2. Thanks again for your work!

thejcannon commented 10 months ago

Thank you for accepting it, and reviewing it