Searching front-matter of all docs #64
-
Can a macro inspect the front-matter of all the Markdown files in my project's docs folder? I'm trying to write a This is a great library, thanks! Enjoying playing around with it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Thanks. 👍 Yes you probably could write such a macro! Here are a few pointers. You could write a It could then read all YAML headers . define_env(env):
"""
This is the hook for defining variables, macros and filters
- variables: the dictionary that contains the environment variables
- macro: a decorator function, to declare a macro.
"""
@env.macro
def link_to(key:str) -> str:
"""Finds a doc that has a matching key in its front-matter, and returns an absolute link to that file"""
...
return link Here are the basic instructions for writing macros. To inspect the YAML front matters, you can check some good Python libraries, such as python-frontmatter. Let me know if that's sufficient to get you started? |
Beta Was this translation helpful? Give feedback.
Thanks. 👍
Yes you probably could write such a macro! Here are a few pointers.
You could write a
main.py
program (in the top directory of your project), with a function that scan sthe yaml files in the docs directory (env.conf['docs_dir']
should contain its (relative) name; unless you are sure it's calleddocs
)It could then read all YAML headers .