Add watchdog
This commit is contained in:
parent
329914e70b
commit
67cd160015
4 changed files with 49 additions and 3 deletions
4
dist/index.css
vendored
4
dist/index.css
vendored
|
|
@ -84,6 +84,7 @@
|
||||||
--primary-text: #58151c;
|
--primary-text: #58151c;
|
||||||
--secondary-text: #052c65;
|
--secondary-text: #052c65;
|
||||||
--link-hover-color: #555;
|
--link-hover-color: #555;
|
||||||
|
--link-hover-color-rgb: 85, 85, 85;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
|
|
@ -98,6 +99,7 @@
|
||||||
--primary-text: #ffddb3;
|
--primary-text: #ffddb3;
|
||||||
--secondary-text: #c6e2ff;
|
--secondary-text: #c6e2ff;
|
||||||
--link-hover-color: #ddd;
|
--link-hover-color: #ddd;
|
||||||
|
--link-hover-color-rgb: 221, 221, 221;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -173,7 +175,7 @@ main.container {
|
||||||
}
|
}
|
||||||
|
|
||||||
.blog-link {
|
.blog-link {
|
||||||
color: var(--link-color);
|
color: var(--text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.blog-link:hover {
|
.blog-link:hover {
|
||||||
|
|
|
||||||
BIN
dist/profile.webp
vendored
BIN
dist/profile.webp
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 722 KiB After Width: | Height: | Size: 121 KiB |
|
|
@ -16,10 +16,10 @@ pkgs.mkShell {
|
||||||
fi
|
fi
|
||||||
source $VENV_PATH/bin/activate
|
source $VENV_PATH/bin/activate
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
pip install watchdog
|
||||||
|
|
||||||
python parser/md.py
|
python parser/md.py
|
||||||
python generate.py
|
python generate.py
|
||||||
cd dist
|
python watch.py
|
||||||
python -m http.server 8000
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
44
watch.py
Normal file
44
watch.py
Normal 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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue