Added SiteConfig.ignore_assets
This commit is contained in:
parent
d5624e209c
commit
167fea0a2c
@ -43,6 +43,8 @@ sites:
|
||||
web_root: ./dist/dogma-jimfinium
|
||||
assets:
|
||||
- assets
|
||||
ignore_assets:
|
||||
- assets/videos
|
||||
articles:
|
||||
- '*.md'
|
||||
addons:
|
||||
|
||||
@ -40,12 +40,24 @@ def copy_assets(site: SiteConfig) -> None:
|
||||
# Assets are defined relative to the build cache; construct the full path.
|
||||
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
|
||||
@ -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] = {}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user