summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Długosz <mirek@mirekdlugosz.com>2021-02-08 22:16:25 +0100
committerMirek Długosz <mirek@mirekdlugosz.com>2021-02-09 20:49:48 +0100
commitf846191edddabb6996c4a15490439f3b2ade1249 (patch)
tree1f8f1276ec0db758aeba7c4ea6395773b3d754c7
parent8bb5f1b786b6f2b22d1dc4501796d6df9a658a05 (diff)
downloadpelican-f846191edddabb6996c4a15490439f3b2ade1249.tar.gz
livereload task improvements
- use custom build command, with caching turned on - this reduces site build time by around 40% on my testing machines - collect all glob patterns in a list and then call `server.watch` on each item - this allows to have single place where callback function must be specified - use '**/*.html' as glob in template, to track changes in subdirectories
-rw-r--r--pelican/tools/templates/tasks.py.jinja232
1 files changed, 20 insertions, 12 deletions
diff --git a/pelican/tools/templates/tasks.py.jinja2 b/pelican/tools/templates/tasks.py.jinja2
index b65f01d2..ff8e526e 100644
--- a/pelican/tools/templates/tasks.py.jinja2
+++ b/pelican/tools/templates/tasks.py.jinja2
@@ -99,23 +99,31 @@ def preview(c):
def livereload(c):
"""Automatically reload browser tab upon file modification."""
from livereload import Server
- build(c)
+
+ def cached_build():
+ cmd = '-s {settings_base} -e CACHE_CONTENT=True LOAD_CONTENT_CACHE=True'
+ pelican_run(cmd.format(**CONFIG))
+
+ cached_build()
server = Server()
- # Watch the base settings file
- server.watch(CONFIG['settings_base'], lambda: build(c))
- # Watch content source files
+ theme_path = SETTINGS['THEME']
+ watched_globs = [
+ CONFIG['settings_base'],
+ '{}/templates/**/*.html'.format(theme_path),
+ ]
+
content_file_extensions = ['.md', '.rst']
for extension in content_file_extensions:
- content_blob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
- server.watch(content_blob, lambda: build(c))
- # Watch the theme's templates and static assets
- theme_path = SETTINGS['THEME']
- server.watch('{}/templates/*.html'.format(theme_path), lambda: build(c))
+ content_glob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
+ watched_globs.append(content_glob)
+
static_file_extensions = ['.css', '.js']
for extension in static_file_extensions:
- static_file = '{0}/static/**/*{1}'.format(theme_path, extension)
- server.watch(static_file, lambda: build(c))
- # Serve output path on configured host and port
+ static_file_glob = '{0}/static/**/*{1}'.format(theme_path, extension)
+ watched_globs.append(static_file_glob)
+
+ for glob in watched_globs:
+ server.watch(glob, cached_build)
server.serve(host=CONFIG['host'], port=CONFIG['port'], root=CONFIG['deploy_path'])
{% if cloudfiles %}