Skip to content

Commit 6a43cc6

Browse files
authored
add names to blog post (#496)
* add names to blog post * Delete docs/conf.py * reject authorless dateless blogs
1 parent 81be2c1 commit 6a43cc6

2 files changed

Lines changed: 75 additions & 1 deletion

File tree

docs/source/_static/css/custom.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ body .bd-article-container {
6363
line-height: 1.3;
6464
margin-bottom: 0 !important;
6565
}
66+
67+
.blog-post-author {
68+
border-left: 3px solid var(--pst-color-primary);
69+
color: var(--pst-color-text-muted);
70+
font-size: 1.12rem;
71+
line-height: 1.5;
72+
margin-top: -0.2rem;
73+
margin-bottom: 2rem;
74+
padding-left: 0.8rem;
75+
}
76+
77+
.blog-post-author a {
78+
font-weight: 600;
79+
}
80+
81+
.blog-post-author .line:nth-child(2) {
82+
font-size: 1rem;
83+
}

docs/source/conf.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
# import sys
1515
# sys.path.insert(0, os.path.abspath('.'))
1616

17+
from ablog.blog import Blog
18+
from docutils import nodes
19+
from sphinx.errors import ExtensionError
20+
1721

1822
# -- Project information -----------------------------------------------------
1923

@@ -198,7 +202,7 @@
198202

199203
linkcheck_ignore = [
200204
# Sphinx-gallery output files only exist after a full HTML build, not during linkcheck
201-
".*/*_examples/.*\.html",
205+
r".*/*_examples/.*\.html",
202206
"https://neuromorpho.org/",
203207
"https://brainglobe.zulipchat.com/#narrow/stream/414089-developer-meeting",
204208
"https://easyengine.io",
@@ -224,3 +228,55 @@
224228
"Authorization": f"Bearer {os.environ.get('GITHUB_TOKEN', '')}",
225229
},
226230
}
231+
232+
233+
def add_blog_author_byline(app, doctree, docname):
234+
"""Add ABlog author metadata to individual blog post pages."""
235+
posts = getattr(app.env, "ablog_posts", {}).get(docname, [])
236+
if len(posts) != 1:
237+
return
238+
239+
post = posts[0]
240+
authors = post.get("author", [])
241+
date = post.get("date")
242+
if not authors or not date:
243+
raise ExtensionError(
244+
f"Blog post '{docname}' must define both author and date metadata."
245+
)
246+
247+
byline = nodes.line_block(classes=["blog-post-author"])
248+
249+
if authors:
250+
author_line = nodes.line()
251+
author_line += nodes.Text("By ")
252+
253+
blog = Blog(app)
254+
author_catalog = blog.catalogs["author"].collections
255+
for index, author in enumerate(authors):
256+
if index:
257+
author_line += nodes.Text(", ")
258+
259+
author_page = author_catalog.get(author)
260+
if author_page is None:
261+
author_line += nodes.Text(author)
262+
continue
263+
264+
author_line += nodes.reference(
265+
"",
266+
author,
267+
refuri=app.builder.get_relative_uri(docname, author_page.docname),
268+
)
269+
270+
byline += author_line
271+
272+
if date:
273+
byline += nodes.line(text=date.strftime(app.config["post_date_format"]))
274+
275+
for section in doctree.findall(nodes.section):
276+
if section.children and isinstance(section.children[0], nodes.title):
277+
section.insert(1, byline)
278+
return
279+
280+
281+
def setup(app):
282+
app.connect("doctree-resolved", add_blog_author_byline)

0 commit comments

Comments
 (0)