1
0
Fork 0

Derive blog post pubdate from git instead of metadata

This commit is contained in:
Tim Van Baak 2024-06-25 13:59:10 -07:00
parent 8935d6f3a9
commit 1a7c02ca64
6 changed files with 14 additions and 11 deletions

View File

@ -4,7 +4,7 @@ help: ## display this help
@awk 'BEGIN{FS = ":.*##"; printf "\033[1m\nUsage\n \033[1;92m make\033[0;36m <target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } ' $(MAKEFILE_LIST) @awk 'BEGIN{FS = ":.*##"; printf "\033[1m\nUsage\n \033[1;92m make\033[0;36m <target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } ' $(MAKEFILE_LIST)
build: ## compile src/ into out/ with pagefind build: ## compile src/ into out/ with pagefind
./build.py out/ --draft ./build.py out/
pagefind --site out/ pagefind --site out/
clean: ## delete out/ and src/ clean: ## delete out/ and src/

View File

@ -6,16 +6,26 @@ import copy
import os import os
import pathlib import pathlib
import shutil import shutil
import subprocess
import bs4 import bs4
from feedgen.feed import FeedGenerator from feedgen.feed import FeedGenerator
import markdown import markdown
def get_pubdate(src_path):
pubdate = subprocess.run(
["git", "log", "--diff-filter=A", "--format=%aI", "--", src_path],
capture_output=True,
text=True,
check=True,
)
return datetime.fromisoformat(pubdate.stdout.strip())
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("out", help="output directory") parser.add_argument("out", help="output directory")
parser.add_argument("--draft", action="store_true", help="include draft pages")
args = parser.parse_args() args = parser.parse_args()
src = pathlib.Path("src") src = pathlib.Path("src")
@ -124,11 +134,8 @@ def main():
page.header.append(aside) page.header.append(aside)
# RSS metadata # RSS metadata
if "pubdate" in meta and meta["pubdate"][0] == "draft" and not args.draft: if "feed" in meta:
continue pubdate = get_pubdate(path.as_posix())
if "feed" in meta and "pubdate" in meta and meta["pubdate"][0] != "draft":
pubdate = datetime.fromisoformat(meta["pubdate"][0])
link = f"https://www.alogoulogoi.com/{dest.relative_to(out).as_posix()}" link = f"https://www.alogoulogoi.com/{dest.relative_to(out).as_posix()}"
for feed in meta["feed"]: for feed in meta["feed"]:
if feed not in feeds: if feed not in feeds:

View File

@ -1,6 +1,5 @@
--- ---
title: The traditional first software engineer blog post title: The traditional first software engineer blog post
pubdate: 2023-09-28T15:39:59-07:00
feed: blog feed: blog
--- ---

View File

@ -1,6 +1,5 @@
--- ---
title: SHLVL PS1 title: SHLVL PS1
pubdate: 2023-12-18T09:53:17-08:00
feed: blog feed: blog
--- ---

View File

@ -1,6 +1,5 @@
--- ---
title: Backing up my ZFS NAS to an external drive title: Backing up my ZFS NAS to an external drive
pubdate: 2023-09-29T16:23:49-07:00
feed: blog feed: blog
--- ---

View File

@ -1,6 +1,5 @@
--- ---
title: Archiving bookmarks title: Archiving bookmarks
pubdate: 2024-05-27T21:06:37-07:00
feed: blog feed: blog
--- ---