Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion solstice/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,13 @@ def hotreload(ssg: SiteGenerator, extra_watches: list[str]):
import pygments.formatters
import pygments.lexers
import watchfiles # type: ignore (removes pyright hallucination)
from watchfiles.filters import DefaultFilter

it = watchfiles.watch(ssg.project_dir, *map(os.path.realpath, extra_watches))
it = watchfiles.watch(
ssg.project_dir,
*map(os.path.realpath, extra_watches),
watch_filter=DefaultFilter(ignore_dirs=(ssg.output_path, *DefaultFilter.ignore_dirs)),
)

# wait for server to start
while True:
Expand Down
24 changes: 17 additions & 7 deletions solstice/sitegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,28 @@ def load_md(self, path: str) -> tuple[str, str, dict[str, Any]]:
content, toc = self.md_to_html(content)
return content, toc, meta

def copy(self, dir: str):
def copy(self, src: str, dest: str | None = None):
"""
Copy a directory to the output path, without altering its contents.
Copy a file/directory to the output path, without altering its contents.
Used for copying static assets like images, CSS, etc.

# Arguments
- `dir`: The directory to copy.
- `src`: The path to copy from.
- `dest`: The path to copy to, relative to `self.output_path`. Defaults to `src`.
"""
if path.exists(dir):
dist = self.output_path_for(dir)
with LogTimer(f"Copying directory '{dir}'..."):
shutil.copytree(dir, dist, dirs_exist_ok=True)

if dest is None:
dest = src

if not path.exists(src):
warn(f"Tried to copy nonexistent path {src}")

dist_path = self.output_path_for(dest)
if path.isdir(src):
with LogTimer(f"Copying directory '{src}'..."):
shutil.copytree(src, dist_path, dirs_exist_ok=True)
else:
shutil.copy(src, dist_path)

def clean(self):
"""Clean the output directory, removing it and all its contents."""
Expand Down