Skip to content

Commit

Permalink
Toml metadata (#2803)
Browse files Browse the repository at this point in the history
* support TOML metadata
  • Loading branch information
ralsina committed May 28, 2017
1 parent 18a4c67 commit 1ea109b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Expand Up @@ -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
=============
Expand Down
17 changes: 15 additions & 2 deletions docs/manual.txt
Expand Up @@ -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

Expand All @@ -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
`````

Expand Down
13 changes: 13 additions & 0 deletions nikola/post.py
Expand Up @@ -51,6 +51,10 @@
import pyphen
except ImportError:
pyphen = None
try:
import toml
except ImportError:
toml = None
try:
import yaml
except ImportError:
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions requirements-extras.txt
Expand Up @@ -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.