feat: markdown build on change
This commit is contained in:
parent
d68cfe15fe
commit
6d1ea43089
@ -1,6 +1,7 @@
|
||||
[project]
|
||||
name = "stsg"
|
||||
dependencies = [
|
||||
"watchdog~=6.0.0"
|
||||
]
|
||||
dynamic = []
|
||||
authors = []
|
||||
@ -10,7 +11,8 @@ classifiers = []
|
||||
version = "0.0.0"
|
||||
|
||||
[project.scripts]
|
||||
stsg_build = "stsg.__main__:main"
|
||||
stsg_build = "stsg.__main__:build"
|
||||
stsg_build_on_change = "stsg.__main__:build_on_change"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user