From 1d414f88822f1d32f533662d30389c754eb56fe9 Mon Sep 17 00:00:00 2001 From: Jim Shepich III Date: Fri, 6 Feb 2026 00:44:09 -0500 Subject: [PATCH] First/last links on articles; lastmod hidden when null --- README.md | 3 +++ jimsite/articles.py | 22 +++++++++++++++-- jimsite/common.py | 27 +++++++++++++++++---- site/assets/css/theme.css | 18 +++++++++++++- site/templates/components/blog_article.html | 9 ++++++- site/templates/partials/footer.html | 1 + 6 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..3badae2 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Jimsite + + \ No newline at end of file diff --git a/jimsite/articles.py b/jimsite/articles.py index ec803b1..16712c1 100644 --- a/jimsite/articles.py +++ b/jimsite/articles.py @@ -107,7 +107,23 @@ def build_articles( '''Generates HTML files for all of a given site's Markdown articles by interpolating the contents and metadata into the HTML templates.''' - for article in index.values(): + # Include the previous and next articles (if available) in the iteration + # in case the article template wants to link to them. + for previous_article, article, next_article in zip( + ([None] + [*index.values()][:-1]), + index.values(), + ([*index.values()][1:] + [None]) + ): + # Create a dummy to be used for the first article's "previous" and the last + # article's "next" to avoid errors if trying to access into None. + dummy_article = Article( + path = '', + content = '', + metadata = ArticleMetadata( + title = '', date = date(1,1,1), published = False, tags = [] + ) + ) + article_html = format_html_template( template_selections['article'], article = article, @@ -115,7 +131,9 @@ def build_articles( article.metadata.tags, template_selections['tag'], site = site )), templates = templates, - site = site + site = site, + previous_article = previous_article or dummy_article, + next_article = next_article or dummy_article ) page_html = format_html_template( diff --git a/jimsite/common.py b/jimsite/common.py index 0c98bcd..1822192 100644 --- a/jimsite/common.py +++ b/jimsite/common.py @@ -2,15 +2,32 @@ import os import inspect import subprocess import pydantic +import logging from dotmap import DotMap from typing import Optional from datetime import date, datetime -run = lambda cmd: subprocess.run( - cmd.split(' '), - stdout = subprocess.PIPE, - stderr = subprocess.PIPE -) +logger = logging.getLogger(__name__) + + +def run(cmd: list|str, log_errors = True, debug = True) -> tuple: + + if isinstance(cmd, str): + cmd = cmd.split(' ') + + res = subprocess.run(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE) + res.stdout = res.stdout.decode().strip() + res.stderr = res.stderr.decode().strip() + res.cmd = cmd + + if debug: + logger.debug(res) + + if log_errors and res.stderr: + logger.exception(res.stderr) + + return res + def filepath_or_string(s: str) -> str: '''Loads the contents of a string if it is a filepath, otherwise returns the string.''' diff --git a/site/assets/css/theme.css b/site/assets/css/theme.css index 11e6001..2f77bed 100644 --- a/site/assets/css/theme.css +++ b/site/assets/css/theme.css @@ -232,7 +232,6 @@ img { ul > li::marker { content: '⍟ '; - /* TODO: Decide on a default li marker for the theme*/ } ul:has(> .blog-archive-li){ @@ -255,4 +254,21 @@ ul:has(> .blog-archive-li){ .blog-archive-li > time { float: right; +} + +a.next-article-link{ + float: right; +} + +a.previous-article-link[data=""], a.next-article-link[data=""]{ + display: none; +} + +time.last-modified-date[data="None"], +time.last-modified-date[data="None"] ~ span.first-published-label, +time.last-modified-date[data="None"] ~ span.last-modified-label, +span.first-published-label:has(~ time.last-modified-date[data="None"]), +span.last-modified-label:has(~ time.last-modified-date[data="None"]) +{ + display: None; } \ No newline at end of file diff --git a/site/templates/components/blog_article.html b/site/templates/components/blog_article.html index dbc4e97..48a7cd1 100644 --- a/site/templates/components/blog_article.html +++ b/site/templates/components/blog_article.html @@ -1,6 +1,9 @@
- First published: · Last modified: + First published: + + · Last modified: +

{article.metadata.title}

{article.content}


+

+ + +

Tags: {blog_tags}{templates.components.rss_icon}

\ No newline at end of file diff --git a/site/templates/partials/footer.html b/site/templates/partials/footer.html index dd714d4..4d30e6a 100644 --- a/site/templates/partials/footer.html +++ b/site/templates/partials/footer.html @@ -1,3 +1,4 @@ \ No newline at end of file