11import shutil
22import sys
33from importlib import resources
4+ from pathlib import Path
45
56from logya .content import write_collection , write_page
67from logya .core import Logya
78from logya .util import paths
89
910
11+ def clean (dir_site : str , ** kwargs ) -> None :
12+ L = Logya (dir_site = dir_site , verbose = kwargs .get ('verbose' ))
13+ L .build ()
14+
15+ search_index = L .collection_index .copy ()
16+ search_index .update (L .doc_index )
17+
18+ for root , _ , files in L .paths .public .walk ():
19+ for f in files :
20+ rel_file = root .relative_to (L .paths .public ).joinpath (f )
21+ url = '/' + rel_file .as_posix ()
22+
23+ if url in search_index or url .replace ('index.html' , '' ) in search_index :
24+ continue
25+ if L .paths .static .joinpath (rel_file ).exists ():
26+ continue
27+
28+ stale_file = Path (root , f )
29+ L .info (f'Remove: { stale_file } - { url } ' )
30+ stale_file .unlink ()
31+
32+
1033def create (dir_site : str , name : str , site : str , ** _kwargs ) -> None :
1134 """Create a new site in the specified directory."""
1235
@@ -23,10 +46,10 @@ def create(dir_site: str, name: str, site: str, **_kwargs) -> None:
2346 print (f'Site created in "{ target } ".' )
2447
2548
26- def generate (dir_site : str , verbose : bool , keep : bool , ** _kwargs ):
49+ def generate (dir_site : str , keep : bool , ** kwargs ):
2750 """Generate a site in the public directory."""
2851
29- L = Logya (dir_site = dir_site , verbose = verbose )
52+ L = Logya (dir_site = dir_site , verbose = kwargs . get ( ' verbose' ) )
3053 L .build ()
3154
3255 mtime_templates = None
0 commit comments