Skip to content
Permalink
Browse files

Toml metadata (#2803)

* support TOML metadata
  • Loading branch information...
ralsina committed May 28, 2017
1 parent 18a4c67 commit 1ea109b0d90cfcfc36ca33ef53d8cf02a539b791
Showing with 31 additions and 3 deletions.
  1. +2 −1 CHANGES.txt
  2. +15 −2 docs/manual.txt
  3. +13 −0 nikola/post.py
  4. +1 −0 requirements-extras.txt
@@ -4,7 +4,8 @@ New in master
Features
--------

* Support for YAML metadata (Issue #2801)

* Support for YAML and TOML metadata (Issue #2801)

New in v7.8.6
=============
@@ -289,8 +289,10 @@ The "traditional" meta field format is:
You can add your own metadata fields in the same manner. If you are not using
reStructuredText, make sure the fields are in a HTML comment in output.

Current Nikola versions experimentally support YAML metadata wrapped by a "---" separator
and in that case, the usual YAML syntax is used:
Current Nikola versions experimentally supports other metadata formats that make it more compatiblw with
other static site generators.

YAML metadata should be wrapped by a "---" separator and in that case, the usual YAML syntax is used:

.. code:: yaml

@@ -300,6 +302,17 @@ and in that case, the usual YAML syntax is used:
date: 2012-09-15 19:52:05 UTC
---

TOML metadata should be wrapped by a "+++" separator and in that case, the usual TOML syntax is used:

.. code:: yaml

+++
title = "How to make money"
slug = "how-to-make-money"
date = "2012-09-15 19:52:05 UTC"
+++


Basic
`````

@@ -51,6 +51,10 @@
import pyphen
except ImportError:
pyphen = None
try:
import toml
except ImportError:
toml = None
try:
import yaml
except ImportError:
@@ -1040,6 +1044,15 @@ def _get_metadata_from_file(meta_data):
meta[k] = ''
return meta

# If 1st line is '+++', then it's TOML metadata
if meta_data[0] == '+++':
if toml is None:
utils.req_missing('toml', 'use TOML metadata', optional=True)
raise ValueError('Error parsing metadata')
idx = meta_data.index('+++', 1)
meta = toml.load('\n'.join(meta_data[1:idx]))
return meta

# First, get metadata from the beginning of the file,
# up to first empty line

@@ -14,4 +14,5 @@ ghp-import2>=1.0.0
ws4py==0.4.2
watchdog==0.8.3
PyYAML==3.12
toml==0.9.2

0 comments on commit 1ea109b

Please sign in to comment.
You can’t perform that action at this time.