First/last links on articles; lastmod hidden when null
This commit is contained in:
parent
90ffc019d2
commit
1d414f8882
@ -107,7 +107,23 @@ def build_articles(
|
|||||||
'''Generates HTML files for all of a given site's Markdown articles
|
'''Generates HTML files for all of a given site's Markdown articles
|
||||||
by interpolating the contents and metadata into the HTML templates.'''
|
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(
|
article_html = format_html_template(
|
||||||
template_selections['article'],
|
template_selections['article'],
|
||||||
article = article,
|
article = article,
|
||||||
@ -115,7 +131,9 @@ def build_articles(
|
|||||||
article.metadata.tags, template_selections['tag'], site = site
|
article.metadata.tags, template_selections['tag'], site = site
|
||||||
)),
|
)),
|
||||||
templates = templates,
|
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(
|
page_html = format_html_template(
|
||||||
|
|||||||
@ -2,15 +2,32 @@ import os
|
|||||||
import inspect
|
import inspect
|
||||||
import subprocess
|
import subprocess
|
||||||
import pydantic
|
import pydantic
|
||||||
|
import logging
|
||||||
from dotmap import DotMap
|
from dotmap import DotMap
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
|
||||||
run = lambda cmd: subprocess.run(
|
logger = logging.getLogger(__name__)
|
||||||
cmd.split(' '),
|
|
||||||
stdout = subprocess.PIPE,
|
|
||||||
stderr = subprocess.PIPE
|
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:
|
def filepath_or_string(s: str) -> str:
|
||||||
'''Loads the contents of a string if it is a filepath, otherwise returns the string.'''
|
'''Loads the contents of a string if it is a filepath, otherwise returns the string.'''
|
||||||
|
|||||||
@ -232,7 +232,6 @@ img {
|
|||||||
|
|
||||||
ul > li::marker {
|
ul > li::marker {
|
||||||
content: '⍟ ';
|
content: '⍟ ';
|
||||||
/* TODO: Decide on a default li marker for the theme*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ul:has(> .blog-archive-li){
|
ul:has(> .blog-archive-li){
|
||||||
@ -256,3 +255,20 @@ ul:has(> .blog-archive-li){
|
|||||||
.blog-archive-li > time {
|
.blog-archive-li > time {
|
||||||
float: right;
|
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;
|
||||||
|
}
|
||||||
@ -1,6 +1,9 @@
|
|||||||
<article>
|
<article>
|
||||||
<!-- TODO: Fix the layout -->
|
<!-- TODO: Fix the layout -->
|
||||||
First published: <time pubdate datetime="{article.metadata.date}">{article.metadata.date}</time> · Last modified: <time pubdate datetime="{article.metadata.lastmod}">{article.metadata.lastmod}</time>
|
<span class="first-published-label">First published: </span>
|
||||||
|
<time class="first-published-date" pubdate data="{article.metadata.date}" datetime="{article.metadata.date}">{article.metadata.date}</time>
|
||||||
|
<span class="last-modified-label"> · Last modified: </span>
|
||||||
|
<time class="last-modified-date" data="{article.metadata.lastmod}" datetime="{article.metadata.lastmod}">{article.metadata.lastmod}</time>
|
||||||
<hr />
|
<hr />
|
||||||
<h1 class="headline">{article.metadata.title}</h1>
|
<h1 class="headline">{article.metadata.title}</h1>
|
||||||
<p class="byline">
|
<p class="byline">
|
||||||
@ -8,5 +11,9 @@
|
|||||||
</p>
|
</p>
|
||||||
{article.content}
|
{article.content}
|
||||||
<br /><hr /><br />
|
<br /><hr /><br />
|
||||||
|
<p>
|
||||||
|
<a href="{previous_article.path}" title="{previous_article.metadata.title}" data="{previous_article.path}" class="previous-article-link">< Previous</a>
|
||||||
|
<a href="{next_article.path}" title="{next_article.metadata.title}" data="{next_article.path}" class="next-article-link">Next ></a>
|
||||||
|
</p>
|
||||||
<p>Tags: {blog_tags}<span>{templates.components.rss_icon}</span></p>
|
<p>Tags: {blog_tags}<span>{templates.components.rss_icon}</span></p>
|
||||||
</article>
|
</article>
|
||||||
@ -1,3 +1,4 @@
|
|||||||
<footer>
|
<footer>
|
||||||
|
<!-- Add socials (email, Matrix, Friendica, Gitea)-->
|
||||||
<br /><span class='copyright'>Copyright © 2021-{globalvars.today.year} Jim Shepich</span>
|
<br /><span class='copyright'>Copyright © 2021-{globalvars.today.year} Jim Shepich</span>
|
||||||
</footer>
|
</footer>
|
||||||
Loading…
x
Reference in New Issue
Block a user