From 8382432bfaee187539543f58780dc27b3408c3d4 Mon Sep 17 00:00:00 2001 From: HengHuH Date: Thu, 6 Jun 2024 10:05:55 +0800 Subject: [PATCH] clear --- build.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/build.py b/build.py index 7a6d111..6e166dc 100644 --- a/build.py +++ b/build.py @@ -10,7 +10,6 @@ root = os.path.dirname(os.path.abspath(__file__)) -outdir = os.path.join(root, "build") root_url = "https://henghuh.github.io" @@ -47,7 +46,7 @@ def load(self, path): self.addr = self.name + ".html" self.url = parse.urljoin(root_url, self.addr) meta, self.content = self.extract_meta_content(path) - self.title = meta["title"] + self.title = meta.get("title", self.name) self.published = meta.get('published', True) @@ -67,12 +66,13 @@ def load(self, path): self.url = parse.urljoin(root_url, self.addr) meta, self.content = self.extract_meta_content(path) self.date = meta.get('date', "-".join(fns[0:3])) - self.title = meta["title"] + self.title = meta.get("title", self.name) self.published = meta.get('published', True) class Site: - def __init__(self) -> None: + def __init__(self, root) -> None: + self.root = root self._posts = set() self._pages = set() @@ -109,10 +109,10 @@ def fillin_content(self, content): return content def build(self): - os.makedirs(outdir, exist_ok=True) + os.makedirs(self._site.root, exist_ok=True) for post in self._site.posts: - abspath = os.path.join(outdir, post.addr) + abspath = os.path.join(self._site.root, post.addr) dirname = os.path.dirname(abspath) os.makedirs(dirname, exist_ok=True) @@ -126,7 +126,7 @@ def build(self): print(f"build post: {post.addr} --- DONE") for page in self._site.pages: - abspath = os.path.join(outdir, page.addr) + abspath = os.path.join(self._site.root, page.addr) with open(abspath, "w", encoding="utf-8") as f: pagecontent = self.fillin_content(page.content) pagehtml = self.page_temp.replace("{{page.title}}", page.title) @@ -136,7 +136,7 @@ def build(self): if __name__ == "__main__": - site = Site() + site = Site(os.path.join(root, "build")) for fname in os.listdir(os.path.join(root, "_posts")): fpath = os.path.join(root, "_posts", fname)