Skip to content

Commit

Permalink
add published
Browse files Browse the repository at this point in the history
  • Loading branch information
HengHuH committed Jun 5, 2024
1 parent 62cc0ed commit c5403b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

/.vscode
/build
1 change: 1 addition & 0 deletions _posts/2024-04-05-my-first-post.post
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
title: test
date: 2024-04-05
published: False
---

<h1>My First Post</h1>
Expand Down
15 changes: 10 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self) -> None:
self.url = ""
self.title = ""
self.content = ""
self.published = True

@staticmethod
def extract_meta_content(path):
Expand All @@ -47,10 +48,12 @@ def load(self, path):
self.url = parse.urljoin(root_url, self.addr)
meta, self.content = self.extract_meta_content(path)
self.title = meta["title"]
self.published = meta.get('published', True)


class Post(Page):
def __init__(self) -> None:
super(Post, self).__init__()
self.date = None

def load(self, path):
Expand All @@ -63,8 +66,9 @@ def load(self, path):
self.addr = os.path.join(fns[0], fns[1], self.name + ".html")
self.url = parse.urljoin(root_url, self.addr)
meta, self.content = self.extract_meta_content(path)
self.date = getattr(meta, "date", "-".join(fns[0:3]))
self.date = meta.get('date', "-".join(fns[0:3]))
self.title = meta["title"]
self.published = meta.get('published', True)


class Site:
Expand Down Expand Up @@ -119,8 +123,7 @@ def build(self):

posthtml = posthtml.replace("{{page.content}}", content)
f.write(bs(posthtml, "html.parser").prettify())

print(f"build post: {post.addr} --- DONE")
print(f"build post: {post.addr} --- DONE")

for page in self._site.pages:
abspath = os.path.join(outdir, page.addr)
Expand All @@ -139,15 +142,17 @@ def build(self):
fpath = os.path.join(root, "_posts", fname)
post = Post()
post.load(fpath)
site.add_post(post)
if post.published:
site.add_post(post)

for fname in os.listdir(root):
if not fname.endswith(".page"):
continue
fpath = os.path.join(root, fname)
page = Page()
page.load(fpath)
site.add_page(page)
if page.published:
site.add_page(page)

builder = Builder(site)
builder.build()

0 comments on commit c5403b6

Please sign in to comment.