Skip to content

Commit e474618

Browse files
committed
feat: Better embeds
1 parent ac0dd93 commit e474618

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

‎overrides/main.html‎

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
{% extends "base.html" %}
22
{% 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">
2229
{
2330
"component": {
2431
"type": 17,
@@ -73,5 +80,5 @@
7380
]
7481
}
7582
}
76-
</script>
83+
</script>
7784
{% endblock %}

0 commit comments

Comments
 (0)