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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file yamlpage-3.2.0.tar.gz.

File metadata

  • Download URL: yamlpage-3.2.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for yamlpage-3.2.0.tar.gz
Algorithm Hash digest
SHA256 b526f40de803b6bc33734a9d72728f5ed6f604395521aafa1e33f4f6e2cb1f0d
MD5 abfe4d9cc7c0341c099f8a648356b3a1
BLAKE2b-256 fdd25d6d239758418832845bb93796ff68cbfda589b562d76dd3e59248844b35

See more details on using hashes here.

File details

Details for the file yamlpage-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: yamlpage-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for yamlpage-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbfd84158d25f04d36fc490e1298ba875ab37b857143ff93090bc838a6576ba1
MD5 b0768c73dc492a3f4303c0ea83c35a91
BLAKE2b-256 45cdf92ecc2a13c8185052860ab885333a2a8ae9c4a3a9251bdd37879b0dde83

See more details on using hashes here.

Supported by

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