Skip to content

Commit

Permalink
clear
Browse files Browse the repository at this point in the history
  • Loading branch information
HengHuH committed Jun 6, 2024
1 parent c5403b6 commit 8382432
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


root = os.path.dirname(os.path.abspath(__file__))
outdir = os.path.join(root, "build")
root_url = "https://henghuh.github.io"


Expand Down Expand Up @@ -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)


Expand All @@ -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()

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8382432

Please sign in to comment.