Skip to main content

Flatpages based on files with yaml syntax

Project description

Install

pip install yamlpage

Usage

>>> import os
>>> from yamlpage import YamlPage, SingleFolderBackend, MultiFolderBackend
>>> p = YamlPage('./content')

Put page

>>> url = '/my/url'
>>> p.put(url, (
...     ('title', 'foo'),
...     ('body|md', '- foo\n- bar'),
... ))
>>> path = './content/^my^url.yaml'
>>> content = open(path).read()
>>> print(content)
title: foo
body|md: |-
    - foo
    - bar
<BLANKLINE>

Get page

>>> p.get(url) == {'body|md': '- foo\n- bar', 'title': 'foo'}
True
>>> p.get('/not/found/') is None
True

Check if page exists

>>> p.exists(url)
True
>>> p.exists('/not/found/')
False

Built in backends

SingleFolderBackend (default) maps ‘my/url’ to filename ‘my^url.yaml’

>>> p = YamlPage('./content')
>>> p.put('single/folder/backend', 'data')
>>> os.path.exists('./content/single^folder^backend.yaml')
True

MultiFolderBackend maps ‘my/url’ to filename ‘my/url.yaml’

>>> p = YamlPage('./content', backend=MultiFolderBackend)
>>> p.put('multi/folder/backend', 'data')
>>> os.path.exists('./content/multi/folder/backend.yaml')
True

Filters

You can automaticaly apply filters to a particular page fields. As an example let’s render body markdown to html.

>>> import misaka
>>> p = YamlPage('./content', filters={"md": misaka.html})
>>> p.get(url)["body"] == '<ul>\n<li>foo</li>\n<li>bar</li>\n</ul>\n'
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yamlpage-3.2.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

yamlpage-3.2.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page