Added SiteConfig.ignore_assets

This commit is contained in:
Jim Shepich III 2026-02-04 12:42:53 -05:00
parent d5624e209c
commit 167fea0a2c
4 changed files with 22 additions and 3 deletions

View File

@ -43,6 +43,8 @@ sites:
web_root: ./dist/dogma-jimfinium
assets:
- assets
ignore_assets:
- assets/videos
articles:
- '*.md'
addons:

View File

@ -41,11 +41,23 @@ def copy_assets(site: SiteConfig) -> None:
glob.glob(f'{site.build_cache}/{a.lstrip("/")}')
)
# Also expand the expressions in the ignore list.
ignored_asset_list = []
for a in (site.ignore_assets or []):
ignored_asset_list.extend(
# Assets are defined relative to the build cache; construct the full path.
glob.glob(f'{site.build_cache}/{a.lstrip("/")}')
)
for asset in expanded_asset_list:
# Skip ignored assets.
if asset in ignored_asset_list:
continue
# Construct the destination path analogous to the source path
# but in the web root instead of the build cache.
destination = f'{site.web_root}/{a.lstrip("/")}'
destination = f'{site.web_root}/{asset.removeprefix(site.build_cache).lstrip("/")}'
# Delete existing files.
shutil.rmtree(destination, ignore_errors=True)
@ -58,4 +70,11 @@ def copy_assets(site: SiteConfig) -> None:
else:
continue
# In cases where the ignored assets are defined at a different
# level of the filetree than the included assets, remove them.
for asset in ignored_asset_list:
destination = f'{site.web_root}/{asset.removeprefix(site.build_cache).lstrip("/")}'
shutil.rmtree(destination, ignore_errors=True)
return None

View File

@ -41,8 +41,6 @@ class SiteConfig(pydantic.BaseModel):
published: Optional[bool] = True
git_repo: Optional[GitRepo] = None
assets: Optional[list] = None
# TODO: implement ignore for assets
ignore_assets: Optional[list] = None
articles: Optional[list] = None
template_selections: Optional[dict] = {}