GithubHelp home page GithubHelp logo

shuttle1987 / gilbert-frontmatter-markdown Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 26 KB

A markdown loader for Gilbert that will process frontmatter

License: GNU Affero General Public License v3.0

Python 100.00%
gilbert markdown-loader

gilbert-frontmatter-markdown's People

Contributors

shuttle1987 avatar

Stargazers

 avatar

Watchers

 avatar

gilbert-frontmatter-markdown's Issues

Frontmatter-markdown metadata value type

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.

Metadata is passed in only as strings which can fail the validation step later

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

Handling for markdown with no frontmatter

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.