Skip to content

Commit

Permalink
post page
Browse files Browse the repository at this point in the history
  • Loading branch information
HengHuH committed Jun 4, 2024
1 parent 2f7bb0e commit 4076678
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
51 changes: 8 additions & 43 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,6 @@
root = os.path.dirname(os.path.abspath(__file__))
root_url = "https://henghuh.github.io"

post_template = """<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{post.title}}</title>
</head>
<body>
{{post.content}}
<hr>
Heng - <a href="https://henghuh.github.io">https://henghuh.github.io</a>
</body>
</html>
"""

index_page = """<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Heng's Home Page</title>
</head>
<body>
<div align="right">
<a href="https://github.com/HengHuH">GitHub Page</a>
</div>
<h2>工作</h2>
<h2>Post</h2>
{{allposts}}
<hr>
联系我: huangxinghuh@163.com<br>
<font size="-1">最近更新: {{date}}</font-size>
</body>
</html>"""


class Post:
def __init__(self) -> None:
Expand Down Expand Up @@ -112,6 +71,12 @@ class Builder:
def __init__(self, site) -> None:
self._site = site

with open(os.path.join(root, "post_page"), 'r', encoding='utf-8') as f:
self.post_page = f.read()

with open(os.path.join(root, 'index_page'), 'r', encoding="utf-8") as f:
self.index_page = f.read()

def build(self):
alllinks = []
for post in sorted(self._site.posts, key=lambda x: (x.year, x.month, x.day), reverse=True):
Expand All @@ -120,15 +85,15 @@ def build(self):
os.makedirs(dirname, exist_ok=True)

with open(abspath, "w", encoding="utf-8") as f:
posthtml = post_template.replace("{{post.title}}", post.title)
posthtml = self.post_page.replace("{{post.title}}", post.title)
posthtml = posthtml.replace("{{post.content}}", post.content)
f.write(bs(posthtml, 'html.parser').prettify())

print(f"build post: {post.addr} --- DONE")
alllinks.append(f"<a href=\"{post.addr}\">{post.title}</a>")

with open(os.path.join(root, 'index.html'), 'w', encoding='utf-8') as f:
content = index_page.replace("{{allposts}}", "<br>\n".join(alllinks))
content = self.index_page.replace("{{allposts}}", "<br>\n".join(alllinks))
content = content.replace("{{date}}", str(date.today()))
f.write(bs(content, 'html.parser').prettify())

Expand Down
22 changes: 22 additions & 0 deletions index_page
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Heng's Home Page</title>
</head>

<body>
<div align="right">
<a href="https://github.com/HengHuH">GitHub Page</a>
</div>
<h2>工作</h2>
<h2>Post</h2>
{{allposts}}
<hr>
联系我: huangxinghuh@163.com<br>
<font size="-1">最近更新: {{date}}</font-size>
</body>

</html>
16 changes: 16 additions & 0 deletions post_page
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{post.title}}</title>
</head>

<body>
{{post.content}}
<hr>
Heng - <a href="https://henghuh.github.io">https://henghuh.github.io</a>
</body>

</html>

0 comments on commit 4076678

Please sign in to comment.