Skip to content

Commit

Permalink
Merge branch 'master' into fixing-pages-index
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwpolska committed Mar 25, 2017
2 parents ea2c609 + 958ff91 commit 204fd33
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 18 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Expand Up @@ -104,6 +104,7 @@
* `Sean Pue <https://github.com/seanpue>`_
* `Simon van der Veldt <https://github.com/simonvanderveldt>`_
* `Stefan Näwe <https://github.com/snaewe>`_
* `Stephan Fitzpatrick <https://github.com/knowsuchagency>`_
* `Sukil Etxenike <https://github.com/sukiletxe>`_
* `Thibauld Nion <https://github.com/tibonihoo>`_
* `Thomas Burette <https://github.com/tburette>`_
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* Refactor RSS feed generation to allow better plugin access
* Add Jupyter config as dependency for jupyter posts (by @knowsuchagency)
* Make ``nikola plugin --list-installed`` more readable (Issue #2692)
* Accept ``now`` in post-list date conditions
* Add ``RSS_COPYRIGHT``, ``RSS_COPYRIGHT_PLAIN``, and
Expand Down
24 changes: 13 additions & 11 deletions nikola/nikola.py
Expand Up @@ -1664,10 +1664,10 @@ def _get_rss_copyright(self, lang, rss_plain):
else:
return self.config['RSS_COPYRIGHT'](lang)

def generic_rss_renderer(self, lang, title, link, description, timeline, output_path,
rss_teasers, rss_plain, feed_length=10, feed_url=None,
enclosure=_enclosure, rss_links_append_query=None, copyright_=None):
"""Take all necessary data, and render a RSS feed in output_path."""
def generic_rss_feed(self, lang, title, link, description, timeline,
rss_teasers, rss_plain, feed_length=10, feed_url=None,
enclosure=_enclosure, rss_links_append_query=None, copyright_=None):
"""Generate an ExtendedRSS2 feed object for later use."""
rss_obj = utils.ExtendedRSS2(
title=title,
link=utils.encodelink(link),
Expand Down Expand Up @@ -1746,14 +1746,16 @@ def generic_rss_renderer(self, lang, title, link, description, timeline, output_
rss_obj.items = items
rss_obj.self_url = feed_url
rss_obj.rss_attrs["xmlns:atom"] = "http://www.w3.org/2005/Atom"
return rss_obj

dst_dir = os.path.dirname(output_path)
utils.makedirs(dst_dir)
with io.open(output_path, "w+", encoding="utf-8") as rss_file:
data = rss_obj.to_xml(encoding='utf-8')
if isinstance(data, utils.bytes_str):
data = data.decode('utf-8')
rss_file.write(data)
def generic_rss_renderer(self, lang, title, link, description, timeline, output_path,
rss_teasers, rss_plain, feed_length=10, feed_url=None,
enclosure=_enclosure, rss_links_append_query=None, copyright_=None):
"""Take all necessary data, and render a RSS feed in output_path."""
rss_obj = self.generic_rss_feed(lang, title, link, description, timeline,
rss_teasers, rss_plain, feed_length=feed_length, feed_url=feed_url,
enclosure=enclosure, rss_links_append_query=rss_links_append_query, copyright_=copyright_)
utils.rss_writer(rss_obj, output_path)

def path(self, kind, name, lang=None, is_link=False, **kwargs):
r"""Build the path to a certain kind of page.
Expand Down
29 changes: 29 additions & 0 deletions nikola/plugins/compile/ipynb.py
Expand Up @@ -28,6 +28,7 @@

from __future__ import unicode_literals, print_function
import io
import json
import os
import sys

Expand Down Expand Up @@ -82,6 +83,7 @@ def _compile_string(self, nb_json):
if flag is None:
req_missing(['ipython[notebook]>=2.0.0'], 'build this site (compile ipynb)')
c = Config(self.site.config['IPYNB_CONFIG'])
c.update(get_default_jupyter_config())
exportHtml = HTMLExporter(config=c)
body, _ = exportHtml.from_notebook_node(nb_json)
return body
Expand Down Expand Up @@ -190,3 +192,30 @@ def create_post(self, path, **kw):
nbformat.write(nb, fd, 4)
else:
nbformat.write(nb, fd, 'ipynb')


def get_default_jupyter_config():
"""Search default jupyter configuration location paths.
Return dictionary from configuration json files.
"""
config = {}
try:
from jupyter_core.paths import jupyter_config_path
except ImportError:
# jupyter not installed, must be using IPython
return config

for parent in jupyter_config_path():
try:
for file in os.listdir(parent):
if 'nbconvert' in file and file.endswith('.json'):
abs_path = os.path.join(parent, file)
with open(abs_path) as config_file:
config.update(json.load(config_file))
except OSError:
# some paths jupyter uses to find configurations
# may not exist
pass

return config
18 changes: 15 additions & 3 deletions nikola/utils.py
Expand Up @@ -97,7 +97,7 @@
'clone_treenode', 'flatten_tree_structure',
'parse_escaped_hierarchical_category_name',
'join_hierarchical_category_path', 'clean_before_deployment',
'sort_posts', 'indent', 'load_data', 'html_unescape',)
'sort_posts', 'indent', 'load_data', 'html_unescape', 'rss_writer',)

# Are you looking for 'generic_rss_renderer'?
# It's defined in nikola.nikola.Nikola (the site object).
Expand Down Expand Up @@ -1279,9 +1279,10 @@ class ExtendedItem(rss.RSSItem):

def __init__(self, **kw):
"""Initialize RSS item."""
self.creator = kw.pop('creator')
self.creator = kw.pop('creator', None)

# It's an old style class
return rss.RSSItem.__init__(self, **kw)
rss.RSSItem.__init__(self, **kw)

def publish_extensions(self, handler):
"""Publish extensions."""
Expand Down Expand Up @@ -2040,3 +2041,14 @@ def html_unescape(s):
"""Convert all named and numeric character references in the string s to the corresponding unicode characters."""
h = HTMLParser()
return h.unescape(s)


def rss_writer(rss_obj, output_path):
"""Write an RSS object to an xml file."""
dst_dir = os.path.dirname(output_path)
makedirs(dst_dir)
with io.open(output_path, "w+", encoding="utf-8") as rss_file:
data = rss_obj.to_xml(encoding='utf-8')
if isinstance(data, bytes_str):
data = data.decode('utf-8')
rss_file.write(data)
2 changes: 1 addition & 1 deletion requirements-extras.txt
Expand Up @@ -11,5 +11,5 @@ webassets>=0.10.1
notebook>=4.0.0
ipykernel>=4.0.0
ghp-import2>=1.0.0
ws4py==0.3.5
ws4py==0.4.0
watchdog==0.8.3
2 changes: 1 addition & 1 deletion snapcraft/edge/requirements.txt
Expand Up @@ -7,7 +7,7 @@ typogrify>=2.0.4
phpserialize>=1.3
webassets>=0.10.1
ghp-import2>=1.0.0
ws4py==0.3.5
ws4py==0.4.0
watchdog==0.8.3
doit>=0.30.0
Pygments>=1.6
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/requirements.txt
Expand Up @@ -7,7 +7,7 @@ typogrify>=2.0.4
phpserialize>=1.3
webassets>=0.10.1
ghp-import2>=1.0.0
ws4py==0.3.5
ws4py==0.4.0
watchdog==0.8.3
doit>=0.30.0
Pygments>=1.6
Expand Down
2 changes: 1 addition & 1 deletion snapcraft/stable/requirements.txt
Expand Up @@ -7,7 +7,7 @@ typogrify>=2.0.4
phpserialize>=1.3
webassets>=0.10.1
ghp-import2>=1.0.0
ws4py==0.3.5
ws4py==0.4.0
watchdog==0.8.3
doit>=0.30.0
Pygments>=1.6
Expand Down

0 comments on commit 204fd33

Please sign in to comment.