shuttle1987 / gilbert-frontmatter-markdown Goto Github PK
View Code? Open in Web Editor NEWA markdown loader for Gilbert that will process frontmatter
License: GNU Affero General Public License v3.0
A markdown loader for Gilbert that will process frontmatter
License: GNU Affero General Public License v3.0
The frontmatter-loader stores metadata values as a list of strings and can't be rendered in the templates the same way as the metadata values from the yaml loader, which are stored as any type.
Take for example this line in our default.html template, which takes the value found in title
and inserts it into the title tag:
{% block title %}{{ this.title }}{% endblock %}
For any .yaml
extension being rendered the output is <title>Blog</title>
with the value in the tag, but for any .md
extension the rendered output is empty <title></title>
I added some print lines to see the difference in metadata. In frontmatter_markdown.py:
class FrontmatterMarkdownPage(Page):
extras: list = ['meta']
@oneshot
def content(self):
extras = self.extras
if not extras:
extras = self.site.config.get('content_type', {}).get('MarkdownPage', [])
md = markdown.Markdown(extensions=extras, output_format='html5')
processed = md.convert(self.data)
print('md meta: ', md.Meta)
return processed
gilbert render
Rendering index.md ...
md meta: {'title': ['Home'], 'in_menu': ['False']}
I realised this from the python markdown docs
Note that the keys are all lowercase and the values consist of a list of strings where each item is one line for that key.
Where as in yaml.py:
def load_yaml(path: Path):
with path.open() as fin:
loader = yaml.Loader(fin)
meta = loader.get_data()
# PyYAML Reader greedily consumes chunks from the stream.
# We must recover any un-consumed data, as well as what's left in the stream.
if loader.buffer:
data = loader.buffer[loader.pointer:-1]
else:
data = ''
data += fin.read()
print('yaml meta: ', meta)
return data, meta
gilbert render
Found 17 content objects.
yaml meta: {'title': 'Blog', 'template': 'blog.html'}`
In PyYAML
PyYAML allows you to construct a Python object of any type.
Would be useful to publish this plugin on PyPi
Take for example this schema for a page:
class Page(Templated, Content):
in_menu: bool = True
call_to_action_text: str
This type of page data fails validation:
---
title: Home
in_menu: false
---
We give high-performing companies the tools they need to compete in the digital age, from skills development and automation to communications and strategy expertise.
the title
and in_menu
items both get passed over as strings here
As of #4 if a markdown file has no frontmatter it will be loaded with the meta dictionary being empty. This isn't the same as what happens with the default markdown loader. Perhaps this should be changed?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.