|
14 | 14 | # import sys |
15 | 15 | # sys.path.insert(0, os.path.abspath('.')) |
16 | 16 |
|
| 17 | +from ablog.blog import Blog |
| 18 | +from docutils import nodes |
| 19 | +from sphinx.errors import ExtensionError |
| 20 | + |
17 | 21 |
|
18 | 22 | # -- Project information ----------------------------------------------------- |
19 | 23 |
|
|
198 | 202 |
|
199 | 203 | linkcheck_ignore = [ |
200 | 204 | # Sphinx-gallery output files only exist after a full HTML build, not during linkcheck |
201 | | - ".*/*_examples/.*\.html", |
| 205 | + r".*/*_examples/.*\.html", |
202 | 206 | "https://neuromorpho.org/", |
203 | 207 | "https://brainglobe.zulipchat.com/#narrow/stream/414089-developer-meeting", |
204 | 208 | "https://easyengine.io", |
|
224 | 228 | "Authorization": f"Bearer {os.environ.get('GITHUB_TOKEN', '')}", |
225 | 229 | }, |
226 | 230 | } |
| 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