summaryrefslogtreecommitdiffstats
path: root/nikola/plugins/compile/rest
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/compile/rest')
-rw-r--r--nikola/plugins/compile/rest/__init__.py19
-rw-r--r--nikola/plugins/compile/rest/gist.py5
-rw-r--r--nikola/plugins/compile/rest/listing.py4
-rw-r--r--nikola/plugins/compile/rest/post_list.py9
4 files changed, 23 insertions, 14 deletions
diff --git a/nikola/plugins/compile/rest/__init__.py b/nikola/plugins/compile/rest/__init__.py
index a93199c..98c7151 100644
--- a/nikola/plugins/compile/rest/__init__.py
+++ b/nikola/plugins/compile/rest/__init__.py
@@ -25,7 +25,7 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import unicode_literals
-import codecs
+import io
import os
import re
@@ -58,8 +58,8 @@ class CompileRest(PageCompiler):
req_missing(['docutils'], 'build this site (compile reStructuredText)')
makedirs(os.path.dirname(dest))
error_level = 100
- with codecs.open(dest, "w+", "utf8") as out_file:
- with codecs.open(source, "r", "utf8") as in_file:
+ with io.open(dest, "w+", encoding="utf8") as out_file:
+ with io.open(source, "r", encoding="utf8") as in_file:
data = in_file.read()
add_ln = 0
if not is_two_file:
@@ -83,11 +83,11 @@ class CompileRest(PageCompiler):
'syntax_highlight': 'short',
'math_output': 'mathjax',
'template': default_template_path,
- }, logger=self.logger, l_source=source, l_add_ln=add_ln)
+ }, logger=self.logger, source_path=source, l_add_ln=add_ln)
out_file.write(output)
deps_path = dest + '.dep'
if deps.list:
- with codecs.open(deps_path, "wb+", "utf8") as deps_file:
+ with io.open(deps_path, "w+", encoding="utf8") as deps_file:
deps_file.write('\n'.join(deps.list))
else:
if os.path.isfile(deps_path):
@@ -108,7 +108,7 @@ class CompileRest(PageCompiler):
makedirs(os.path.dirname(path))
if not content.endswith('\n'):
content += '\n'
- with codecs.open(path, "wb+", "utf8") as fd:
+ with io.open(path, "w+", encoding="utf8") as fd:
if onefile:
fd.write(write_metadata(metadata))
fd.write('\n' + content)
@@ -213,7 +213,7 @@ def rst2html(source, source_path=None, source_class=docutils.io.StringInput,
parser=None, parser_name='restructuredtext', writer=None,
writer_name='html', settings=None, settings_spec=None,
settings_overrides=None, config_section=None,
- enable_exit_status=None, logger=None, l_source='', l_add_ln=0):
+ enable_exit_status=None, logger=None, l_add_ln=0):
"""
Set up & run a `Publisher`, and return a dictionary of document parts.
Dictionary keys are the names of parts, and values are Unicode strings;
@@ -237,7 +237,7 @@ def rst2html(source, source_path=None, source_class=docutils.io.StringInput,
# logger a logger from Nikola
# source source filename (docutils gets a string)
# add_ln amount of metadata lines (see comment in compile_html above)
- reader.l_settings = {'logger': logger, 'source': l_source,
+ reader.l_settings = {'logger': logger, 'source': source_path,
'add_ln': l_add_ln}
pub = docutils.core.Publisher(reader, parser, writer, settings=settings,
@@ -246,7 +246,8 @@ def rst2html(source, source_path=None, source_class=docutils.io.StringInput,
pub.set_components(None, parser_name, writer_name)
pub.process_programmatic_settings(
settings_spec, settings_overrides, config_section)
- pub.set_source(source, source_path)
+ pub.set_source(source, None)
+ pub.settings._nikola_source_path = source_path
pub.set_destination(None, destination_path)
pub.publish(enable_exit_status=enable_exit_status)
diff --git a/nikola/plugins/compile/rest/gist.py b/nikola/plugins/compile/rest/gist.py
index e09ed76..65189b5 100644
--- a/nikola/plugins/compile/rest/gist.py
+++ b/nikola/plugins/compile/rest/gist.py
@@ -49,7 +49,10 @@ class GitHubGist(Directive):
def get_raw_gist(self, gistID):
url = "https://gist.github.com/raw/{0}".format(gistID)
- return requests.get(url).text
+ try:
+ return requests.get(url).text
+ except requests.exceptions.RequestException:
+ raise self.error('Cannot get gist for url={0}'.format(url))
def run(self):
if 'https://' in self.arguments[0]:
diff --git a/nikola/plugins/compile/rest/listing.py b/nikola/plugins/compile/rest/listing.py
index 18a1807..23ec254 100644
--- a/nikola/plugins/compile/rest/listing.py
+++ b/nikola/plugins/compile/rest/listing.py
@@ -29,7 +29,7 @@
from __future__ import unicode_literals
-from codecs import open as codecs_open # for patching purposes
+import io
import os
try:
from urlparse import urlunsplit
@@ -111,7 +111,7 @@ class Listing(Include):
self.options['code'] = lang
if 'linenos' in self.options:
self.options['number-lines'] = self.options['linenos']
- with codecs_open(fpath, 'rb+', 'utf8') as fileobject:
+ with io.open(fpath, 'r+', encoding='utf8') as fileobject:
self.content = fileobject.read().splitlines()
self.state.document.settings.record_dependencies.add(fpath)
target = urlunsplit(("link", 'listing', fname, '', ''))
diff --git a/nikola/plugins/compile/rest/post_list.py b/nikola/plugins/compile/rest/post_list.py
index 456e571..f719e31 100644
--- a/nikola/plugins/compile/rest/post_list.py
+++ b/nikola/plugins/compile/rest/post_list.py
@@ -129,6 +129,7 @@ class PostList(Directive):
else:
post_list_id = self.options.get('id', 'post_list_' + uuid.uuid4().hex)
+ filtered_timeline = []
posts = []
step = -1 if reverse is None else None
if show_all is None:
@@ -136,16 +137,20 @@ class PostList(Directive):
else:
timeline = [p for p in self.site.timeline if p.use_in_feeds]
- for post in timeline[start:stop:step]:
+ for post in timeline:
if tags:
cont = True
+ tags_lower = [t.lower() for t in post.tags]
for tag in tags:
- if tag in [t.lower() for t in post.tags]:
+ if tag in tags_lower:
cont = False
if cont:
continue
+ filtered_timeline.append(post)
+
+ for post in filtered_timeline[start:stop:step]:
if slugs:
cont = True
for slug in slugs: