|
1 | 1 | 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 | + |
2 | 39 |
|
3 | 40 | SITENAME = "aio-libs" |
4 | 41 | SITEURL = "" |
|
10 | 47 | LOCALE = "en_US.utf8" |
11 | 48 | TIMEZONE = "UTC" |
12 | 49 |
|
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/"), |
16 | 53 | ) |
| 54 | +SPONSORS = tuple({"name": s[0], "img": sponsor_img(s[0]), "url": s[1]} for s in _SPONSORS) |
17 | 55 |
|
18 | 56 | # URL settings |
19 | 57 | FILENAME_METADATA = r"(?P<date>\d{4}-\d{2}-\d{2})_(?P<slug>.*)" |
|
45 | 83 | # Plugins |
46 | 84 | PLUGIN_PATHS = ("plugins",) |
47 | 85 | 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 | +} |
48 | 97 |
|
49 | 98 | # Theme |
50 | 99 | THEME = "theme/" |
|
0 commit comments