1
1
import shutil
2
- from shutil import copytree
2
+ import sys
3
+ from importlib import resources
3
4
4
5
from logya .content import write_collection , write_page
5
6
from 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 } ".' )
6
24
7
25
8
26
def generate (dir_site : str , verbose : bool , keep : bool , ** _kwargs ):
27
+ """Generate a site in the public directory."""
28
+
9
29
L = Logya (dir_site = dir_site , verbose = verbose )
10
30
L .build ()
11
31
@@ -16,7 +36,7 @@ def generate(dir_site: str, verbose: bool, keep: bool, **_kwargs):
16
36
print (f'Generate site in directory: { L .paths .public .as_posix ()} ' )
17
37
if L .paths .static .exists ():
18
38
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 )
20
40
21
41
print ('Write pages.' )
22
42
for url , content in L .doc_index .items ():
0 commit comments