diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-02-27 20:29:08 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-02-27 20:29:08 +0100 |
| commit | 67896d3cdde877de940a282bebacd10ca1c56499 (patch) | |
| tree | c523b7b5443c1eb0aa061c2394f8440dba567620 /megapixels/commands/site | |
| parent | c8e7a10be948c2405d46d8c3caf4a8c6675eee29 (diff) | |
site watcher / loader
Diffstat (limited to 'megapixels/commands/site')
| -rw-r--r-- | megapixels/commands/site/watch.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/megapixels/commands/site/watch.py b/megapixels/commands/site/watch.py new file mode 100644 index 00000000..7fd3ba7c --- /dev/null +++ b/megapixels/commands/site/watch.py @@ -0,0 +1,44 @@ +""" +Watch for changes in the static site and build them +""" + +import click +import time +from watchdog.observers import Observer +from watchdog.events import PatternMatchingEventHandler + +import app.settings.app_cfg as cfg +from app.site.builder import build_site, build_file + +class SiteBuilder(PatternMatchingEventHandler): + """ + Handler for filesystem changes to the content path + """ + patterns = ["*.md"] + + def on_modified(self, event): + print(event.src_path, event.event_type) + build_file(event.src_path) + + def on_created(self, event): + print(event.src_path, event.event_type) + build_file(event.src_path) + +@click.command() +@click.pass_context +def cli(ctx): + """ + Run the observer and start watching for changes + """ + print("{} is now being watched for changes.".format(cfg.DIR_SITE_CONTENT)) + observer = Observer() + observer.schedule(SiteBuilder(), path=cfg.DIR_SITE_CONTENT, recursive=True) + observer.start() + + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + observer.stop() + + observer.join() |
