From 35bbda45071973f9de54999f0256c53e7affb4e4 Mon Sep 17 00:00:00 2001 From: Romain Porte Date: Fri, 5 Jun 2020 19:48:33 +0200 Subject: [PATCH] templates/tasks.py: livereload: automatically open browser When the livereload target is invoked, a web brower will be automatically opened pointing to the locally-served website. In case of no web browser can be found by the module, the open call returns False but no exception is raised. This means that it is still possible to call livereload on a remote machine and access it without any error being triggered. Signed-off-by: Romain Porte --- pelican/tools/templates/tasks.py.jinja2 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pelican/tools/templates/tasks.py.jinja2 b/pelican/tools/templates/tasks.py.jinja2 index ff8e526e..38278876 100644 --- a/pelican/tools/templates/tasks.py.jinja2 +++ b/pelican/tools/templates/tasks.py.jinja2 @@ -13,6 +13,7 @@ from pelican import main as pelican_main from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer from pelican.settings import DEFAULT_CONFIG, get_settings_from_file +OPEN_BROWSER_ON_SERVE = True SETTINGS_FILE_BASE = 'pelicanconf.py' SETTINGS = {} SETTINGS.update(DEFAULT_CONFIG) @@ -124,6 +125,12 @@ def livereload(c): for glob in watched_globs: server.watch(glob, cached_build) + + if OPEN_BROWSER_ON_SERVE: + # Open site in default browser + import webbrowser + webbrowser.open("http://{host}:{port}".format(**CONFIG)) + server.serve(host=CONFIG['host'], port=CONFIG['port'], root=CONFIG['deploy_path']) {% if cloudfiles %}