Merge pull request #2847 from mirekdlugosz/livereload-cleanup

livereload task improvements
This commit is contained in:
Justin Mayer 2021-02-09 21:28:54 +01:00 committed by GitHub
commit 7a26f509df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -99,23 +99,31 @@ def preview(c):
def livereload(c): def livereload(c):
"""Automatically reload browser tab upon file modification.""" """Automatically reload browser tab upon file modification."""
from livereload import Server 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() server = Server()
# Watch the base settings file theme_path = SETTINGS['THEME']
server.watch(CONFIG['settings_base'], lambda: build(c)) watched_globs = [
# Watch content source files CONFIG['settings_base'],
'{}/templates/**/*.html'.format(theme_path),
]
content_file_extensions = ['.md', '.rst'] content_file_extensions = ['.md', '.rst']
for extension in content_file_extensions: for extension in content_file_extensions:
content_blob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension) content_glob = '{0}/**/*{1}'.format(SETTINGS['PATH'], extension)
server.watch(content_blob, lambda: build(c)) watched_globs.append(content_glob)
# Watch the theme's templates and static assets
theme_path = SETTINGS['THEME']
server.watch('{}/templates/*.html'.format(theme_path), lambda: build(c))
static_file_extensions = ['.css', '.js'] static_file_extensions = ['.css', '.js']
for extension in static_file_extensions: for extension in static_file_extensions:
static_file = '{0}/static/**/*{1}'.format(theme_path, extension) static_file_glob = '{0}/static/**/*{1}'.format(theme_path, extension)
server.watch(static_file, lambda: build(c)) watched_globs.append(static_file_glob)
# Serve output path on configured host and port
for glob in watched_globs:
server.watch(glob, cached_build)
server.serve(host=CONFIG['host'], port=CONFIG['port'], root=CONFIG['deploy_path']) server.serve(host=CONFIG['host'], port=CONFIG['port'], root=CONFIG['deploy_path'])
{% if cloudfiles %} {% if cloudfiles %}