Add watchdog

This commit is contained in:
Yan Lin 2025-05-16 17:31:36 +02:00
parent 329914e70b
commit 67cd160015
4 changed files with 49 additions and 3 deletions

4
dist/index.css vendored
View file

@ -84,6 +84,7 @@
--primary-text: #58151c;
--secondary-text: #052c65;
--link-hover-color: #555;
--link-hover-color-rgb: 85, 85, 85;
}
@media (prefers-color-scheme: dark) {
@ -98,6 +99,7 @@
--primary-text: #ffddb3;
--secondary-text: #c6e2ff;
--link-hover-color: #ddd;
--link-hover-color-rgb: 221, 221, 221;
}
}
@ -173,7 +175,7 @@ main.container {
}
.blog-link {
color: var(--link-color);
color: var(--text-color);
}
.blog-link:hover {

BIN
dist/profile.webp vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 722 KiB

After

Width:  |  Height:  |  Size: 121 KiB

Before After
Before After

View file

@ -16,10 +16,10 @@ pkgs.mkShell {
fi
source $VENV_PATH/bin/activate
pip install -r requirements.txt
pip install watchdog
python parser/md.py
python generate.py
cd dist
python -m http.server 8000
python watch.py
'';
}

44
watch.py Normal file
View file

@ -0,0 +1,44 @@
import time
import os
import subprocess
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class ChangeHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.is_directory:
return
if any(event.src_path.endswith(ext) for ext in ['.md', '.py', '.html', '.css', '.js']):
print(f"File {event.src_path} has been modified")
self.regenerate()
def on_created(self, event):
if event.is_directory:
return
if any(event.src_path.endswith(ext) for ext in ['.md', '.py', '.html', '.css', '.js']):
print(f"File {event.src_path} has been created")
self.regenerate()
def regenerate(self):
print("Regenerating content...")
subprocess.run(["python", "parser/md.py"])
subprocess.run(["python", "generate.py"])
print("Content regenerated")
if __name__ == "__main__":
event_handler = ChangeHandler()
observer = Observer()
# Watch both current directory and dist directory
observer.schedule(event_handler, "templates", recursive=True)
observer.start()
http_server = subprocess.Popen(["python", "-m", "http.server", "8000", "--directory", "dist"])
try:
print("Watching for file changes... (Press Ctrl+C to stop)")
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
http_server.terminate()
observer.join()