11import shutil
2- from shutil import copytree
2+ import sys
3+ from importlib import resources
34
45from logya .content import write_collection , write_page
56from logya .core import Logya
7+ from logya .util import paths
8+
9+
10+ def create (dir_site : str , name : str , site : str , ** _kwargs ) -> None :
11+ """Create a new site in the specified directory."""
12+
13+ target = paths (dir_site = dir_site ).root .joinpath (name )
14+ if target .exists ():
15+ sys .exit (f'Error: "{ target } " already exists. Please remove it or specify another location.' )
16+
17+ source = resources .files (__name__ ).joinpath (f'sites/{ site } ' )
18+ if source .is_dir ():
19+ shutil .copytree (source , target ) # type: ignore
20+ else :
21+ sys .exit (f'The site "{ site } " is not installed.' )
22+
23+ print (f'Site created in "{ target } ".' )
624
725
826def generate (dir_site : str , verbose : bool , keep : bool , ** _kwargs ):
27+ """Generate a site in the public directory."""
28+
929 L = Logya (dir_site = dir_site , verbose = verbose )
1030 L .build ()
1131
@@ -16,7 +36,7 @@ def generate(dir_site: str, verbose: bool, keep: bool, **_kwargs):
1636 print (f'Generate site in directory: { L .paths .public .as_posix ()} ' )
1737 if L .paths .static .exists ():
1838 print ('Copy static files.' )
19- copytree (L .paths .static , L .paths .public , dirs_exist_ok = True )
39+ shutil . copytree (L .paths .static , L .paths .public , dirs_exist_ok = True )
2040
2141 print ('Write pages.' )
2242 for url , content in L .doc_index .items ():
0 commit comments