summaryrefslogtreecommitdiff
path: root/src/pyssg/generator.py
blob: 143eae1b0d0850238e6bb653bf9d3d28d5226d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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)