diff options
author | Justin Mayer <entroP@gmail.com> | 2021-02-09 21:28:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 21:28:54 +0100 |
commit | 7a26f509dfc76d7fcd4d2d28eac02aae0a8fbd17 (patch) | |
tree | 1f8f1276ec0db758aeba7c4ea6395773b3d754c7 | |
parent | 8bb5f1b786b6f2b22d1dc4501796d6df9a658a05 (diff) | |
parent | f846191edddabb6996c4a15490439f3b2ade1249 (diff) | |
download | pelican-7a26f509dfc76d7fcd4d2d28eac02aae0a8fbd17.tar.gz |
Merge pull request #2847 from mirekdlugosz/livereload-cleanup
livereload task improvements
-rw-r--r-- | pelican/tools/templates/tasks.py.jinja2 | 32 |
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 %} |