|
40 | 40 | match = re.search(pattern, readme_md, re.M | re.S) |
41 | 41 | extracted[key] = match.group(1) if match else "" |
42 | 42 |
|
43 | | -# Convert markdown to HTML |
44 | | -meta_html = markdown.markdown(meta_md) |
45 | | -section_html = {k: markdown.markdown(v) for k, v in extracted.items()} |
| 43 | + |
| 44 | +# Extract meta tags, schema.org, and Open Graph from META.md |
| 45 | +meta_tags = [] |
| 46 | +schema_org = [] |
| 47 | +open_graph = [] |
| 48 | +for line in meta_md.splitlines(): |
| 49 | + if line.strip().startswith('<meta '): |
| 50 | + meta_tags.append(line.strip()) |
| 51 | + elif line.strip().startswith('<script '): |
| 52 | + schema_org.append(line.strip()) |
| 53 | + elif line.strip().startswith('<meta property="og:'): |
| 54 | + open_graph.append(line.strip()) |
| 55 | + |
| 56 | +# Compose meta head HTML |
| 57 | +meta_head_html = '\n'.join(meta_tags + schema_org + open_graph) |
| 58 | + |
| 59 | + |
| 60 | +# Convert markdown to HTML for README sections |
| 61 | +section_html = {} |
| 62 | +for k, v in extracted.items(): |
| 63 | + if k == "project-structure": |
| 64 | + # Find code block in markdown and wrap in div |
| 65 | + code_block = re.search(r'```([\s\S]+?)```', v) |
| 66 | + if code_block: |
| 67 | + html_block = f'<div class="project-structure-block">{code_block.group(1).strip()}</div>' |
| 68 | + # Remove code block from markdown and add after |
| 69 | + v_no_code = re.sub(r'```[\s\S]+?```', '', v) |
| 70 | + section_html[k] = markdown.markdown(v_no_code) + html_block |
| 71 | + else: |
| 72 | + section_html[k] = markdown.markdown(v) |
| 73 | + elif k == "core-commands": |
| 74 | + # Render markdown table as HTML table |
| 75 | + section_html[k] = markdown.markdown(v, extensions=["markdown.extensions.tables"]) |
| 76 | + else: |
| 77 | + section_html[k] = markdown.markdown(v) |
46 | 78 |
|
47 | 79 | # Read index.html template |
48 | 80 | html = index_path.read_text() if index_path.exists() else "" |
49 | 81 |
|
50 | | -# Replace sections |
51 | | -html = re.sub(r"<section id=\"meta\">.*?</section>", f"<section id=\"meta\">{meta_html}</section>", html, flags=re.S) |
| 82 | +# Replace META_HEAD placeholder in <head> |
| 83 | +html = re.sub(r'<!-- META_HEAD -->', meta_head_html, html) |
| 84 | + |
| 85 | +# Replace README sections in body |
52 | 86 | html = re.sub(r"<section id=\"readme-intro\">.*?</section>", f"<section id=\"readme-intro\">{section_html.get('intro','')}</section>", html, flags=re.S) |
53 | 87 | html = re.sub(r"<section id=\"readme-usage\">.*?</section>", f"<section id=\"readme-usage\">{section_html.get('quick-start','')}</section>", html, flags=re.S) |
54 | 88 | html = re.sub(r"<section id=\"readme-other\">.*?</section>", f"<section id=\"readme-other\">{section_html.get('core-commands','')}{section_html.get('project-structure','')}{section_html.get('cli-skeleton','')}{section_html.get('status-command','')}{section_html.get('importing-system-caddyfiles','')}{section_html.get('privileged-helper','')}{section_html.get('admin-api-probe','')}{section_html.get('interactive-menu','')}{section_html.get('database-schema','')}{section_html.get('import-export-hooks','')}{section_html.get('example-workflow','')}{section_html.get('how-to-run-locally','')}{section_html.get('publishing-to-pypi','')}{section_html.get('wishlist','')}</section>", html, flags=re.S) |
|
0 commit comments