From 5ec02211214350ee558fd9f6bb052264fd24f75e Mon Sep 17 00:00:00 2001 From: Agustin Henze Date: Tue, 21 Oct 2014 10:33:15 -0300 Subject: Imported Upstream version 7.1.0 --- nikola/plugins/task/bundles.py | 10 +++++++--- nikola/plugins/task/copy_assets.py | 8 +++++--- nikola/plugins/task/copy_files.py | 2 +- nikola/plugins/task/galleries.py | 16 +++++++++++---- nikola/plugins/task/indexes.py | 35 +++++++++++++++++++++------------ nikola/plugins/task/listings.py | 5 ++++- nikola/plugins/task/redirect.py | 5 +++-- nikola/plugins/task/robots.py | 10 +++++----- nikola/plugins/task/sitemap/__init__.py | 11 ++++++----- nikola/plugins/task/sources.py | 8 ++++---- nikola/plugins/task/tags.py | 11 +++++------ 11 files changed, 74 insertions(+), 47 deletions(-) (limited to 'nikola/plugins/task') diff --git a/nikola/plugins/task/bundles.py b/nikola/plugins/task/bundles.py index 7437a9d..fca6924 100644 --- a/nikola/plugins/task/bundles.py +++ b/nikola/plugins/task/bundles.py @@ -122,8 +122,12 @@ def get_theme_bundles(themes): if os.path.isfile(bundles_path): with open(bundles_path) as fd: for line in fd: - name, files = line.split('=') - files = [f.strip() for f in files.split(',')] - bundles[name.strip().replace('/', os.sep)] = files + try: + name, files = line.split('=') + files = [f.strip() for f in files.split(',')] + bundles[name.strip().replace('/', os.sep)] = files + except ValueError: + # for empty lines + pass break return bundles diff --git a/nikola/plugins/task/copy_assets.py b/nikola/plugins/task/copy_assets.py index 4801347..29aa083 100644 --- a/nikola/plugins/task/copy_assets.py +++ b/nikola/plugins/task/copy_assets.py @@ -24,7 +24,9 @@ # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -import codecs +from __future__ import unicode_literals + +import io import os from nikola.plugin_categories import Task @@ -82,13 +84,13 @@ class CopyAssets(Task): from pygments.formatters import get_formatter_by_name formatter = get_formatter_by_name('html', style=kw["code_color_scheme"]) utils.makedirs(os.path.dirname(code_css_path)) - with codecs.open(code_css_path, 'wb+', 'utf8') as outf: + with io.open(code_css_path, 'w+', encoding='utf8') as outf: outf.write(kw["code.css_head"]) outf.write(formatter.get_style_defs(kw["code.css_selectors"])) outf.write(kw["code.css_close"]) if os.path.exists(code_css_path): - with codecs.open(code_css_path, 'r', 'utf-8') as fh: + with io.open(code_css_path, 'r', encoding='utf-8') as fh: testcontents = fh.read(len(kw["code.css_head"])) == kw["code.css_head"] else: testcontents = False diff --git a/nikola/plugins/task/copy_files.py b/nikola/plugins/task/copy_files.py index 9846ca0..1d31756 100644 --- a/nikola/plugins/task/copy_files.py +++ b/nikola/plugins/task/copy_files.py @@ -52,4 +52,4 @@ class CopyFiles(Task): for task in utils.copy_tree(src, real_dst, link_cutoff=dst): task['basename'] = self.name task['uptodate'] = [utils.config_changed(kw)] - yield utils.apply_filters(task, filters) + yield utils.apply_filters(task, filters, skip_ext=['.html']) diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py index 366374b..f835444 100644 --- a/nikola/plugins/task/galleries.py +++ b/nikola/plugins/task/galleries.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 datetime import glob import json @@ -55,6 +55,8 @@ from nikola import utils from nikola.post import Post from nikola.utils import req_missing +_image_size_cache = {} + class Galleries(Task): """Render image galleries.""" @@ -153,6 +155,9 @@ class Galleries(Task): # Create index.html for each language for lang in self.kw['translations']: + # save navigation links as dependencies + self.kw['navigation_links|{0}'.format(lang)] = self.kw['global_context']['navigation_links'](lang) + dst = os.path.join( self.kw['output_folder'], self.site.path( @@ -460,8 +465,11 @@ class Galleries(Task): photo_array = [] for img, thumb, title in zip(img_list, thumbs, img_titles): - im = Image.open(thumb) - w, h = im.size + w, h = _image_size_cache.get(thumb, (None, None)) + if w is None: + im = Image.open(thumb) + w, h = im.size + _image_size_cache[thumb] = w, h # Thumbs are files in output, we need URLs photo_array.append({ 'url': url_from_path(img), @@ -515,7 +523,7 @@ class Galleries(Task): rss_obj.rss_attrs["xmlns:dc"] = "http://purl.org/dc/elements/1.1/" dst_dir = os.path.dirname(output_path) utils.makedirs(dst_dir) - with codecs.open(output_path, "wb+", "utf-8") as rss_file: + 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') diff --git a/nikola/plugins/task/indexes.py b/nikola/plugins/task/indexes.py index 386cc18..0a2cd02 100644 --- a/nikola/plugins/task/indexes.py +++ b/nikola/plugins/task/indexes.py @@ -147,20 +147,29 @@ class Indexes(Task): groups[dirname].append(p) for dirname, post_list in groups.items(): context = {} - context["items"] = [ - (post.title(lang), post.permalink(lang)) - for post in post_list - ] + context["items"] = [] + should_render = True output_name = os.path.join(kw['output_folder'], dirname, kw['index_file']) - task = self.site.generic_post_list_renderer(lang, post_list, - output_name, - template_name, - kw['filters'], - context) - task_cfg = {1: task['uptodate'][0].config, 2: kw} - task['uptodate'] = [config_changed(task_cfg)] - task['basename'] = self.name - yield task + short_destination = os.path.join(dirname, kw['index_file']) + for post in post_list: + # If there is an index.html pending to be created from + # a story, do not generate the STORY_INDEX + if post.destination_path(lang) == short_destination: + should_render = False + else: + context["items"].append((post.title(lang), + post.permalink(lang))) + + if should_render: + task = self.site.generic_post_list_renderer(lang, post_list, + output_name, + template_name, + kw['filters'], + context) + task_cfg = {1: task['uptodate'][0].config, 2: kw} + task['uptodate'] = [config_changed(task_cfg)] + task['basename'] = self.name + yield task def index_path(self, name, lang): if name not in [None, 0]: diff --git a/nikola/plugins/task/listings.py b/nikola/plugins/task/listings.py index a0fe974..79f6763 100644 --- a/nikola/plugins/task/listings.py +++ b/nikola/plugins/task/listings.py @@ -73,7 +73,7 @@ class Listings(Task): code = highlight(fd.read(), lexer, HtmlFormatter(cssclass='code', linenos="table", nowrap=False, - lineanchors=utils.slugify(in_name), + lineanchors=utils.slugify(in_name, force=True), anchorlinenos=True)) # the pygments highlighter uses
                 # for code.  We switch it to reST's 
.
@@ -124,6 +124,9 @@ class Listings(Task):
             for k in self.site._GLOBAL_CONTEXT_TRANSLATABLE:
                 uptodate[k] = self.site.GLOBAL_CONTEXT[k](kw['default_lang'])
 
+            # save navigation links as dependencies
+            uptodate['navigation_links'] = uptodate['c']['navigation_links'](kw['default_lang'])
+
             uptodate2 = uptodate.copy()
             uptodate2['f'] = files
             uptodate2['d'] = dirs
diff --git a/nikola/plugins/task/redirect.py b/nikola/plugins/task/redirect.py
index eccc0ab..e1134bf 100644
--- a/nikola/plugins/task/redirect.py
+++ b/nikola/plugins/task/redirect.py
@@ -24,7 +24,7 @@
 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-import codecs
+import io
 import os
 
 from nikola.plugin_categories import Task
@@ -60,7 +60,8 @@ class Redirect(Task):
 
 def create_redirect(src, dst):
     utils.makedirs(os.path.dirname(src))
-    with codecs.open(src, "wb+", "utf8") as fd:
+    with io.open(src, "w+", encoding="utf8") as fd:
         fd.write('Redirecting...'
+                 ''
                  '

Page moved here

'.format(dst)) diff --git a/nikola/plugins/task/robots.py b/nikola/plugins/task/robots.py index 9944c0d..b229d37 100644 --- a/nikola/plugins/task/robots.py +++ b/nikola/plugins/task/robots.py @@ -25,7 +25,7 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import print_function, absolute_import, unicode_literals -import codecs +import io import os try: from urlparse import urljoin, urlparse @@ -51,14 +51,14 @@ class RobotsFile(LateTask): "robots_exclusions": self.site.config["ROBOTS_EXCLUSIONS"] } - if kw["site_url"] != urljoin(kw["site_url"], "/"): - utils.LOGGER.warn('robots.txt not ending up in server root, will be useless') - sitemapindex_url = urljoin(kw["base_url"], "sitemapindex.xml") robots_path = os.path.join(kw['output_folder'], "robots.txt") def write_robots(): - with codecs.open(robots_path, 'wb+', 'utf8') as outf: + if kw["site_url"] != urljoin(kw["site_url"], "/"): + utils.LOGGER.warn('robots.txt not ending up in server root, will be useless') + + with io.open(robots_path, 'w+', encoding='utf8') as outf: outf.write("Sitemap: {0}\n\n".format(sitemapindex_url)) if kw["robots_exclusions"]: outf.write("User-Agent: *\n") diff --git a/nikola/plugins/task/sitemap/__init__.py b/nikola/plugins/task/sitemap/__init__.py index beac6cb..943e9b2 100644 --- a/nikola/plugins/task/sitemap/__init__.py +++ b/nikola/plugins/task/sitemap/__init__.py @@ -25,7 +25,7 @@ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. from __future__ import print_function, absolute_import, unicode_literals -import codecs +import io import datetime import os try: @@ -150,7 +150,7 @@ class Sitemap(LateTask): continue if path.endswith('.html') or path.endswith('.htm'): try: - if u'