Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError when nav is generated automatically #62

Closed
wants to merge 1 commit into from

Conversation

gferon
Copy link

@gferon gferon commented Nov 4, 2021

if nav is not specified in mkdocs.yml, the entire on_config function body is skipped but on_serve relies on self.originalDocsDir.

@gferon gferon requested a review from a team as a code owner November 4, 2021 10:20
Copy link
Member

@emmaindal emmaindal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @gferon, I've added a comment just to understand the use case a bit more!

@@ -28,6 +28,7 @@ def __init__(self):
def on_config(self, config):
# If no 'nav' defined, we don't need to run.
if not config.get('nav'):
self.originalDocsDir = config['docs_dir']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm interested in knowing more about the use case for this. The way I understand it is that the !import statements needs to be configured in the 'nav'. So if you do not have a nav, its almost like we don't want to do anything and bubble some feedback up to the user that a nav is required to use this plugin?

Copy link
Author

@gferon gferon Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Backstage, which makes our mkdocs depend on mkdocs-tech-core.

Some pages were added to our documentation without properly editing the navigation. After reading the documentation of mkdocs, I discovered that if you omit nav, (quoting the doc) it will contain an alphanumerically sorted, nested list of all the Markdown files found within the docs_dir and its sub-directories, which is ideal for us.

Upon removing nav, running mkdocs serve failed, which made me submit this fix 😄

EDIT: maybe it would be more clear if I added a test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gferon Understand, it makes sense to me! Thanks for giving a bit more context. If you can add a test that would be great!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gferon, just for follow-up, want to add tests? Thanks in advance 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reminding me! I had a quick look, and I'm actually not sure how I could easily add a bats test because the bug only affects mkdocs serve and per my understanding, most tests verify that docs can be built using mkdocs build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we can implement some unittests? just to test the on_confg? I found some examples for the search plugin https://github.com/mkdocs/mkdocs/blob/master/mkdocs/tests/search_tests.py#L208.

@camilaibs
Copy link
Contributor

Hi @gferon 👋🏻 ,
Thanks again for contributing!
I would like to ask if you had time to take a look at Emma's example here.
Would you still like to add tests? Tell us what your plan is, no pressure, just follow along 🙌🏻

@richardmcsong
Copy link
Contributor

richardmcsong commented Jan 21, 2022

I found this PR because I ran into this exact use case! Anything I can do to help with this?

@gferon
Copy link
Author

gferon commented Jan 27, 2022

I'll close this PR since it looks like it'll get taken care of with #69

@gferon gferon closed this Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants