aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruser@node5.net <user@node5.net>2026-05-31 11:13:44 +0200
committeruser@node5.net <user@node5.net>2026-05-31 11:13:44 +0200
commitdd207fc2a42c4587ffe1ace77fe8c939bc00e7be (patch)
tree8c5ea3d652eda0e4ac8c2492410361f07a1631d0
parentcc83ff401fe5d13b44fdfa3c33b757bb99f8cb8c (diff)
article metadata - get modified date from git instead of file system
after migrating to nix, it resolved to 1970-01-01, it's better to get the modified date directly from git regardless
-rw-r--r--src/article.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/article.py b/src/article.py
index a35b431..fc73edd 100644
--- a/src/article.py
+++ b/src/article.py
@@ -8,6 +8,7 @@ import typing
import markdown
import yaml
import markupsafe
+import subprocess
logger = logging.getLogger(__name__)
@@ -140,8 +141,14 @@ class ArticleGenerator:
article_args[
'url'] = f'{"/" if article_args["web_dir"] else ""}{"/".join(article_args["web_dir"])}/{article_args["name"]}'
- article_args['modified'] = datetime.datetime.utcfromtimestamp(os.path.getmtime(path)).replace(
- tzinfo=datetime.datetime.now().astimezone().tzinfo)
+ # Get article modified date time from git commit
+ article_args['modified'] = datetime.datetime.fromisoformat(subprocess.run(
+ ['git', 'log', '-1', '--pretty=format:%ci', pathlib.Path(path).relative_to(self.articles_path)],
+ cwd=self.articles_path, capture_output=True, text=True).stdout)
+
+ # Get article modified date time from file system
+ # article_args['modified'] = datetime.datetime.utcfromtimestamp(os.path.getmtime(path)).replace(
+ # tzinfo=datetime.datetime.now().astimezone().tzinfo)
with open(path, 'r') as file:
source = file.read()