aboutsummaryrefslogtreecommitdiffstats
path: root/nikola/plugins
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2022-04-20 00:12:09 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2022-04-20 00:12:09 -0400
commit942e313727d1ad886a1024c24fe4a9e8e2e0bb3e (patch)
tree1c4d5d826655cdb812c88563a25410f8b54e41d2 /nikola/plugins
parent8eeed31eb2f86ac982fa4b26f93b15828289c56d (diff)
New upstream version 8.2.0.upstream/8.2.0
Diffstat (limited to 'nikola/plugins')
-rw-r--r--nikola/plugins/command/auto/__init__.py29
-rw-r--r--nikola/plugins/command/import_wordpress.py5
-rw-r--r--nikola/plugins/shortcode/post_list.py2
-rw-r--r--nikola/plugins/task/categories.py6
-rw-r--r--nikola/plugins/task/galleries.py7
-rw-r--r--nikola/plugins/task/listings.py2
-rw-r--r--nikola/plugins/task/tags.py6
-rw-r--r--nikola/plugins/template/jinja.py24
-rw-r--r--nikola/plugins/template/mako.py19
9 files changed, 75 insertions, 25 deletions
diff --git a/nikola/plugins/command/auto/__init__.py b/nikola/plugins/command/auto/__init__.py
index 9de5622..2c6d0e7 100644
--- a/nikola/plugins/command/auto/__init__.py
+++ b/nikola/plugins/command/auto/__init__.py
@@ -37,6 +37,7 @@ import sys
import typing
import webbrowser
+import blinker
import pkg_resources
from nikola.plugin_categories import Command
@@ -122,7 +123,8 @@ class CommandAuto(Command):
'long': 'process',
'default': 0,
'type': int,
- 'help': 'Number of subprocesses (nikola build argument)'
+ 'help': 'Number of subprocesses',
+ 'section': 'Arguments passed to `nikola build`'
},
{
'name': 'parallel-type',
@@ -130,8 +132,25 @@ class CommandAuto(Command):
'long': 'parallel-type',
'default': 'process',
'type': str,
- 'help': "Parallelization mode ('process' or 'thread', nikola build argument)"
+ 'help': "Parallelization mode ('process' or 'thread')",
+ 'section': 'Arguments passed to `nikola build`'
},
+ {
+ 'name': 'db-file',
+ 'long': 'db-file',
+ 'default': '.doit.db',
+ 'type': str,
+ 'help': 'Database file',
+ 'section': 'Arguments passed to `nikola build`'
+ },
+ {
+ 'name': 'backend',
+ 'long': 'backend',
+ 'default': 'dbm',
+ 'type': str,
+ 'help': "Database backend ('dbm', 'json', 'sqlite3')",
+ 'section': 'Arguments passed to `nikola build`'
+ }
]
def _execute(self, options, args):
@@ -149,6 +168,8 @@ class CommandAuto(Command):
elif Observer is None:
req_missing(['watchdog'], 'use the "auto" command')
+ blinker.signal('auto_command_starting').send(self.site)
+
if sys.argv[0].endswith('__main__.py'):
self.nikola_cmd = [sys.executable, '-m', 'nikola', 'build']
else:
@@ -161,6 +182,10 @@ class CommandAuto(Command):
self.nikola_cmd += ['--process={}'.format(options['process']),
'--parallel-type={}'.format(options['parallel-type'])]
+ if options:
+ self.nikola_cmd += ['--db-file={}'.format(options['db-file']),
+ '--backend={}'.format(options['backend'])]
+
port = options and options.get('port')
self.snippet = '''<script>document.write('<script src="http://'
+ (location.host || 'localhost').split(':')[0]
diff --git a/nikola/plugins/command/import_wordpress.py b/nikola/plugins/command/import_wordpress.py
index 06e00a1..f513e1c 100644
--- a/nikola/plugins/command/import_wordpress.py
+++ b/nikola/plugins/command/import_wordpress.py
@@ -582,6 +582,11 @@ to
def add(our_key, wp_key, is_int=False, ignore_zero=False, is_float=False):
if wp_key in image_meta:
value = image_meta[wp_key]
+ if value in ("", b"") and (is_int or is_float):
+ if ignore_zero:
+ return
+ else:
+ dst_meta[our_key] = 0
if is_int:
value = int(value)
if ignore_zero and value == 0:
diff --git a/nikola/plugins/shortcode/post_list.py b/nikola/plugins/shortcode/post_list.py
index 0206cf0..2d8d170 100644
--- a/nikola/plugins/shortcode/post_list.py
+++ b/nikola/plugins/shortcode/post_list.py
@@ -219,7 +219,7 @@ class PostListShortcode(ShortcodePlugin):
posts += [post]
- template_deps = site.template_system.template_deps(template)
+ template_deps = site.template_system.template_deps(template, site.GLOBAL_CONTEXT)
if state:
# Register template as a dependency (Issue #2391)
for d in template_deps:
diff --git a/nikola/plugins/task/categories.py b/nikola/plugins/task/categories.py
index 3c0ea6b..b140101 100644
--- a/nikola/plugins/task/categories.py
+++ b/nikola/plugins/task/categories.py
@@ -186,6 +186,8 @@ link://category_rss/dogs => /categories/dogs.xml""",
"title": self.site.MESSAGES[lang]["Categories"],
"description": self.site.MESSAGES[lang]["Categories"],
"pagekind": ["list", "tags_page"],
+ "category_descriptions": self.site.config['CATEGORY_DESCRIPTIONS'](lang),
+ "category_titles": self.site.config['CATEGORY_TITLES'](lang),
}
kw.update(context)
return context, kw
@@ -209,8 +211,8 @@ link://category_rss/dogs => /categories/dogs.xml""",
subcats = [(child.name, self.site.link(self.classification_name, child.classification_name, lang)) for child in children]
friendly_name = self.get_classification_friendly_name(classification, lang)
context = {
- "title": self.site.config['CATEGORY_TITLES'].get(lang, {}).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),
- "description": self.site.config['CATEGORY_DESCRIPTIONS'].get(lang, {}).get(classification),
+ "title": self.site.config['CATEGORY_TITLES'](lang).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % friendly_name),
+ "description": self.site.config['CATEGORY_DESCRIPTIONS'](lang).get(classification),
"pagekind": ["tag_page", "index" if self.show_list_as_index else "list"],
"tag": friendly_name,
"category": classification,
diff --git a/nikola/plugins/task/galleries.py b/nikola/plugins/task/galleries.py
index 1c53cbd..c9b1915 100644
--- a/nikola/plugins/task/galleries.py
+++ b/nikola/plugins/task/galleries.py
@@ -307,10 +307,13 @@ class Galleries(Task, ImageProcessor):
context['post'] = post
else:
context['post'] = None
+
+ template_dep_context = context.copy()
+ template_dep_context.update(self.site.GLOBAL_CONTEXT)
file_dep = self.site.template_system.template_deps(
- template_name) + image_list + thumbs
+ template_name, template_dep_context) + image_list + thumbs
file_dep_dest = self.site.template_system.template_deps(
- template_name) + dest_img_list + thumbs
+ template_name, template_dep_context) + dest_img_list + thumbs
if post:
file_dep += [post.translated_base_path(l) for l in self.kw['translations']]
file_dep_dest += [post.translated_base_path(l) for l in self.kw['translations']]
diff --git a/nikola/plugins/task/listings.py b/nikola/plugins/task/listings.py
index 5f4fca9..d52ddb2 100644
--- a/nikola/plugins/task/listings.py
+++ b/nikola/plugins/task/listings.py
@@ -179,7 +179,7 @@ class Listings(Task):
yield self.group_task()
- template_deps = self.site.template_system.template_deps('listing.tmpl')
+ template_deps = self.site.template_system.template_deps('listing.tmpl', self.site.GLOBAL_CONTEXT)
for input_folder, output_folder in self.kw['listings_folders'].items():
for root, dirs, files in os.walk(input_folder, followlinks=True):
diff --git a/nikola/plugins/task/tags.py b/nikola/plugins/task/tags.py
index a1a6b77..cc2ced8 100644
--- a/nikola/plugins/task/tags.py
+++ b/nikola/plugins/task/tags.py
@@ -128,6 +128,8 @@ link://tag_rss/cats => /tags/cats.xml""",
"title": self.site.MESSAGES[lang]["Tags"],
"description": self.site.MESSAGES[lang]["Tags"],
"pagekind": ["list", "tags_page"],
+ "tag_descriptions": self.site.config['TAG_DESCRIPTIONS'](lang),
+ "tag_titles": self.site.config['TAG_TITLES'](lang),
}
kw.update(context)
return context, kw
@@ -143,8 +145,8 @@ link://tag_rss/cats => /tags/cats.xml""",
"tag_titles": self.site.config['TAG_TITLES'],
}
context = {
- "title": self.site.config['TAG_TITLES'].get(lang, {}).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % classification),
- "description": self.site.config['TAG_DESCRIPTIONS'].get(lang, {}).get(classification),
+ "title": self.site.config['TAG_TITLES'](lang).get(classification, self.site.MESSAGES[lang]["Posts about %s"] % classification),
+ "description": self.site.config['TAG_DESCRIPTIONS'](lang).get(classification),
"pagekind": ["tag_page", "index" if self.show_list_as_index else "list"],
"tag": classification,
}
diff --git a/nikola/plugins/template/jinja.py b/nikola/plugins/template/jinja.py
index 845f4d5..aec6063 100644
--- a/nikola/plugins/template/jinja.py
+++ b/nikola/plugins/template/jinja.py
@@ -31,10 +31,11 @@ import json
import os
from nikola.plugin_categories import TemplateSystem
-from nikola.utils import makedirs, req_missing, sort_posts, _smartjoin_filter
+from nikola.utils import makedirs, req_missing, slugify, sort_posts, _smartjoin_filter
try:
import jinja2
+ import jinja2.nodes
from jinja2 import meta
except ImportError:
jinja2 = None
@@ -66,6 +67,7 @@ class JinjaTemplates(TemplateSystem):
self.lookup.filters['tojson'] = json.dumps
self.lookup.filters['sort_posts'] = sort_posts
self.lookup.filters['smartjoin'] = _smartjoin_filter
+ self.lookup.filters['slugify'] = slugify
self.lookup.globals['enumerate'] = enumerate
self.lookup.globals['isinstance'] = isinstance
self.lookup.globals['tuple'] = tuple
@@ -104,29 +106,35 @@ class JinjaTemplates(TemplateSystem):
"""Render template to a string using context."""
return self.lookup.from_string(template).render(**context)
- def get_string_deps(self, text):
+ def get_string_deps(self, text, context=None):
"""Find dependencies for a template string."""
deps = set([])
ast = self.lookup.parse(text)
- dep_names = [d for d in meta.find_referenced_templates(ast) if d]
+ simple_dep_names = [d for d in meta.find_referenced_templates(ast) if d]
+ formatted_dep_names = [
+ imp.template.left.value % (context[imp.template.right.name],)
+ for imp in ast.find_all(jinja2.nodes.Import)
+ if isinstance(imp.template, jinja2.nodes.Mod)
+ ]
+ dep_names = simple_dep_names + formatted_dep_names
for dep_name in dep_names:
filename = self.lookup.loader.get_source(self.lookup, dep_name)[1]
- sub_deps = [filename] + self.get_deps(filename)
+ sub_deps = [filename] + self.get_deps(filename, context)
self.dependency_cache[dep_name] = sub_deps
deps |= set(sub_deps)
return list(deps)
- def get_deps(self, filename):
+ def get_deps(self, filename, context=None):
"""Return paths to dependencies for the template loaded from filename."""
with io.open(filename, 'r', encoding='utf-8-sig') as fd:
text = fd.read()
- return self.get_string_deps(text)
+ return self.get_string_deps(text, context)
- def template_deps(self, template_name):
+ def template_deps(self, template_name, context=None):
"""Generate list of dependencies for a template."""
if self.dependency_cache.get(template_name) is None:
filename = self.lookup.loader.get_source(self.lookup, template_name)[1]
- self.dependency_cache[template_name] = [filename] + self.get_deps(filename)
+ self.dependency_cache[template_name] = [filename] + self.get_deps(filename, context)
return self.dependency_cache[template_name]
def get_template_path(self, template_name):
diff --git a/nikola/plugins/template/mako.py b/nikola/plugins/template/mako.py
index 8066b96..8197518 100644
--- a/nikola/plugins/template/mako.py
+++ b/nikola/plugins/template/mako.py
@@ -28,6 +28,7 @@
import io
import os
+import re
import shutil
from mako import exceptions, util, lexer, parsetree
@@ -52,7 +53,7 @@ class MakoTemplates(TemplateSystem):
directories = []
cache_dir = None
- def get_string_deps(self, text, filename=None):
+ def get_string_deps(self, text, context=None, *, filename=None):
"""Find dependencies for a template string."""
lex = lexer.Lexer(text=text, filename=filename, input_encoding='utf-8')
lex.parse()
@@ -61,7 +62,11 @@ class MakoTemplates(TemplateSystem):
for n in lex.template.nodes:
keyword = getattr(n, 'keyword', None)
if keyword in ["inherit", "namespace"] or isinstance(n, parsetree.IncludeTag):
- deps.append(n.attributes['file'])
+ filename = n.attributes["file"]
+ if '${' in filename:
+ # Support for comment helper inclusions
+ filename = re.sub(r'''\${context\[['"](.*?)['"]]}''', lambda m: context[m.group(1)], filename)
+ deps.append(filename)
# Some templates will include "foo.tmpl" and we need paths, so normalize them
# using the template lookup
for i, d in enumerate(deps):
@@ -73,10 +78,10 @@ class MakoTemplates(TemplateSystem):
d, filename)
return deps
- def get_deps(self, filename):
+ def get_deps(self, filename, context=None):
"""Get paths to dependencies for a template."""
text = util.read_file(filename)
- return self.get_string_deps(text, filename)
+ return self.get_string_deps(text, context, filename=filename)
def set_directories(self, directories, cache_folder):
"""Create a new template lookup with set directories."""
@@ -122,17 +127,17 @@ class MakoTemplates(TemplateSystem):
context.update(self.filters)
return Template(template, lookup=self.lookup).render(**context)
- def template_deps(self, template_name):
+ def template_deps(self, template_name, context=None):
"""Generate list of dependencies for a template."""
# We can cache here because dependencies should
# not change between runs
if self.cache.get(template_name, None) is None:
template = self.lookup.get_template(template_name)
- dep_filenames = self.get_deps(template.filename)
+ dep_filenames = self.get_deps(template.filename, context)
deps = [template.filename]
for fname in dep_filenames:
# yes, it uses forward slashes on Windows
- deps += self.template_deps(fname.split('/')[-1])
+ deps += self.template_deps(fname.split('/')[-1], context)
self.cache[template_name] = list(set(deps))
return self.cache[template_name]