""" 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/brainwash/index.md") try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()