diff options
Diffstat (limited to 'nikola/plugins/task')
| -rw-r--r-- | nikola/plugins/task/__init__.py | 25 | ||||
| -rw-r--r-- | nikola/plugins/task/archive.py | 9 | ||||
| -rw-r--r-- | nikola/plugins/task/build_less.py | 13 | ||||
| -rw-r--r-- | nikola/plugins/task/build_sass.py | 15 | ||||
| -rw-r--r-- | nikola/plugins/task/bundles.py | 8 | ||||
| -rw-r--r-- | nikola/plugins/task/copy_assets.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/copy_files.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/galleries.py | 40 | ||||
| -rw-r--r-- | nikola/plugins/task/gzip.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/indexes.py | 15 | ||||
| -rw-r--r-- | nikola/plugins/task/listings.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/localsearch/__init__.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/mustache/__init__.py | 8 | ||||
| -rw-r--r-- | nikola/plugins/task/pages.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/posts.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/redirect.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/rss.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/sitemap/__init__.py | 2 | ||||
| -rw-r--r-- | nikola/plugins/task/sources.py | 4 | ||||
| -rw-r--r-- | nikola/plugins/task/tags.py | 13 |
20 files changed, 125 insertions, 45 deletions
diff --git a/nikola/plugins/task/__init__.py b/nikola/plugins/task/__init__.py index e69de29..6ad8bac 100644 --- a/nikola/plugins/task/__init__.py +++ b/nikola/plugins/task/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +# Copyright © 2012-2014 Roberto Alsina and others. + +# Permission is hereby granted, free of charge, to any +# person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the +# Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the +# Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice +# shall be included in all copies or substantial portions of +# the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/nikola/plugins/task/archive.py b/nikola/plugins/task/archive.py index 3afbea1..a65a63f 100644 --- a/nikola/plugins/task/archive.py +++ b/nikola/plugins/task/archive.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -92,7 +92,8 @@ class Archive(Task): kw['filters'], context, ) - task_cfg = {1: task['uptodate'][0].config, 2: kw} + n = len(post_list) if 'posts' in context else len(months) + task_cfg = {1: task['uptodate'][0].config, 2: kw, 3: n} task['uptodate'] = [config_changed(task_cfg)] task['basename'] = self.name yield task @@ -123,7 +124,7 @@ class Archive(Task): kw['filters'], context, ) - task_cfg = {1: task['uptodate'][0].config, 2: kw} + task_cfg = {1: task['uptodate'][0].config, 2: kw, 3: len(post_list)} task['uptodate'] = [config_changed(task_cfg)] task['basename'] = self.name yield task @@ -151,7 +152,7 @@ class Archive(Task): kw['filters'], context, ) - task_cfg = {1: task['uptodate'][0].config, 2: kw} + task_cfg = {1: task['uptodate'][0].config, 2: kw, 3: len(years)} task['uptodate'] = [config_changed(task_cfg)] task['basename'] = self.name yield task diff --git a/nikola/plugins/task/build_less.py b/nikola/plugins/task/build_less.py index 8889cbe..14a53f9 100644 --- a/nikola/plugins/task/build_less.py +++ b/nikola/plugins/task/build_less.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -29,6 +29,7 @@ from __future__ import unicode_literals import codecs import glob import os +import sys import subprocess from nikola.plugin_categories import Task @@ -41,10 +42,10 @@ class BuildLess(Task): name = "build_less" sources_folder = "less" sources_ext = ".less" - compiler_name = "lessc" def gen_tasks(self): """Generate CSS out of LESS sources.""" + self.compiler_name = self.site.config['LESS_COMPILER'] kw = { 'cache_folder': self.site.config['CACHE_FOLDER'], @@ -79,7 +80,13 @@ class BuildLess(Task): def compile_target(target, dst): utils.makedirs(dst_dir) src = os.path.join(kw['cache_folder'], self.sources_folder, target) - compiled = subprocess.check_output([self.compiler_name, src]) + run_in_shell = sys.platform == 'win32' + try: + compiled = subprocess.check_output([self.compiler_name, src], shell=run_in_shell) + except OSError: + utils.req_missing([self.compiler_name], + 'build LESS files (and use this theme)', + False, False) with open(dst, "wb+") as outf: outf.write(compiled) diff --git a/nikola/plugins/task/build_sass.py b/nikola/plugins/task/build_sass.py index a5d22fb..7575505 100644 --- a/nikola/plugins/task/build_sass.py +++ b/nikola/plugins/task/build_sass.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -29,6 +29,7 @@ from __future__ import unicode_literals import codecs import glob import os +import sys import subprocess from nikola.plugin_categories import Task @@ -41,11 +42,11 @@ class BuildSass(Task): name = "build_sass" sources_folder = "sass" sources_ext = (".sass", ".scss") - compiler_name = "sass" def gen_tasks(self): """Generate CSS out of Sass sources.""" self.logger = utils.get_logger('build_sass', self.site.loghandlers) + self.compiler_name = self.site.config['SASS_COMPILER'] kw = { 'cache_folder': self.site.config['CACHE_FOLDER'], @@ -79,8 +80,14 @@ class BuildSass(Task): def compile_target(target, dst): utils.makedirs(dst_dir) + run_in_shell = sys.platform == 'win32' src = os.path.join(kw['cache_folder'], self.sources_folder, target) - compiled = subprocess.check_output([self.compiler_name, src]) + try: + compiled = subprocess.check_output([self.compiler_name, src], shell=run_in_shell) + except OSError: + utils.req_missing([self.compiler_name], + 'build Sass files (and use this theme)', + False, False) with open(dst, "wb+") as outf: outf.write(compiled) @@ -99,7 +106,7 @@ class BuildSass(Task): if base in seennames: self.logger.error( - 'Duplicate filenames for SASS compiled files: {0} and ' + 'Duplicate filenames for Sass compiled files: {0} and ' '{1} (both compile to {2})'.format( seennames[base], target, base + ".css")) else: diff --git a/nikola/plugins/task/bundles.py b/nikola/plugins/task/bundles.py index 488f96f..b035b97 100644 --- a/nikola/plugins/task/bundles.py +++ b/nikola/plugins/task/bundles.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -44,7 +44,9 @@ class BuildBundles(LateTask): def set_site(self, site): super(BuildBundles, self).set_site(site) - if webassets is None: + if webassets is None and self.site.config['USE_BUNDLES']: + utils.req_missing(['webassets'], 'USE_BUNDLES', optional=True) + utils.LOGGER.warn('Setting USE_BUNDLES to False.') self.site.config['USE_BUNDLES'] = False def gen_tasks(self): @@ -111,6 +113,6 @@ def get_theme_bundles(themes): for line in fd: name, files = line.split('=') files = [f.strip() for f in files.split(',')] - bundles[name.strip()] = files + bundles[name.strip().replace('/', os.sep)] = files break return bundles diff --git a/nikola/plugins/task/copy_assets.py b/nikola/plugins/task/copy_assets.py index f3d85df..21f1f85 100644 --- a/nikola/plugins/task/copy_assets.py +++ b/nikola/plugins/task/copy_assets.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/copy_files.py b/nikola/plugins/task/copy_files.py index 88e89eb..9846ca0 100644 --- a/nikola/plugins/task/copy_files.py +++ b/nikola/plugins/task/copy_files.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py index cf670e0..6977eab 100644 --- a/nikola/plugins/task/galleries.py +++ b/nikola/plugins/task/galleries.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -51,6 +51,7 @@ import PyRSS2Gen as rss from nikola.plugin_categories import Task from nikola import utils from nikola.post import Post +from nikola.utils import req_missing class Galleries(Task): @@ -77,6 +78,9 @@ class Galleries(Task): def gen_tasks(self): """Render image galleries.""" + if Image is None: + req_missing(['pillow'], 'render galleries') + self.logger = utils.get_logger('render_galleries', self.site.loghandlers) self.image_ext_list = ['.jpg', '.png', '.jpeg', '.gif', '.svg', '.bmp', '.tiff'] self.image_ext_list.extend(self.site.config.get('EXTRA_IMAGE_EXTENSIONS', [])) @@ -111,7 +115,7 @@ class Galleries(Task): for gallery in self.gallery_list: # Create subfolder list - folder_list = [x.split(os.sep)[-2] for x in + folder_list = [(x, x.split(os.sep)[-2]) for x in glob.glob(os.path.join(gallery, '*') + os.sep)] # Parse index into a post (with translations) @@ -137,7 +141,7 @@ class Galleries(Task): for task in self.remove_excluded_image(image): yield task - crumbs = utils.get_crumbs(gallery) + crumbs = utils.get_crumbs(gallery, index_folder=self) # Create index.html for each language for lang in self.kw['translations']: @@ -173,9 +177,20 @@ class Galleries(Task): thumbs = ['.thumbnail'.join(os.path.splitext(p)) for p in image_list] thumbs = [os.path.join(self.kw['output_folder'], t) for t in thumbs] + folders = [] + + # Generate friendly gallery names + for path, folder in folder_list: + fpost = self.parse_index(path) + if fpost: + ft = fpost.title(lang) or folder + else: + ft = folder + folders.append((folder, ft)) + ## TODO: in v7 remove images from context, use photo_array context["images"] = list(zip(image_name_list, thumbs, img_titles)) - context["folders"] = folder_list + context["folders"] = folders context["crumbs"] = crumbs context["permalink"] = self.site.link( "gallery", os.path.basename(gallery), lang) @@ -288,8 +303,14 @@ class Galleries(Task): False, self.site.MESSAGES, 'story.tmpl', - self.site.get_compiler(index_path).compile_html + self.site.get_compiler(index_path) ) + # If this did not exist, galleries without a title in the + # index.txt file would be errorneously named `index` + # (warning: galleries titled index and filenamed differently + # may break) + if post.title == 'index': + post.title = os.path.split(gallery)[1] else: post = None return post @@ -460,7 +481,7 @@ class Galleries(Task): os.path.join( self.site.config['OUTPUT_FOLDER'], img)).st_size args = { - 'title': full_title.split('"')[-2], + 'title': full_title.split('"')[-2] if full_title else '', 'link': make_url(img), 'guid': rss.Guid(img, False), 'pubDate': self.image_date(img), @@ -477,7 +498,7 @@ class Galleries(Task): description='', lastBuildDate=datetime.datetime.now(), items=items, - generator='nikola', + generator='Nikola <http://getnikola.com/>', language=lang ) rss_obj.self_url = make_url(permalink) @@ -523,8 +544,9 @@ class Galleries(Task): try: im.thumbnail(size, Image.ANTIALIAS) im.save(dst) - except Exception: - self.logger.warn("Can't thumbnail {0}, using original image as thumbnail".format(src)) + except Exception as e: + self.logger.warn("Can't thumbnail {0}, using original " + "image as thumbnail ({1})".format(src, e)) utils.copy_file(src, dst) else: # Image is small utils.copy_file(src, dst) diff --git a/nikola/plugins/task/gzip.py b/nikola/plugins/task/gzip.py index 738d52c..bcc9637 100644 --- a/nikola/plugins/task/gzip.py +++ b/nikola/plugins/task/gzip.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/indexes.py b/nikola/plugins/task/indexes.py index 0d20422..3f45161 100644 --- a/nikola/plugins/task/indexes.py +++ b/nikola/plugins/task/indexes.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -57,6 +57,7 @@ class Indexes(Task): "hide_untranslated_posts": self.site.config['HIDE_UNTRANSLATED_POSTS'], "indexes_title": self.site.config['INDEXES_TITLE'], "indexes_pages": self.site.config['INDEXES_PAGES'], + "indexes_pages_main": self.site.config['INDEXES_PAGES_MAIN'], "blog_title": self.site.config["BLOG_TITLE"], } @@ -78,12 +79,18 @@ class Indexes(Task): for i, post_list in enumerate(lists): context = {} indexes_title = kw['indexes_title'] or kw['blog_title'] + if kw["indexes_pages_main"]: + ipages_i = i + 1 + ipages_msg = "page %d" + else: + ipages_i = i + ipages_msg = "old posts, page %d" if kw["indexes_pages"]: - indexes_pages = kw["indexes_pages"] % i + indexes_pages = kw["indexes_pages"] % ipages_i else: indexes_pages = " (" + \ - kw["messages"][lang]["old posts page %d"] % i + ")" - if i > 0: + kw["messages"][lang][ipages_msg] % ipages_i + ")" + if i > 0 or kw["indexes_pages_main"]: context["title"] = indexes_title + indexes_pages else: context["title"] = indexes_title diff --git a/nikola/plugins/task/listings.py b/nikola/plugins/task/listings.py index ab62e74..d8ed43b 100644 --- a/nikola/plugins/task/listings.py +++ b/nikola/plugins/task/listings.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/localsearch/__init__.py b/nikola/plugins/task/localsearch/__init__.py index 9162604..c501d80 100644 --- a/nikola/plugins/task/localsearch/__init__.py +++ b/nikola/plugins/task/localsearch/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/mustache/__init__.py b/nikola/plugins/task/mustache/__init__.py index c392e3b..5be98f0 100644 --- a/nikola/plugins/task/mustache/__init__.py +++ b/nikola/plugins/task/mustache/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -31,7 +31,9 @@ import json import os from nikola.plugin_categories import Task -from nikola.utils import config_changed, copy_file, unicode_str, makedirs +from nikola.utils import ( + config_changed, copy_file, LocaleBorg, makedirs, unicode_str, +) class Mustache(Task): @@ -106,7 +108,7 @@ class Mustache(Task): }) # Comments - context = dict(post=post, lang=self.site.current_lang()) + context = dict(post=post, lang=LocaleBorg().current_lang) context.update(self.site.GLOBAL_CONTEXT) data["comment_html"] = self.site.template_system.render_template( 'mustache-comment-form.tmpl', None, context).strip() diff --git a/nikola/plugins/task/pages.py b/nikola/plugins/task/pages.py index eb5b49e..f4c0469 100644 --- a/nikola/plugins/task/pages.py +++ b/nikola/plugins/task/pages.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/posts.py b/nikola/plugins/task/posts.py index 18d61b8..a502b81 100644 --- a/nikola/plugins/task/posts.py +++ b/nikola/plugins/task/posts.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/redirect.py b/nikola/plugins/task/redirect.py index ade878a..6fafd13 100644 --- a/nikola/plugins/task/redirect.py +++ b/nikola/plugins/task/redirect.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/rss.py b/nikola/plugins/task/rss.py index bcca4da..e5f7548 100644 --- a/nikola/plugins/task/rss.py +++ b/nikola/plugins/task/rss.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/sitemap/__init__.py b/nikola/plugins/task/sitemap/__init__.py index f34bc0a..0164000 100644 --- a/nikola/plugins/task/sitemap/__init__.py +++ b/nikola/plugins/task/sitemap/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated diff --git a/nikola/plugins/task/sources.py b/nikola/plugins/task/sources.py index 672f354..2324af2 100644 --- a/nikola/plugins/task/sources.py +++ b/nikola/plugins/task/sources.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -66,7 +66,7 @@ class Sources(Task): if dest_ext == post.source_ext(): continue if lang != kw["default_lang"]: - source_lang = source + '.' + lang + source_lang = utils.get_translation_candidate(self.site.config, source, lang) if os.path.exists(source_lang): source = source_lang if os.path.isfile(source): diff --git a/nikola/plugins/task/tags.py b/nikola/plugins/task/tags.py index 299dca4..a2444ec 100644 --- a/nikola/plugins/task/tags.py +++ b/nikola/plugins/task/tags.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright © 2012-2013 Roberto Alsina and others. +# Copyright © 2012-2014 Roberto Alsina and others. # Permission is hereby granted, free of charge, to any # person obtaining a copy of this software and associated @@ -110,8 +110,14 @@ class RenderTags(Task): # Tag cloud json file tag_cloud_data = {} for tag, posts in self.site.posts_per_tag.items(): + tag_posts = dict(posts=[{'title': post.meta[post.default_lang]['title'], + 'date': post.date.strftime('%m/%d/%Y'), + 'isodate': post.date.isoformat(), + 'url': post.base_path.replace('cache', '')} + for post in reversed(sorted(self.site.timeline, key=lambda post: post.date)) + if tag in post.alltags]) tag_cloud_data[tag] = [len(posts), self.site.link( - 'tag', tag, self.site.config['DEFAULT_LANG'])] + 'tag', tag, self.site.config['DEFAULT_LANG']), tag_posts] output_name = os.path.join(kw['output_folder'], 'assets', 'js', 'tag_cloud_data.json') @@ -124,6 +130,7 @@ class RenderTags(Task): 'basename': str(self.name), 'name': str(output_name) } + task['uptodate'] = [utils.config_changed(tag_cloud_data)] task['targets'] = [output_name] task['actions'] = [(write_tag_data, [tag_cloud_data])] @@ -189,7 +196,7 @@ class RenderTags(Task): return name # FIXME: deduplicate this with render_indexes - template_name = "index.tmpl" + template_name = "tagindex.tmpl" # Split in smaller lists lists = [] while post_list: |
