Skip to content
Permalink
Browse files
Better support for a whole tree of data files
  • Loading branch information
ralsina committed Aug 30, 2016
1 parent 6497f53 commit c09787a9307666850685c82e2a55388bb09276e4
Showing with 18 additions and 7 deletions.
  1. +8 −0 CHANGES.txt
  2. +7 −7 nikola/nikola.py
  3. +3 −0 nikola/utils.py
@@ -1,3 +1,11 @@
New in master
=============

Features
--------

* Better support for a tree of files in ``data/``

New in v7.8.0
=============

@@ -32,7 +32,6 @@
from copy import copy
from pkg_resources import resource_filename
import datetime
import glob
import locale
import os
import json
@@ -1136,12 +1135,13 @@ def _set_global_context_from_config(self):

def _set_global_context_from_data(self):
"""Load files from data/ and put them in the global context."""
self._GLOBAL_CONTEXT['data'] = {}
for fname in glob.glob('data/*'):
data = utils.load_data(fname)
key = os.path.basename(fname)
key = os.path.splitext(key)[0]
self._GLOBAL_CONTEXT['data'][key] = data
self._GLOBAL_CONTEXT['data'] = defaultdict(defaultdict)
for root, dirs, files in os.walk('data', followlinks=True):
for fname in files:
fname = os.path.join(root, fname)
data = utils.load_data(fname)
key = os.path.splitext(fname.split(os.sep, 1)[1])[0]
self._GLOBAL_CONTEXT['data'][key] = data

def _activate_plugins_of_category(self, category):
"""Activate all the plugins of a given category and return them."""
@@ -1923,6 +1923,7 @@ def prefixed_lines():
def load_data(path):
"""Given path to a file, load data from it."""
ext = os.path.splitext(path)[-1]
loader = None
if ext in {'.yml', '.yaml'}:
loader = yaml
if yaml is None:
@@ -1935,5 +1936,7 @@ def load_data(path):
req_missing(['toml'], 'use TOML data files')
return {}
loader = toml
if loader is None:
return
with io.open(path, 'r', encoding='utf8') as inf:
return loader.load(inf)

0 comments on commit c09787a

Please sign in to comment.