diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2021-05-09 12:37:01 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2021-05-09 12:37:01 -0600 |
commit | 0a9c6693255800c6c197a3dcf3614046c296e293 (patch) | |
tree | d4e9999c2a0931db95379f7cb3a9c5fe0d7a7eaa /src/pyssg/generator.py | |
parent | 6f143604c28c3165db35c2cad99a0dc76d7ccdaa (diff) |
semiworking program, still very alpha
Diffstat (limited to 'src/pyssg/generator.py')
-rw-r--r-- | src/pyssg/generator.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/pyssg/generator.py b/src/pyssg/generator.py new file mode 100644 index 0000000..143eae1 --- /dev/null +++ b/src/pyssg/generator.py @@ -0,0 +1,40 @@ +import os +import shutil +from .discovery import get_all_files +from .converter import create_html_files + + +def create_dir_structure(dst: str, dirs: list[str]) -> None: + iwd = os.getcwd() + + os.chdir(dst) + cwd = os.getcwd() + + for d in dirs: + # for the dir structure, + # doesn't matter if the dir already exists + try: + os.makedirs(os.path.join(cwd, d)) + except FileExistsError: + pass + + os.chdir(iwd) + + +def copy_html_files(src: str, dst: str, files: list[str]) -> None: + src_file = None + dst_file = None + + for f in files: + src_file = os.path.join(src, f) + dst_file = os.path.join(dst, f) + + shutil.copy2(src_file, dst_file) + + +def generate_static_site(src: str, dst: str) -> None: + dirs, md_files, html_files = get_all_files(src) + create_dir_structure(dst, dirs) + + copy_html_files(src, dst, html_files) + create_html_files(src, dst, md_files) |