rosscdh / mkdocs-markdownextradata-plugin

A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template
MIT License
83 stars 18 forks source link

Allow calling `extra` #35

Closed operte closed 3 years ago

operte commented 3 years ago

This modification allows the user to call extra as the root for all the variables.

For example, given the following file structure:

mkdocs.yaml
docs/
    1_foo.md
    assets/
        1_foo.yaml

mkdocs.yaml:

plugins:
    - search
    - markdownextradata:
        data: docs/assets

1_foo.yaml:

bar: 42

The user can call the variable bar as:

1_foo.md:

The answer to everything is {{extra['1_foo']['bar']}}

Up to now, the user would have to call the variable with {{1_foo.bar}}, which raises a jinja2.exceptions.TemplateSyntaxError, since the name 1_foo is not according to the Python variable naming restrictions.

One unintended effect of this modification is that the user is now able to call all entries in self.mkdocsConfig. If the user declares a file with a name which is the same as a pre-existing key on self.mkdocsConfig, this is not a problem: due to the order in which the dictionaries are merged on line 109, the entries inside self.mkdocsConfig.get("extra") overwrite whatever was in self.mkdocsConfig.

This solves #34.

operte commented 3 years ago

I updated the documentation to inform the user about this option.

In addition, apply_template now catches the TemplateSyntaxError that jinja raises when the file or foldername is not valid. It informs the users about the extra option, refers them to the documentation, and raises the TemplateSyntaxError anyway, since the error might have been raised for another reason.

rosscdh commented 3 years ago

Please add yourself to the README.md as contributors :) and this can go out as the next release

operte commented 3 years ago

Ah yes let me add Tim as well, since he helped think this through. I think he also contributed to the project in the past as well :)

rosscdh commented 3 years ago

Thanks for your contrib ❤️

operte commented 3 years ago

Hey Ross, can you give us an estimate of when there will be a new release? :)

rosscdh commented 3 years ago

https://pypi.org/project/mkdocs-markdownextradata-plugin/

last Saturday evening ;)

On Mon, Mar 1, 2021 at 9:42 AM João Moura notifications@github.com wrote:

Hey Ross, can you give us an estimate of when there will be a new release? :)

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/rosscdh/mkdocs-markdownextradata-plugin/pull/35#issuecomment-787767857, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADA6MWMNAZ3ZIKRKLMS65TTBNHQBANCNFSM4YILX4WA .

operte commented 3 years ago

Oh cool, for some reason I don't see the newer releases here on Github. Thanks a lot! :)