Skip to content

Instantly share code, notes, and snippets.

@saschwarz
Last active November 8, 2016 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saschwarz/8eff30f5ea5d468f0b86bd0bb149a186 to your computer and use it in GitHub Desktop.
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.
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