Skip to content
Permalink
Browse files

support TOML metadata

  • Loading branch information...
ralsina committed May 28, 2017
1 parent 5885f69 commit 2948013f0b9c5128eba98f099d1db0b832fb8de3
Showing with 31 additions and 3 deletions.
  1. +1 −1 CHANGES.txt
  2. +15 −2 docs/manual.txt
  3. +14 −0 nikola/post.py
  4. +1 −0 requirements-extras.txt
@@ -4,7 +4,7 @@ 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:
@@ -1038,6 +1042,16 @@ def _get_metadata_from_file(meta_data):
for k in meta:
if meta[k] is None:
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 2948013

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