fralau / mkdocs-macros-plugin

Create richer and more beautiful pages in MkDocs, by using variables and calls to macros in the markdown code.
https://mkdocs-macros-plugin.readthedocs.io
Other
321 stars 50 forks source link

Using a source file containing a yaml list #96

Closed akhmerov closed 3 years ago

akhmerov commented 3 years ago

I am switching an existing repo to mkdocs. For historical reason, my data is stored as a list in the root of a yaml file. Currently, when a file is loaded, update(self.variables, content) is called. This naturally fails if content is a list. Since this yaml format is used in several places throughout my codebase, I would prefer to keep it as is.

Therefore I have two questions:

  1. Is there a workaround in the current version of the macros plugin, which would allow to load yaml files containing lists?
  2. Would it be desirable to be able to load yaml content other than dictionaries, for example by putting them in a dictionary {filename: content}

Thanks for the powerful plugin!

github-actions[bot] commented 3 years ago

Welcome to this project and thank you!' first issue

akhmerov commented 3 years ago

Hmm, another alternative for supporting loading of arbitrary yaml data would be to extend the specification for include_yaml to allow dictionaries:

include_yaml:
  - data/file1.yml
  - key: data/file2.yml
fralau commented 3 years ago

@akhmerov That sounds like an interesting use case!

Could you give me an example of how your yaml file would look like, and what you would like to do with it?

akhmerov commented 3 years ago

It's https://github.com/virtualscienceforum/virtualscienceforum/blob/master/talks.yml, and it's in a repo for hosting online talks.

akhmerov commented 3 years ago

See #97 for a possible resolution.

akhmerov commented 3 years ago

And here's how it'd look in use: mkdocs.yml. Works like a charm.

fralau commented 3 years ago

I get the point: it's elegant.

Let me check further on this.

akhmerov commented 3 years ago

I wouldn't go as far as to say elegant, but it's backwards-compatible, and better for interoperability with other tooling since it allows to load any data into the template context without format restrictions.