Skip to content

Commit 1a86aeb

Browse files
committed
feat: improved build.py for project structure/code/table rendering; style.css now matches GitHub for code blocks and tables
1 parent 01e4ce1 commit 1a86aeb

File tree

2 files changed

+93
-18
lines changed

2 files changed

+93
-18
lines changed

pages/build.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,49 @@
4040
match = re.search(pattern, readme_md, re.M | re.S)
4141
extracted[key] = match.group(1) if match else ""
4242

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)
4678

4779
# Read index.html template
4880
html = index_path.read_text() if index_path.exists() else ""
4981

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
5286
html = re.sub(r"<section id=\"readme-intro\">.*?</section>", f"<section id=\"readme-intro\">{section_html.get('intro','')}</section>", html, flags=re.S)
5387
html = re.sub(r"<section id=\"readme-usage\">.*?</section>", f"<section id=\"readme-usage\">{section_html.get('quick-start','')}</section>", html, flags=re.S)
5488
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)

pages/style.css

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,64 @@
11
/* Basic style for caddy-tui pages site */
2-
body {
3-
font-family: system-ui, sans-serif;
4-
background: #f9f9f6;
5-
color: #222;
6-
margin: 0;
7-
padding: 0;
8-
}
9-
10-
h1,
11-
h2,
12-
h3 {
2+
h1, h2, h3 {
3+
h1, h2, h3 {
134
color: #2a4d69;
145
}
15-
166
.container {
177
max-width: 800px;
188
margin: 2rem auto;
199
padding: 2rem;
2010
background: #fff;
2111
border-radius: 8px;
22-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
12+
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
13+
}
14+
15+
/* Code blocks and inline code (GitHub style) */
16+
pre, code {
17+
font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'monospace';
18+
background: #f6f8fa;
19+
color: #24292f;
20+
border-radius: 6px;
21+
}
22+
pre {
23+
padding: 1em;
24+
margin: 1em 0;
25+
overflow-x: auto;
26+
font-size: 0.95em;
27+
border: 1px solid #e1e4e8;
28+
}
29+
code {
30+
padding: 0.2em 0.4em;
31+
font-size: 0.95em;
32+
border: 1px solid #e1e4e8;
33+
}
34+
35+
/* Markdown tables (core commands) */
36+
table {
37+
border-collapse: collapse;
38+
width: 100%;
39+
margin: 1em 0;
40+
background: #fff;
41+
}
42+
th, td {
43+
border: 1px solid #e1e4e8;
44+
padding: 0.5em 0.75em;
45+
text-align: left;
46+
font-size: 0.97em;
47+
}
48+
th {
49+
background: #f6f8fa;
50+
font-weight: 600;
51+
}
52+
53+
/* Project structure block */
54+
.project-structure-block {
55+
background: #f6f8fa;
56+
border-radius: 6px;
57+
border: 1px solid #e1e4e8;
58+
padding: 1em;
59+
font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'monospace';
60+
font-size: 0.97em;
61+
margin: 1em 0;
62+
white-space: pre;
63+
overflow-x: auto;
2364
}

0 commit comments

Comments
 (0)