mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Add livereload invoke task. Fixes #1326
Adds a `livereload` invoke task that builds the project and reloads the browser window when content files are updated. Usage: ```console $ invoke livereload [I 190202 16:28:30 server:298] Serving on http://127.0.0.1:5500 [I 190202 16:28:30 handlers:59] Start watching changes [I 190202 16:28:30 handlers:61] Start detecting changes [I 190202 16:28:32 handlers:132] Browser Connected: http://127.0.0.1:5500/ ``` See: https://livereload.readthedocs.io/en/latest/
This commit is contained in:
parent
2e82a53cdf
commit
28383a6355
2 changed files with 21 additions and 1 deletions
|
|
@ -7,7 +7,14 @@ import datetime
|
||||||
|
|
||||||
from invoke import task
|
from invoke import task
|
||||||
from invoke.util import cd
|
from invoke.util import cd
|
||||||
|
from livereload import Server
|
||||||
from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
|
from pelican.server import ComplexHTTPRequestHandler, RootedHTTPServer
|
||||||
|
from pelican.settings import DEFAULT_CONFIG, get_settings_from_file
|
||||||
|
|
||||||
|
SETTINGS = {}
|
||||||
|
SETTINGS.update(DEFAULT_CONFIG)
|
||||||
|
LOCAL_SETTINGS = get_settings_from_file('pelicanconf.py')
|
||||||
|
SETTINGS.update(LOCAL_SETTINGS)
|
||||||
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
# Local path configuration (can be absolute or relative to tasks.py)
|
# Local path configuration (can be absolute or relative to tasks.py)
|
||||||
|
|
@ -80,6 +87,19 @@ def preview(c):
|
||||||
"""Build production version of site"""
|
"""Build production version of site"""
|
||||||
c.run('pelican -s publishconf.py')
|
c.run('pelican -s publishconf.py')
|
||||||
|
|
||||||
|
@task
|
||||||
|
def livereload(c):
|
||||||
|
"""Automatically reload browser tab upon file modification."""
|
||||||
|
build(c)
|
||||||
|
server = Server()
|
||||||
|
deploy_path = CONFIG['deploy_path']
|
||||||
|
content_path = SETTINGS['PATH']
|
||||||
|
content_file_extensions = ['.md', '.rst']
|
||||||
|
for file_extension in content_file_extensions:
|
||||||
|
content_blob = '{0}/**/*{1}'.format(content_path, file_extension)
|
||||||
|
server.watch(content_blob, lambda: build(c))
|
||||||
|
server.serve(root=deploy_path)
|
||||||
|
|
||||||
{% if cloudfiles %}
|
{% if cloudfiles %}
|
||||||
@task
|
@task
|
||||||
def cf_upload(c):
|
def cf_upload(c):
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -8,7 +8,7 @@ from setuptools import setup
|
||||||
|
|
||||||
requires = ['feedgenerator >= 1.9', 'jinja2 >= 2.7', 'pygments', 'docutils',
|
requires = ['feedgenerator >= 1.9', 'jinja2 >= 2.7', 'pygments', 'docutils',
|
||||||
'pytz >= 0a', 'blinker', 'unidecode', 'six >= 1.4',
|
'pytz >= 0a', 'blinker', 'unidecode', 'six >= 1.4',
|
||||||
'python-dateutil']
|
'python-dateutil', 'livereload']
|
||||||
|
|
||||||
entry_points = {
|
entry_points = {
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue