Skip to content

Commit

Permalink
Support YAML metadata (Issue #2801)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralsina committed May 28, 2017
1 parent 2d25ac7 commit 7672b57
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
New in master
=============

Features
--------

* Support for YAML metadata (Issue #2801)

New in v7.8.6
=============

Expand Down
15 changes: 15 additions & 0 deletions nikola/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
import pyphen
except ImportError:
pyphen = None
try:
import yaml
except ImportError:
yaml = None

from math import ceil # for reading time feature

Expand Down Expand Up @@ -1023,6 +1027,17 @@ def _get_metadata_from_file(meta_data):
if not meta_data[0]:
meta_data = meta_data[1:]

# If 1st line is '---', then it's YAML metadata
if meta_data[0] == '---':
if yaml is None:
utils.req_missing('pyyaml', 'use YAML metadata')
idx = meta_data.index('---', 1)
meta = yaml.load('\n'.join(meta_data[1:idx]))
# We expect empty metadata to be '', not None
for k in meta:
if meta[k] is None:
meta[k] = ''

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

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ setuptools>=20.3
natsort>=3.5.2
requests>=2.2.0
piexif>=1.0.3
PyYAML==3.12

0 comments on commit 7672b57

Please sign in to comment.