aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins/task
diff options
context:
space:
mode:
Diffstat (limited to 'nikola/plugins/task')
-rw-r--r--nikola/plugins/task/bundles.py10
-rw-r--r--nikola/plugins/task/copy_assets.py8
-rw-r--r--nikola/plugins/task/copy_files.py2
-rw-r--r--nikola/plugins/task/galleries.py16
-rw-r--r--nikola/plugins/task/indexes.py35
-rw-r--r--nikola/plugins/task/listings.py5
-rw-r--r--nikola/plugins/task/redirect.py5
-rw-r--r--nikola/plugins/task/robots.py10
-rw-r--r--nikola/plugins/task/sitemap/__init__.py11
-rw-r--r--nikola/plugins/task/sources.py8
-rw-r--r--nikola/plugins/task/tags.py11
11 files changed, 74 insertions, 47 deletions
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 <div class="codehilite"><pre>
# for code. We switch it to reST's <pre class="code">.
@@ -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('<!DOCTYPE html><head><title>Redirecting...</title>'
+ '<meta name="robots" content="noindex">'
'<meta http-equiv="refresh" content="0; '
'url={0}"></head><body><p>Page moved <a href="{0}">here</a></p></body>'.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'<!doctype html' not in codecs.open(real_path, 'r', 'utf8').read(1024).lower():
+ if u'<!doctype html' not in io.open(real_path, 'r', encoding='utf8').read(1024).lower():
# ignores "html" files without doctype
# alexa-verify, google-site-verification, etc.
continue
@@ -160,7 +160,8 @@ class Sitemap(LateTask):
continue
""" put RSS in sitemapindex[] instead of in urlset[], sitemap_path is included after it is generated """
if path.endswith('.xml') or path.endswith('.rss'):
- if u'<rss' in codecs.open(real_path, 'r', 'utf8').read(512) or u'<urlset'and path != sitemap_path:
+ filehead = io.open(real_path, 'r', encoding='utf8').read(512)
+ if u'<rss' in filehead or (u'<urlset' in filehead and path != sitemap_path):
path = path.replace(os.sep, '/')
lastmod = self.get_lastmod(real_path)
loc = urljoin(base_url, base_path + path)
@@ -187,7 +188,7 @@ class Sitemap(LateTask):
def write_sitemap():
# Have to rescan, because files may have been added between
# task dep scanning and task execution
- with codecs.open(sitemap_path, 'wb+', 'utf8') as outf:
+ with io.open(sitemap_path, 'w+', encoding='utf8') as outf:
outf.write(urlset_header)
for k in sorted(urlset.keys()):
outf.write(urlset[k])
@@ -196,7 +197,7 @@ class Sitemap(LateTask):
sitemapindex[sitemap_url] = sitemap_format.format(sitemap_url, self.get_lastmod(sitemap_path))
def write_sitemapindex():
- with codecs.open(sitemapindex_path, 'wb+', 'utf8') as outf:
+ with io.open(sitemapindex_path, 'w+', encoding='utf8') as outf:
outf.write(sitemapindex_header)
for k in sorted(sitemapindex.keys()):
outf.write(sitemapindex[k])
diff --git a/nikola/plugins/task/sources.py b/nikola/plugins/task/sources.py
index 2324af2..4c669c2 100644
--- a/nikola/plugins/task/sources.py
+++ b/nikola/plugins/task/sources.py
@@ -60,11 +60,11 @@ class Sources(Task):
continue
output_name = os.path.join(
kw['output_folder'], post.destination_path(
- lang, post.source_ext()))
- source = post.source_path
- dest_ext = self.site.get_compiler(post.source_path).extension()
- if dest_ext == post.source_ext():
+ lang, post.source_ext(True)))
+ # do not publish PHP sources
+ if post.source_ext(True) == post.compiler.extension():
continue
+ source = post.source_path
if lang != kw["default_lang"]:
source_lang = utils.get_translation_candidate(self.site.config, source, lang)
if os.path.exists(source_lang):
diff --git a/nikola/plugins/task/tags.py b/nikola/plugins/task/tags.py
index f7f3579..8d43f13 100644
--- a/nikola/plugins/task/tags.py
+++ b/nikola/plugins/task/tags.py
@@ -25,7 +25,6 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from __future__ import unicode_literals
-import codecs
import json
import os
try:
@@ -124,8 +123,8 @@ class RenderTags(Task):
def write_tag_data(data):
utils.makedirs(os.path.dirname(output_name))
- with codecs.open(output_name, 'wb+', 'utf8') as fd:
- fd.write(json.dumps(data))
+ with open(output_name, 'w+') as fd:
+ json.dump(data, fd)
task = {
'basename': str(self.name),
@@ -169,7 +168,7 @@ class RenderTags(Task):
else:
context["cat_items"] = None
context["permalink"] = self.site.link("tag_index", None, lang)
- context["description"] = None
+ context["description"] = context["title"]
task = self.site.generic_post_list_renderer(
lang,
[],
@@ -231,7 +230,7 @@ class RenderTags(Task):
page_name(tag, i + 1, lang))
context["permalink"] = self.site.link(kind, tag, lang)
context["tag"] = tag
- context["description"] = None
+ context["description"] = context["title"]
task = self.site.generic_post_list_renderer(
lang,
post_list,
@@ -259,7 +258,7 @@ class RenderTags(Task):
context["permalink"] = self.site.link(kind, tag, lang)
context["tag"] = tag
context["kind"] = kind
- context["description"] = None
+ context["description"] = context["title"]
task = self.site.generic_post_list_renderer(
lang,
post_list,