Commit 8c8c09b13e

8c8c09b13ebab2ea3d74ed8e9b7fa9246477ea94

parent: dcfa93fc08

Unsigned

github-actions <41898282+github-actions[bot]@users.noreply.github.com> · 2025-06-04 01:04 UTC

Commit from GitHub Actions (Ruff)

Layout: unified · split

build.py +23 −21
@@ -7,6 +7,7 @@ import sys
77from pathlib import Path
88from datetime import datetime
99
10
1011def update_index_html(html_snippet, template_path="./theme/templates/index.html"):
1112 """
1213 Read the index.html file at `template_path`, replace everything between
@@ -31,7 +32,7 @@ def update_index_html(html_snippet, template_path="./theme/templates/index.html"
3132 # Include the newline after BEGIN_POSTS
3233 insert_start = begin_index + len(begin_marker)
3334 # Ensure we capture the newline character if present
34 if content[insert_start:insert_start+1] == "\n":
35 if content[insert_start : insert_start + 1] == "\n":
3536 insert_start += 1
3637
3738 # If there is a newline before END_POSTS, trim trailing whitespace from snippet block
@@ -59,16 +60,13 @@ def update_index_html(html_snippet, template_path="./theme/templates/index.html"
5960 end_line_start = end_index
6061
6162 # Construct the new content
62 new_content = (
63 content[:insert_start]
64 + indented_snippet
65 + content[end_line_start:]
66 )
63 new_content = content[:insert_start] + indented_snippet + content[end_line_start:]
6764
6865 # Write back to index.html
6966 with open(template_path, "w", encoding="utf-8") as f:
7067 f.write(new_content)
7168
69
7270def get_recent_posts_html(content_dir="./content/blog", num_posts=3):
7371 """
7472 Scan the `content_dir` for .org blog post files, extract their headers,
@@ -86,10 +84,10 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3):
8684 posts = []
8785
8886 header_patterns = {
89 "title": re.compile(r'^#\+title:\s*(.+)$', re.IGNORECASE),
90 "date": re.compile(r'^#\+date:\s*<(\d{4}-\d{2}-\d{2})'),
91 "slug": re.compile(r'^#\+slug:\s*(.+)$', re.IGNORECASE),
92 "filetags": re.compile(r'^#\+filetags:\s*(.+)$', re.IGNORECASE),
87 "title": re.compile(r"^#\+title:\s*(.+)$", re.IGNORECASE),
88 "date": re.compile(r"^#\+date:\s*<(\d{4}-\d{2}-\d{2})"),
89 "slug": re.compile(r"^#\+slug:\s*(.+)$", re.IGNORECASE),
90 "filetags": re.compile(r"^#\+filetags:\s*(.+)$", re.IGNORECASE),
9391 }
9492
9593 for org_path in Path(content_dir).glob("*.org"):
@@ -139,13 +137,15 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3):
139137 # Skip files with invalid date format
140138 continue
141139
142 posts.append({
143 "title": title,
144 "date_str": date_str,
145 "date_obj": date_obj,
146 "slug": slug,
147 "tags": tags,
148 })
140 posts.append(
141 {
142 "title": title,
143 "date_str": date_str,
144 "date_obj": date_obj,
145 "slug": slug,
146 "tags": tags,
147 }
148 )
149149
150150 # Sort posts by date (newest first)
151151 posts.sort(key=lambda x: x["date_obj"], reverse=True)
@@ -157,16 +157,18 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3):
157157 lines = []
158158 for post in recent:
159159 lines.append('\t<div class="post">')
160 lines.append(f'\t\t<time datetime="{post["date_str"]}">{post["date_str"]}</time>')
160 lines.append(
161 f'\t\t<time datetime="{post["date_str"]}">{post["date_str"]}</time>'
162 )
161163 lines.append('\t\t<div class="post-content">')
162164 lines.append(f'\t\t\t<a href="/blog/{post["slug"]}.html">{post["title"]}</a>')
163165 if post["tags"]:
164166 lines.append('\t\t\t<div class="post-tags">')
165167 for tag in post["tags"]:
166168 lines.append(f'\t\t\t\t<span class="tag">{tag}</span>')
167 lines.append('\t\t\t</div>')
168 lines.append('\t\t</div>')
169 lines.append('\t</div>')
169 lines.append("\t\t\t</div>")
170 lines.append("\t\t</div>")
171 lines.append("\t</div>")
170172
171173 return "\n".join(lines)
172174