Skip to content
Permalink
Browse files

Support YAML metadata (Issue #2801)

  • Loading branch information...
ralsina committed May 28, 2017
1 parent 2d25ac7 commit 7672b573627a323f096ca86ae4d3d192b2446420
Showing with 24 additions and 0 deletions.
  1. +8 −0 CHANGES.txt
  2. +15 −0 nikola/post.py
  3. +1 −0 requirements.txt
@@ -1,3 +1,11 @@
New in master
=============

Features
--------

* Support for YAML metadata (Issue #2801)

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

@@ -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

@@ -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

@@ -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.
You can’t perform that action at this time.