Compare commits
4 Commits
ea7688016a
...
b3ad6d7114
| Author | SHA1 | Date | |
|---|---|---|---|
| b3ad6d7114 | |||
| 7c819bc923 | |||
| e001c18cf6 | |||
| 44cb4045ba |
@@ -68,10 +68,23 @@ HTML_TEMPLATE = """<!DOCTYPE html>
|
|||||||
color: #191919;
|
color: #191919;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
.page-content h3 {{
|
||||||
|
font-family: 'Permanent Marker', cursive;
|
||||||
|
font-size: 1.4rem;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
margin-bottom: 0.75rem;
|
||||||
|
color: #191919;
|
||||||
|
font-weight: 700;
|
||||||
|
}}
|
||||||
|
|
||||||
.page-content p {{
|
.page-content p {{
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
.page-content strong {{
|
||||||
|
font-weight: 700;
|
||||||
|
}}
|
||||||
|
|
||||||
.page-content a {{
|
.page-content a {{
|
||||||
color: #E6507D;
|
color: #E6507D;
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
@@ -89,6 +102,22 @@ HTML_TEMPLATE = """<!DOCTYPE html>
|
|||||||
.page-content li {{
|
.page-content li {{
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
.page-content blockquote {{
|
||||||
|
margin: 1.5rem 0;
|
||||||
|
padding: 1rem 1.5rem;
|
||||||
|
border-left: 4px solid #E6507D;
|
||||||
|
background-color: rgba(230, 80, 125, 0.05);
|
||||||
|
font-style: italic;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.page-content blockquote p {{
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}}
|
||||||
|
|
||||||
|
.page-content blockquote p:last-child {{
|
||||||
|
margin-bottom: 0;
|
||||||
|
}}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="page">
|
<body class="page">
|
||||||
@@ -102,15 +131,15 @@ HTML_TEMPLATE = """<!DOCTYPE html>
|
|||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Page background colors
|
# Page background colors (muted primary and secondary colors)
|
||||||
PAGE_COLORS = {
|
PAGE_COLORS = {
|
||||||
'comics': '#ffffff',
|
'about': '#f5e3d9', # muted peach
|
||||||
'about': '#f5e6d3',
|
'comics': '#e3d9f5', # muted lavender
|
||||||
'projects': '#e8dfd0',
|
'projects': '#f5f5d9', # muted yellow
|
||||||
'links': '#d9e8d8',
|
'links': '#d9f5e3', # muted teal
|
||||||
'contact': '#e8d8d8',
|
'contact': '#f5d9d9', # muted coral
|
||||||
'now': '#d8e3e8',
|
'now': '#d9e3f5', # muted blue
|
||||||
'uses': '#e8e0d8',
|
'uses': '#f5dfe3', # muted peach-pink
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
118
scripts/watch.py
Normal file
118
scripts/watch.py
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Watch script for Puercito Fiction site.
|
||||||
|
Monitors markdown files in content/ directory and automatically rebuilds when changes are detected.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
from watchdog.observers import Observer
|
||||||
|
from watchdog.events import FileSystemEventHandler
|
||||||
|
|
||||||
|
# Add parent directory to path so we can import build script
|
||||||
|
sys.path.insert(0, str(Path(__file__).parent))
|
||||||
|
from build import convert_markdown_to_html, PAGE_COLORS
|
||||||
|
|
||||||
|
|
||||||
|
class MarkdownChangeHandler(FileSystemEventHandler):
|
||||||
|
"""Handler for markdown file changes."""
|
||||||
|
|
||||||
|
def __init__(self, content_dir: Path, site_dir: Path):
|
||||||
|
self.content_dir = content_dir
|
||||||
|
self.site_dir = site_dir
|
||||||
|
self.last_modified = {}
|
||||||
|
|
||||||
|
def on_modified(self, event):
|
||||||
|
"""Called when a file is modified."""
|
||||||
|
if event.is_directory:
|
||||||
|
return
|
||||||
|
|
||||||
|
file_path = Path(event.src_path)
|
||||||
|
|
||||||
|
# Only process .md files
|
||||||
|
if file_path.suffix != '.md':
|
||||||
|
return
|
||||||
|
|
||||||
|
# Debounce: ignore if file was modified less than 0.5 seconds ago
|
||||||
|
current_time = time.time()
|
||||||
|
if file_path in self.last_modified:
|
||||||
|
if current_time - self.last_modified[file_path] < 0.5:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.last_modified[file_path] = current_time
|
||||||
|
|
||||||
|
print(f"\n📝 Change detected: {file_path.name}")
|
||||||
|
self._rebuild_file(file_path)
|
||||||
|
|
||||||
|
def on_created(self, event):
|
||||||
|
"""Called when a file is created."""
|
||||||
|
if event.is_directory:
|
||||||
|
return
|
||||||
|
|
||||||
|
file_path = Path(event.src_path)
|
||||||
|
|
||||||
|
# Only process .md files
|
||||||
|
if file_path.suffix != '.md':
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"\n✨ New file created: {file_path.name}")
|
||||||
|
self._rebuild_file(file_path)
|
||||||
|
|
||||||
|
def _rebuild_file(self, markdown_file: Path):
|
||||||
|
"""Rebuild a single markdown file."""
|
||||||
|
try:
|
||||||
|
convert_markdown_to_html(markdown_file, self.site_dir)
|
||||||
|
print(f"✅ Build successful at {time.strftime('%H:%M:%S')}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Build failed: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main watch script."""
|
||||||
|
# Define directories
|
||||||
|
script_dir = Path(__file__).parent
|
||||||
|
project_dir = script_dir.parent
|
||||||
|
content_dir = project_dir / 'content'
|
||||||
|
site_dir = project_dir / 'site'
|
||||||
|
|
||||||
|
# Ensure directories exist
|
||||||
|
if not content_dir.exists():
|
||||||
|
print(f"❌ Error: {content_dir} directory not found")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not site_dir.exists():
|
||||||
|
print(f"Creating {site_dir} directory...")
|
||||||
|
site_dir.mkdir(parents=True)
|
||||||
|
|
||||||
|
# Initial build
|
||||||
|
print("🏗️ Running initial build...")
|
||||||
|
print("-" * 50)
|
||||||
|
md_files = list(content_dir.glob('*.md'))
|
||||||
|
for md_file in md_files:
|
||||||
|
convert_markdown_to_html(md_file, site_dir)
|
||||||
|
print("-" * 50)
|
||||||
|
print(f"✅ Initial build complete! Built {len(md_files)} file(s)\n")
|
||||||
|
|
||||||
|
# Setup file watcher
|
||||||
|
event_handler = MarkdownChangeHandler(content_dir, site_dir)
|
||||||
|
observer = Observer()
|
||||||
|
observer.schedule(event_handler, str(content_dir), recursive=False)
|
||||||
|
observer.start()
|
||||||
|
|
||||||
|
print("👀 Watching for changes in content/ directory...")
|
||||||
|
print(" Press Ctrl+C to stop\n")
|
||||||
|
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n\n👋 Stopping watch script...")
|
||||||
|
observer.stop()
|
||||||
|
|
||||||
|
observer.join()
|
||||||
|
print("✅ Watch script stopped")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user