Skip to content

Commit 51c7d5c

Browse files
committed
feat: generated embed cards and title
1 parent 2bd1d44 commit 51c7d5c

2 files changed

Lines changed: 30 additions & 3 deletions

File tree

generate.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import re
66
import markdown
77

8+
SUMMARY_MAX = 200
9+
810
# Markdown to HTML conversion functions
911
def mdspan(md, classname=None):
1012
html = markdown.markdown(md)
@@ -31,9 +33,8 @@ def read_section(path):
3133
ent_path = os.path.join(path, ent)
3234
if not os.path.isfile(ent_path): continue
3335
if not ent_path.endswith(".md") and not ent_path.endswith(".html"): continue
34-
out += "\n"
3536
basename = os.path.splitext(ent_path)[0]
36-
out += read_section(basename)
37+
out += "\n" + read_section(basename)
3738

3839
if os.path.isfile(f"{path}.cats"):
3940
out += '<div class="categories">'
@@ -151,12 +152,27 @@ def _repl(m):
151152

152153
md_str = _replace_timestamp_tokens(md_str)
153154

155+
title = "Portal 2 Rules"
156+
if page != "index":
157+
title_match = re.search(r'^#+ (.*)', md_str)
158+
if title_match:
159+
title = title_match.group(1)
160+
161+
desc = "This page covers " + title + ". Find more info in the Portal 2 Speedrunning Discord at https://s.portal2.sr/discord"
162+
desc_match = re.search(r'(^[^#].*)', re.sub(r'\n+', '\n', re.sub(r'\n([^\n])', r' \1', md_str).strip()), flags=re.MULTILINE)
163+
if desc_match:
164+
desc = desc_match.group(1).strip()
165+
if len(desc) > SUMMARY_MAX:
166+
desc = desc[:SUMMARY_MAX - 3] + "..."
167+
154168
content = md.convert(md_str)
155169
content = re.sub(r'<a href="/', f'<a href="/', content)
156170
content = re.sub(r'<a href="', f'<a target="_blank" href="', content)
157171
content = re.sub(r'<a href="/', f'<a href="/', content)
158172

159173
out = (template
174+
.replace("{{PAGE_TITLE}}", re.sub(r'\"', '&quot;', title))
175+
.replace("{{PAGE_DESC}}", re.sub(r'\"', '&quot;', desc))
160176
.replace("{{CONTENT}}", content)
161177
.replace("{{NAV_MENU}}", generate_nav(page, md.toc_tokens))
162178
.replace("{{COMMAND_LIST}}", commands)

template.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,21 @@
44
<head>
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Portal 2 Rules</title>
7+
<title>{{PAGE_TITLE}}</title>
88
<link rel="stylesheet" href="/style.css" type="text/css">
99
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css" type="text/css">
1010
<link rel="icon" type="image/png" href="https://avatars.githubusercontent.com/u/83299896" />
11+
<meta property="og:locale" content="en_US">
12+
<meta property="og:site_name" content="Portal 2 Rules">
13+
<meta property="og:type" content="website">
14+
<meta name="twitter:card" content="summary">
15+
<meta property="og:image" content="https://avatars.githubusercontent.com/u/83299896">
16+
<meta name="twitter:image" content="https://avatars.githubusercontent.com/u/83299896">
17+
<meta property="og:title" content="{{PAGE_TITLE}}">
18+
<meta name="twitter:title" content="{{PAGE_TITLE}}">
19+
<meta name="description" content="{{PAGE_DESC}}">
20+
<meta property="og:description" content="{{PAGE_DESC}}">
21+
<meta name="twitter:description" content="{{PAGE_DESC}}">
1122
</head>
1223

1324
<body>

0 commit comments

Comments
 (0)