feat: markdown build on change
This commit is contained in:
		| @@ -1,2 +1,45 @@ | ||||
| def main(): | ||||
|     print("main") | ||||
| import logging | ||||
| from watchdog.observers import Observer | ||||
| from watchdog.events import FileSystemEventHandler | ||||
| import time | ||||
| import os | ||||
|  | ||||
| from .config import SOURCE_DIRECTORY | ||||
|  | ||||
|  | ||||
| logger = logging.getLogger("stsg") | ||||
|  | ||||
|  | ||||
| def build(): | ||||
|     print("building") | ||||
|  | ||||
|  | ||||
| class CustomFileSystemEventHandler(FileSystemEventHandler): | ||||
|     def on_modified(self, event): | ||||
|         if event.is_directory: | ||||
|             return | ||||
|  | ||||
|         filename = os.path.basename(event.src_path) | ||||
|         if filename.startswith('.') or filename.endswith(('~', '.tmp', '.swp')): | ||||
|             return | ||||
|  | ||||
|         logger.info("%s changed, building", event.src_path) | ||||
|         build() | ||||
|  | ||||
|  | ||||
|  | ||||
| def build_on_change(): | ||||
|     print("build on change") | ||||
|     build() | ||||
|  | ||||
|     observer = Observer() | ||||
|     observer.schedule(CustomFileSystemEventHandler(), path=SOURCE_DIRECTORY, recursive=True) | ||||
|     observer.start() | ||||
|  | ||||
|  | ||||
|     try: | ||||
|         while True: | ||||
|             time.sleep(1)  # Keeps the thread alive | ||||
|     except KeyboardInterrupt: | ||||
|         observer.stop() | ||||
|     observer.join() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user