55import re
66import markdown
77
8+ SUMMARY_MAX = 200
9+
810# Markdown to HTML conversion functions
911def 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'\"' , '"' , title ))
175+ .replace ("{{PAGE_DESC}}" , re .sub (r'\"' , '"' , desc ))
160176 .replace ("{{CONTENT}}" , content )
161177 .replace ("{{NAV_MENU}}" , generate_nav (page , md .toc_tokens ))
162178 .replace ("{{COMMAND_LIST}}" , commands )
0 commit comments