Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

src/fileops.py

 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
from os import makedirs, path, sep
from .modules import Tree

def is_dotfile(file_path):
    return any(part.startswith(".") for part in path.normpath(file_path).split(sep))

def write_file(file_path, file_content):
    with open(file_path, "w") as f:
        f.write(file_content)

def read_file(file_path):
    with open(file_path, "r") as f:
        return f.read()

def resolve_tree_paths(project_dir, tree):
    return Tree(
        markdown=path.join(project_dir, tree.markdown),
        static=path.join(project_dir, tree.static),
        templates=path.join(project_dir, tree.templates),
        draft_dest=path.join(project_dir, tree.draft_dest),
        release_dest=path.join(project_dir, tree.release_dest),
        plugins=path.join(project_dir, tree.plugins),
    )

def create_tree_dirs(tree):
    for d in [tree.markdown, tree.static, tree.templates, tree.draft_dest, tree.release_dest, tree.plugins]:
        makedirs(d, exist_ok=True)