Commit a869a9f343
Unsigned
Layout: unified · split
build.py +29 −8
| @@ -185,7 +185,9 @@ def get_recent_posts_html(content_dir="./content/blog", num_posts=3): | |||
| 185 | lines = [] | 185 | lines = [] |
| 186 | for post in recent: | 186 | for post in recent: |
| 187 | lines.append('\t<li class="post-list-item">') | 187 | lines.append('\t<li class="post-list-item">') |
| 188 | lines.append(f'\t\t<time datetime="{post["date_str"]}">{post["date_full"]}</time>') | 188 | lines.append( |
| 189 | f'\t\t<time datetime="{post["date_str"]}">{post["date_full"]}</time>' | ||
| 190 | ) | ||
| 189 | lines.append(f'\t\t<a href="/blog/{post["slug"]}.html">{post["title"]}</a>') | 191 | lines.append(f'\t\t<a href="/blog/{post["slug"]}.html">{post["title"]}</a>') |
| 190 | lines.append("\t</li>") | 192 | lines.append("\t</li>") |
| 191 | 193 | ||
| @@ -358,6 +360,7 @@ def inject_blog_year_separators(blog_index_path="./.build/blog/index.html"): | |||
| 358 | date_pattern = re.compile(r"datetime=['\"]?(\d{4})-\d{2}-\d{2}['\"]?") | 360 | date_pattern = re.compile(r"datetime=['\"]?(\d{4})-\d{2}-\d{2}['\"]?") |
| 359 | 361 | ||
| 360 | current_year = None | 362 | current_year = None |
| 363 | |||
| 361 | def replace_item(m): | 364 | def replace_item(m): |
| 362 | nonlocal current_year | 365 | nonlocal current_year |
| 363 | item_html = m.group(1) | 366 | item_html = m.group(1) |
| @@ -382,13 +385,22 @@ def generate_tags_page(content_dir="./content/blog", build_dir="./.build"): | |||
| 382 | with one section per tag, each post listed under its tags, sorted newest first. | 385 | with one section per tag, each post listed under its tags, sorted newest first. |
| 383 | Tags link to anchor IDs on the same page. | 386 | Tags link to anchor IDs on the same page. |
| 384 | """ | 387 | """ |
| 385 | TAG_ORDER = ["audit", "emacs", "linux", "personal", "privacy", "security", "self-hosting", "web"] | 388 | TAG_ORDER = [ |
| 389 | "audit", | ||
| 390 | "emacs", | ||
| 391 | "linux", | ||
| 392 | "personal", | ||
| 393 | "privacy", | ||
| 394 | "security", | ||
| 395 | "self-hosting", | ||
| 396 | "web", | ||
| 397 | ] | ||
| 386 | 398 | ||
| 387 | header_patterns = { | 399 | header_patterns = { |
| 388 | "title": re.compile(r"^#\+title:\s*(.+)$", re.IGNORECASE), | 400 | "title": re.compile(r"^#\+title:\s*(.+)$", re.IGNORECASE), |
| 389 | "date": re.compile(r"^#\+date:\s*[\[<](\d{4}-\d{2}-\d{2})"), | 401 | "date": re.compile(r"^#\+date:\s*[\[<](\d{4}-\d{2}-\d{2})"), |
| 390 | "slug": re.compile(r"^#\+slug:\s*(.+)$", re.IGNORECASE), | 402 | "slug": re.compile(r"^#\+slug:\s*(.+)$", re.IGNORECASE), |
| 391 | "tags": re.compile(r"^#\+filetags:\s*(.+)$", re.IGNORECASE), | 403 | "tags": re.compile(r"^#\+filetags:\s*(.+)$", re.IGNORECASE), |
| 392 | "draft": re.compile(r"^#\+draft:\s*(.+)$", re.IGNORECASE), | 404 | "draft": re.compile(r"^#\+draft:\s*(.+)$", re.IGNORECASE), |
| 393 | } | 405 | } |
| 394 | 406 | ||
| @@ -439,7 +451,14 @@ def generate_tags_page(content_dir="./content/blog", build_dir="./.build"): | |||
| 439 | 451 | ||
| 440 | for tag in tags: | 452 | for tag in tags: |
| 441 | if tag in tag_map: | 453 | if tag in tag_map: |
| 442 | tag_map[tag].append({"title": title, "slug": slug, "date_obj": date_obj, "date_str": date_str}) | 454 | tag_map[tag].append( |
| 455 | { | ||
| 456 | "title": title, | ||
| 457 | "slug": slug, | ||
| 458 | "date_obj": date_obj, | ||
| 459 | "date_str": date_str, | ||
| 460 | } | ||
| 461 | ) | ||
| 443 | 462 | ||
| 444 | for tag in tag_map: | 463 | for tag in tag_map: |
| 445 | tag_map[tag].sort(key=lambda x: x["date_obj"], reverse=True) | 464 | tag_map[tag].sort(key=lambda x: x["date_obj"], reverse=True) |
| @@ -458,10 +477,12 @@ def generate_tags_page(content_dir="./content/blog", build_dir="./.build"): | |||
| 458 | f'<li class="post-list-item">' | 477 | f'<li class="post-list-item">' |
| 459 | f'<time datetime="{p["date_str"]}">{p["date_str"]}</time>' | 478 | f'<time datetime="{p["date_str"]}">{p["date_str"]}</time>' |
| 460 | f'<a href="/blog/{p["slug"]}.html">{p["title"]}</a>' | 479 | f'<a href="/blog/{p["slug"]}.html">{p["title"]}</a>' |
| 461 | f'</li>' | 480 | f"</li>" |
| 462 | for p in posts | 481 | for p in posts |
| 463 | ) | 482 | ) |
| 464 | sections.append(f'<h2 id="{tag}">{tag}</h2>\n<ul class="post-list">\n{items}\n</ul>') | 483 | sections.append( |
| 484 | f'<h2 id="{tag}">{tag}</h2>\n<ul class="post-list">\n{items}\n</ul>' | ||
| 485 | ) | ||
| 465 | 486 | ||
| 466 | html = f"""<!doctype html> | 487 | html = f"""<!doctype html> |
| 467 | <html lang=en-us> | 488 | <html lang=en-us> |