about summary refs log tree commit diff
diff options
context:
space:
mode:
authoruser <user@node5.net>2024-03-11 23:01:34 +0100
committeruser <user@node5.net>2024-03-11 23:01:34 +0100
commit6caca7331885d63fe1d84a3be303c51ed0bd97ba (patch)
tree50e18ece2cadf3722b2f18950ea86f74af05e238
parent3c0058ec43642e6c43094d8e9f7a35c98569d559 (diff)
article thumbnail file extension agnostic
-rw-r--r--blog.node5.net/templates/folder.html2
-rw-r--r--src/article.py31
2 files changed, 23 insertions, 10 deletions
diff --git a/blog.node5.net/templates/folder.html b/blog.node5.net/templates/folder.html
index 41a9ee0..1104551 100644
--- a/blog.node5.net/templates/folder.html
+++ b/blog.node5.net/templates/folder.html
@@ -9,7 +9,7 @@
 		<li class="entry">
 			<a href="{{ article.name }}">
 				{% if article.folder_path %}
-					<img src="{{ article.name }}/Thumbnail.jpg" alt="📄"/>
+					<img src="{{ article.thumbnail_path }}" alt="📄"/>
 				{% endif %}
 				<div class="entry-text">
 					<div>
diff --git a/src/article.py b/src/article.py
index afca0df..20e1c21 100644
--- a/src/article.py
+++ b/src/article.py
@@ -55,20 +55,22 @@ class Article(WebPage):
     source: str
     html: str
     modified: datetime.datetime
+    thumbnail_path: typing.Union[None, str] = None
     folder_path: typing.Union[None, str] = None
 
     @property
     def pretty_print(self) -> str:
         return f'''
-Name:        {self.name}
-Metadata:    {self.metadata.pretty_print}
-Web dir:     {self.web_dir}
-URL:         {self.url}
-Source path: {self.source_path}
-Folder path: {self.folder_path}
-Modified:    {self.modified}
-HTML:        {truncate(self.html)}
-Source:      {truncate(self.source)}'''
+Name:           {self.name}
+Metadata:       {self.metadata.pretty_print}
+Web dir:        {self.web_dir}
+URL:            {self.url}
+Source path:    {self.source_path}
+Thumbnail path: {self.thumbnail_path}
+Folder path:    {self.folder_path}
+Modified:       {self.modified}
+HTML:           {truncate(self.html)}
+Source:         {truncate(self.source)}'''
 
 
 @dataclasses.dataclass
@@ -115,6 +117,17 @@ class ArticleGenerator:
             article_args['folder_path'] = article_folder_name
             dir_basename = os.path.basename(article_folder_name)
             article_args['name'] = dir_basename
+
+            # Look for a thumbnail (file extension agnostic)
+            thumbnail_paths = glob.glob(f'{article_args["folder_path"]}/Thumbnail*')
+
+            if len(thumbnail_paths) > 1:
+                logging.warning(f"More than one thumbnail found, using: {thumbnail_paths[0]}")
+
+            if len(thumbnail_paths) == 0:
+                logging.warning("No thumbnail image")
+            else:
+                article_args['thumbnail_path'] = '/'.join(pathlib.Path(thumbnail_paths[0]).parts[2:])
         else:
             # Article one file
             article_args['name'] = os.path.basename(filename)