Skip to content

Commit 985dea6

Browse files
committed
Added RSS feed.
1 parent fcdd312 commit 985dea6

6 files changed

Lines changed: 41 additions & 12 deletions

File tree

‎.github/workflows/build_pages.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ jobs:
2121
pip install mkdocs-include-markdown-plugin
2222
pip install mike
2323
pip install mkdocs-git-committers-plugin-2
24+
pip install mkdocs-rss-plugin
2425
- name: Build website
2526
run: mkdocs gh-deploy --verbose

‎README.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,20 @@ Related configuration:
6363
The hook is plain Python run by MkDocs itself - no extra package needs to be installed.
6464
Note that it relies on MkDocs hooks and on internals of the Material blog plugin, so it needs to be revisited when upgrading Material or migrating to [Zensical](https://zensical.org/).
6565

66+
## RSS feed
67+
68+
Announcements are published as RSS and JSON feeds by the [mkdocs-rss-plugin](https://guts.github.io/mkdocs-rss-plugin/), configured under `rss:` in [mkdocs.yml](mkdocs.yml):
69+
70+
- [feed_rss_created.xml](https://www.utplsql.org/feed_rss_created.xml) - newest posts first (the one to subscribe to),
71+
- [feed_rss_updated.xml](https://www.utplsql.org/feed_rss_updated.xml) - most recently updated posts first,
72+
- `feed_json_created.json` and `feed_json_updated.json` - the same as [JSON Feed](https://www.jsonfeed.org/).
73+
74+
Only posts under `docs/announcements/posts/` are included (`match_path`), up to 20 newest.
75+
Dates come from `date.created` / `date.updated` in the post front matter (git history is used when `date.updated` is missing), and `categories` become RSS categories.
76+
The item description is the post `description:` or the summary generated by [hooks/latest_posts.py](hooks/latest_posts.py) - the same text as on the home page card.
77+
78+
The feeds are linked from the home page, the Announcements page and the RSS icon in the footer, and Material adds `<link rel="alternate" type="application/rss+xml">` to every page, so feed readers find them automatically.
79+
6680
## Local setup
6781

6882
If you want to generate and preview the website locally, you will need to have [python and pip installed](https://squidfunk.github.io/mkdocs-material/getting-started/))
@@ -73,6 +87,7 @@ pip install mkdocs-material
7387
pip install mkdocs-git-revision-date-localized-plugin
7488
pip install mkdocs-include-markdown-plugin
7589
pip install mkdocs-git-committers-plugin-2
90+
pip install mkdocs-rss-plugin
7691
pip install mike
7792
```
7893

‎docs/announcements/index.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
# Announcements
2+
3+
[:material-rss: Subscribe via RSS](/feed_rss_created.xml)

‎docs/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Write and run tests directly in PL/SQL, integrate with your CI/CD pipeline, and
1414

1515
<!-- latest-posts -->
1616

17-
[All announcements :octicons-arrow-right-24:](announcements/index.md)
17+
[All announcements :octicons-arrow-right-24:](announcements/index.md) · [:material-rss: RSS feed](/feed_rss_created.xml)
1818

1919
---
2020

‎hooks/latest_posts.py‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
3. the list items (release notes), without author, PR and issue references.
1212
1313
Posts without a `description:` also get the generated summary as their
14-
`<meta name="description">`.
14+
`<meta name="description">` and RSS feed item description.
1515
"""
1616
import posixpath
1717
import re
@@ -51,6 +51,12 @@
5151

5252

5353
def on_page_markdown(markdown, page, config, files):
54+
# Set before the page is rendered, so the RSS plugin picks it up as well
55+
if isinstance(page, Post) and not page.meta.get("description"):
56+
summary = _summary(page)
57+
if summary:
58+
page.meta["description"] = re.sub(r"`|\*\*", "", summary)
59+
page.meta["description_generated"] = True
5460
if PLACEHOLDER not in markdown:
5561
return markdown
5662
blog = config.plugins["material/blog"].blog
@@ -61,15 +67,6 @@ def on_page_markdown(markdown, page, config, files):
6167
return markdown.replace(PLACEHOLDER, html)
6268

6369

64-
# Runs after Markdown of all pages is processed, so the cards are not affected
65-
def on_page_context(context, page, config, nav):
66-
if isinstance(page, Post) and not page.meta.get("description"):
67-
summary = _summary(page)
68-
if summary:
69-
page.meta["description"] = re.sub(r"`|\*\*", "", summary)
70-
return context
71-
72-
7370
def _card(post, link):
7471
categories = post.config.categories
7572
icon = next((ICONS[c] for c in categories if c in ICONS), DEFAULT_ICON)
@@ -87,7 +84,8 @@ def _card(post, link):
8784

8885

8986
def _summary(post):
90-
if post.meta.get("description"):
87+
# A generated description is plain text - rebuild it, so cards keep code formatting
88+
if post.meta.get("description") and not post.meta.get("description_generated"):
9189
return _truncate(_plain(post.meta["description"]))
9290
body = SETEXT_HEADING.sub("", post.markdown)
9391
first_item = LIST_ITEM.search(body)

‎mkdocs.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ extra:
7575
link: https://github.com/utPLSQL
7676
- icon: fontawesome/solid/envelope
7777
link: mailto:utPLSQL@utPLSQL.org
78+
- icon: fontawesome/solid/rss
79+
link: https://www.utplsql.org/feed_rss_created.xml
80+
name: Announcements RSS feed
7881
consent:
7982
title: Cookie consent
8083
description: >-
@@ -126,6 +129,16 @@ plugins:
126129
post_url_format: "{slug}" # keeps URLs clean
127130
archive: false
128131
categories: true
132+
- rss:
133+
match_path: "announcements/posts/.*"
134+
feed_title: "utPLSQL Announcements"
135+
feed_description: "Releases and news from the utPLSQL project"
136+
image: https://www.utplsql.org/assets/icon-transparent.png
137+
date_from_meta:
138+
as_creation: date.created
139+
as_update: date.updated
140+
categories:
141+
- categories
129142
nav:
130143
- Home: index.md
131144
- Announcements:

0 commit comments

Comments
 (0)