Skip to content

Commit 6b12aee

Browse files
committed
Add sponsors custom tag
1 parent 6faf4ff commit 6b12aee

7 files changed

Lines changed: 61 additions & 11 deletions

File tree

3.04 KB
Loading
Lines changed: 3 additions & 0 deletions
Loading

content/pages/index.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ We are a co-operative of developers who maintain open-source libraries for the P
88

99
Asyncio would not be possible without our amazing sponsors. Please consider joining them to help fund our work. Our finances are entirely transparent and managed by [Open Collective](https://opencollective.com/aio-libs).
1010

11-
> ### Sponsor Card
12-
> ![]({static}/images/aiohttp.svg)
13-
> Blockquotes can be used for featured content blocks I guess. Nice to keep things simple, especially these days am I right?
14-
>
15-
> I usually am.
11+
[SPONSORS]
1612

1713
### Asyncio Cooperative (Totally Fictional)
1814

pelicanconf.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
import logging
2+
import re
3+
from pathlib import Path
4+
5+
from jinja2 import Environment, FileSystemLoader
6+
from markdown import Markdown
7+
from markdown.extensions import Extension
8+
from markdown.extensions.admonition import AdmonitionExtension
9+
from markdown.extensions.meta import MetaExtension
10+
from markdown.extensions.smart import SmartyExtension
11+
from markdown.extensions.toc import TocExtension
12+
from markdown.extensions.wikilinks import WikiLinkExtension
13+
from markdown.inlinepatterns import InlineProcessor
14+
15+
jinja_fragments = Environment(
16+
loader=FileSystemLoader("theme/templates/fragments/"),
17+
autoescape=select_autoescape()
18+
)
19+
sponsor_template = jinja_fragments.get_template("sponsor.html")
20+
SPONSOR_IMG_PATH = Path("content/images/sponsors/")
21+
22+
23+
def sponsor_img(name: str):
24+
name = name.lower().replace(" ", "-")
25+
f = next(SPONSOR_IMG_PATH.glob(name + ".*"))
26+
return "/images/sponsors/" + f.name
27+
28+
29+
class SponsorInlineProcessor(InlineProcessor):
30+
def handleMatch(self, m: re.Match[str], data: str) -> tuple[str, int, int]:
31+
return sponsor_template.render(SPONSORS=SPONSORS), m.start(0), m.end(0)
32+
33+
34+
class SponsorExtension(Extension):
35+
def extendMarkdown(self, md: Markdown) -> None:
36+
processor = SponsorInlineProcessor(r'\[\[SPONSORS\]\]', md)
37+
md.inlinePatterns.register(processor, "sponsor", 200)
38+
239

340
SITENAME = "aio-libs"
441
SITEURL = ""
@@ -10,10 +47,11 @@
1047
LOCALE = "en_US.utf8"
1148
TIMEZONE = "UTC"
1249

13-
SPONSORS = (
14-
("Bill Gates", "http://google.com"),
15-
("TerenceCorp", "http://google.com")
50+
_SPONSORS = (
51+
("Tidelift", "https://tidelift.com/"),
52+
("Open Home Foundation", "https://www.openhomefoundation.org/"),
1653
)
54+
SPONSORS = tuple({"name": s[0], "img": sponsor_img(s[0]), "url": s[1]} for s in _SPONSORS)
1755

1856
# URL settings
1957
FILENAME_METADATA = r"(?P<date>\d{4}-\d{2}-\d{2})_(?P<slug>.*)"
@@ -45,6 +83,17 @@
4583
# Plugins
4684
PLUGIN_PATHS = ("plugins",)
4785
PLUGINS = ("linkclass",)
86+
MARKDOWN = {
87+
"extensions": (
88+
"extra",
89+
AdmonitionExtension(),
90+
MetaExtension(),
91+
SmartyExtension(),
92+
TocExtension(),
93+
WikiLinkExtension(base_url="/projects/", html_class=None),
94+
SponsorExtension(),
95+
),
96+
}
4897

4998
# Theme
5099
THEME = "theme/"

publishconf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from pelicanconf import *
99

1010
RELATIVE_URLS = False
11-
TYPOGRIFY = True
12-
TYPOGRIFY_OMIT_FILTERS = ("amp", "caps", "initial_quotes", "widont",)
1311

1412
FEED_DOMAIN = "https://aio-libs.org"
1513
FEED_ATOM = "feeds/atom.xml"

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Jinja2==3.1.6
2+
Markdown==3.10
13
Pelican[markdown]==4.11.0
24
pelican-linkclass==2.1.6
3-
typogrify==2.1.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% for sponsor in SPONSORS %}
2+
<a href="{{ sponsor.url }}"><img src={{ sponsor.img }} alt="{{ sponsor.name }}" /></a>
3+
{% endfor %}

0 commit comments

Comments
 (0)