Last active
November 8, 2016 17:32
-
-
Save saschwarz/8eff30f5ea5d468f0b86bd0bb149a186 to your computer and use it in GitHub Desktop.
An enhanced version of pelican-livereload.py from https://merlijn.vandeen.nl/2015/pelican-livereload.html which watches content and theme directories and runs on either the specified SITEURL's host/port or the default liver eload host/port.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
from urllib.parse import urlparse | |
except ImportError: | |
from urlparse import urlparse | |
from livereload import Server, shell | |
from pelican import Pelican | |
from pelican.settings import read_settings | |
settings = read_settings('pelicanconf.py') | |
p = Pelican(settings) | |
def compile(): | |
try: | |
p.run() | |
except SystemExit as e: | |
pass | |
server = Server() | |
server.watch(p.settings['PATH'], compile) | |
server.watch(p.settings['THEME'], compile) | |
server.watch('./pelicanconf.py', compile) | |
host_port = p.settings.get('SITEURL') or 'http://localhost:5500' | |
details = urlparse(host_port) | |
host, port = details[1].split(':') | |
server.serve(host=host, port=port, root=settings['OUTPUT_PATH']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment