|
1 | 1 | {% extends "base.html" %} |
2 | 2 | {% block extrahead %} |
3 | | -{% set ns = namespace(title="", content="", readtime_s="", icon_href="https://guide.pycord.dev/img/logo.png") %} |
4 | | -{% set ns.title = page.meta.title if page.meta and page.meta.title else page.title|striptags %} |
5 | | -{% set ns.content = page.meta.description if page.meta and page.meta.description else config.site_description %} |
6 | | - |
7 | | -{% if page.url %} |
8 | | -{% set chars = page.content|striptags|length %} |
9 | | -{% if chars > 300 %} |
10 | | -{% set minutes = (chars / 1590)|round|int %} |
11 | | -{% if minutes < 1 %}{% set minutes = 1 %}{% endif %} |
12 | | -{% set ns.readtime_s = lang.t("readtime.one") if minutes == 1 else lang.t("readtime.other")|replace("#", minutes|string) %} |
13 | | -{% set stripped = page.content|striptags %} |
14 | | -{% if stripped|length > 250 %} |
15 | | -{% set ns.content = stripped[:247] ~ "..." %} |
16 | | -{% else %} |
17 | | -{% set ns.content = stripped %} |
18 | | -{% endif %} |
19 | | -{% endif %} |
20 | | -{% endif %} |
21 | | -<script id="discord:component-embed" type="application/json"> |
| 3 | + {% set ns = namespace(title="", content="", readtime_s="", icon_href="https://guide.pycord.dev/img/logo.png") %} |
| 4 | + {% set ns.title = page.meta.title if page.meta and page.meta.title else page.title|striptags %} |
| 5 | + {% set ns.content = page.meta.description if page.meta and page.meta.description else config.site_description %} |
| 6 | + {% if page.url %} |
| 7 | + {% set chars = page.content|striptags|length %} |
| 8 | + {% if chars > 300 %} |
| 9 | + {% set minutes = (chars / 1590)|round|int %} |
| 10 | + {% if minutes < 1 %} |
| 11 | + {% set minutes = 1 %} |
| 12 | + {% endif %} |
| 13 | + {% set ns.readtime_s = lang.t("readtime.one") if minutes == 1 else lang.t("readtime.other")|replace("#", minutes|string) %} |
| 14 | + {# Drop the leading <h1>, header-link pilcrows and collapse whitespace #} |
| 15 | + {% set body = page.content|trim %} |
| 16 | + {% if body[:3] == "<h1" %} |
| 17 | + {% set body = (body|split("</h1>", 1)|list)[-1] %} |
| 18 | + {% endif %} |
| 19 | + {% set stripped = body|striptags|replace("¶", "")|split|list|join(" ") %} |
| 20 | + {% if stripped|length > 250 %} |
| 21 | + {# Cut on a word boundary #} |
| 22 | + {% set ns.content = (stripped[:248]|split|list)[:-1]|join(" ") ~ "…" %} |
| 23 | + {% else %} |
| 24 | + {% set ns.content = stripped %} |
| 25 | + {% endif %} |
| 26 | + {% endif %} |
| 27 | + {% endif %} |
| 28 | + <script id="discord:component-embed" type="application/json"> |
22 | 29 | { |
23 | 30 | "component": { |
24 | 31 | "type": 17, |
|
73 | 80 | ] |
74 | 81 | } |
75 | 82 | } |
76 | | -</script> |
| 83 | + </script> |
77 | 84 | {% endblock %} |
0 commit comments