aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoruser@node5.net <user@node5.net>2026-05-31 12:12:25 +0200
committeruser@node5.net <user@node5.net>2026-05-31 12:12:25 +0200
commit23cf16e4aed56300698879c1862ce84eab812aea (patch)
tree4f65291ec6ff080f90e3ae790b40549646c0b501 /src
parentdd207fc2a42c4587ffe1ace77fe8c939bc00e7be (diff)
article metadata - modified date fallback if articles aren't git tracked
fallback to file system modified data
Diffstat (limited to 'src')
-rw-r--r--src/article.py41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/article.py b/src/article.py
index fc73edd..4fff8b5 100644
--- a/src/article.py
+++ b/src/article.py
@@ -53,14 +53,15 @@ def truncate(text: str, max_length: int = 50):
@dataclasses.dataclass
class Article(WebPage):
- metadata: MetaData
- web_dir: tuple
- source_path: str
- source: str
- html: str
- modified: datetime.datetime
- thumbnail_path: typing.Union[None, str] = None
- folder_path: typing.Union[None, str] = None
+ metadata: MetaData # date, description
+ web_dir: tuple # Url path of the article, folder agnostic, removes .md
+ source_path: str # Path to the markdown source file
+ git_path: str # This is the top most path e.g. /article.md for single file articles, and /Article folder for folder
+ source: str # Source markdown, without the metadata
+ html: str # The generated HTML output
+ modified: datetime.datetime # Article last modification date
+ thumbnail_path: typing.Union[None, str] = None # Path to the thumbnail image to display in folder view, e.g. /
+ folder_path: typing.Union[None, str] = None # Path to the folder path to the article folder, if applicable
@property
def pretty_print(self) -> str:
@@ -70,6 +71,7 @@ Metadata: {self.metadata.pretty_print}
Web dir: {self.web_dir}
URL: {self.url}
Source path: {self.source_path}
+Git path: {self.git_path}
Thumbnail path: {self.thumbnail_path}
Folder path: {self.folder_path}
Modified: {self.modified}
@@ -116,7 +118,7 @@ class ArticleGenerator:
basename = os.path.basename(filename)
if basename == 'index':
- # Article is the folder
+ # Article type is folder
article_folder_name = os.path.dirname(path)
article_args['folder_path'] = article_folder_name
dir_basename = os.path.basename(article_folder_name)
@@ -132,23 +134,28 @@ class ArticleGenerator:
logger.warning("No thumbnail image")
else:
article_args['thumbnail_path'] = '/'.join(pathlib.Path(thumbnail_paths[0]).parts[-2:])
+ article_args['git_path'] = article_args['folder_path']
else:
- # Article one file
+ # Article is one file
article_args['name'] = os.path.basename(filename)
+ article_args['git_path'] = path
article_args['web_dir'] = self.get_web_dir(path, article_args['name'])
article_args['source_path'] = path
article_args[
'url'] = f'{"/" if article_args["web_dir"] else ""}{"/".join(article_args["web_dir"])}/{article_args["name"]}'
- # 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)
+ git_date = subprocess.run(['git', 'log', '-1', '--pretty=format:%ci', pathlib.Path(article_args['git_path']) \
+ .relative_to(self.articles_path)], cwd=self.articles_path, capture_output=True, text=True).stdout
+ if git_date == '':
+ logger.warning("Article folder is not a git directory, modified dates will use file system (worse data)")
+ # 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)
+ else:
+ # Get article modified date time from git commit
+ article_args['modified'] = datetime.datetime.fromisoformat(git_date)
- # 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()