Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,21 @@ html[data-theme=dark] .bd-main img {
flex-wrap: wrap;
justify-content: space-between;
}

.blog-post-author {
border-left: 3px solid var(--pst-color-primary);
color: var(--pst-color-text-muted);
font-size: 1.12rem;
line-height: 1.5;
margin-top: -0.2rem;
margin-bottom: 2rem;
padding-left: 0.8rem;
}

.blog-post-author a {
font-weight: 600;
}

.blog-post-author .line:nth-child(2) {
font-size: 1rem;
}
58 changes: 58 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
# import sys
# sys.path.insert(0, os.path.abspath('.'))

from ablog.blog import Blog
from docutils import nodes
from sphinx.errors import ExtensionError


# -- Project information -----------------------------------------------------

Expand Down Expand Up @@ -95,6 +99,60 @@
"Authorization": f"Bearer {os.environ.get('GITHUB_TOKEN', '')}",
},
}


def add_blog_author_byline(app, doctree, docname):
"""Add ABlog author metadata to individual blog post pages."""
posts = getattr(app.env, "ablog_posts", {}).get(docname, [])
if len(posts) != 1:
return

post = posts[0]
authors = post.get("author", [])
date = post.get("date")
if not authors or not date:
raise ExtensionError(
f"Blog post '{docname}' must define both author and date metadata."
)

byline = nodes.line_block(classes=["blog-post-author"])

if authors:
author_line = nodes.line()
author_line += nodes.Text("By ")

blog = Blog(app)
author_catalog = blog.catalogs["author"].collections
for index, author in enumerate(authors):
if index:
author_line += nodes.Text(", ")

author_page = author_catalog.get(author)
if author_page is None:
author_line += nodes.Text(author)
continue

author_line += nodes.reference(
"",
author,
refuri=app.builder.get_relative_uri(docname, author_page.docname),
)

byline += author_line

if date:
byline += nodes.line(text=date.strftime(app.config["post_date_format"]))

for section in doctree.findall(nodes.section):
if section.children and isinstance(section.children[0], nodes.title):
section.insert(1, byline)
return


def setup(app):
app.connect("doctree-resolved", add_blog_author_byline)


# Suppress strikethrough warnings - strikethrough is only supported in HTML
suppress_warnings = ['myst.strikethrough']

Expand Down
Loading