diff options
Diffstat (limited to 'megapixels/commands/site/watch.py')
| -rw-r--r-- | megapixels/commands/site/watch.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/megapixels/commands/site/watch.py b/megapixels/commands/site/watch.py new file mode 100644 index 00000000..7bd71038 --- /dev/null +++ b/megapixels/commands/site/watch.py @@ -0,0 +1,46 @@ +""" +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() + + build_file(cfg.DIR_SITE_CONTENT + "/datasets/lfw/index.md") + + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + observer.stop() + + observer.join() |
