Skip to content

Commit 7d4a47f

Browse files
authored
Update pages.yml
1 parent 6dbf15e commit 7d4a47f

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

.github/workflows/pages.yml

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ jobs:
9292
</html>
9393
TPL
9494
95-
if [ -f index.html ]; then
96-
echo "Keeping existing index.html (not regenerating)."
97-
elif [ -f README.md ]; then
98-
echo "Generating index.html from README.md with a TOC..."
99-
pandoc README.md -f markdown -t html -s \
100-
--template=pandoc_template.html \
101-
-o index.html \
102-
--metadata title="$REPO_HTML_TITLE" \
103-
--toc --toc-depth=6 -V toc-title=""
104-
GENERATED=1
105-
else
106-
echo "No index.html or README.md found; writing minimal page."
107-
printf '%s\n' '<!doctype html><html><head><meta charset="utf-8"><title>Site</title></head><body>' '<h1>Site</h1>' '<p>No README.md found. Add one and push to regenerate this page.</p>' '</body></html>' > index.html
108-
GENERATED=1
109-
fi
110-
11195
# Styles (grid layout + sidebar + nice TOC)
11296
CSS='<style>
11397
html, body { width:100%; max-width:none; margin:0; padding:0; font-family: Arial, Helvetica, sans-serif; color:#222; }
@@ -125,7 +109,6 @@ jobs:
125109
.sidebar nav.toc li { margin:4px 0; }
126110
.sidebar nav.toc a { color:#24292f; text-decoration:none; }
127111
.sidebar nav.toc a:hover { text-decoration:underline; }
128-
.sidebar nav.toc ul ul { padding-left:14px; border-left:2px solid #e5e7eb; margin-left:6px; }
129112
130113
/* TOC indentation rules */
131114
.sidebar nav.toc ul ul { padding-left:14px; border-left:2px solid #e5e7eb; margin-left:6px; }
@@ -145,6 +128,22 @@ jobs:
145128
}
146129
</style>'
147130
131+
# Always rebuild index.html from README.md
132+
if [ -f README.md ]; then
133+
echo "Generating index.html from README.md with a TOC..."
134+
rm -f index.html
135+
pandoc README.md -f markdown -t html -s \
136+
--template=pandoc_template.html \
137+
-o index.html \
138+
--metadata title="$REPO_HTML_TITLE" \
139+
--toc --toc-depth=6 -V toc-title=""
140+
GENERATED=1
141+
else
142+
echo "No README.md found; writing minimal page."
143+
printf '%s\n' '<!doctype html><html><head><meta charset="utf-8"><title>Site</title></head><body>' '<h1>Site</h1>' '<p>No README.md found. Add one and push to regenerate this page.</p>' '</body></html>' > index.html
144+
GENERATED=1
145+
fi
146+
148147
# Inject CSS into <head>
149148
if grep -qi '</head>' index.html; then
150149
awk -v css="$CSS" 'BEGIN{IGNORECASE=1} { if (!done && match(tolower($0), /<\/head>/)) { sub(/<\/head>/, css"</head>"); done=1 } print }' index.html > index.html.tmp
@@ -186,10 +185,17 @@ jobs:
186185
if [ -n "$TOC_INNER" ]; then
187186
# Remove any <h2>Contents</h2> title inside the nav
188187
TOC_CLEAN=$(printf "%s" "$TOC_INNER" | perl -0777 -pe 's|<h[1-6][^>]*>.*?</h[1-6]>||si')
189-
# Inject into sidebar placeholder
190-
awk -v block="$TOC_CLEAN" 'BEGIN{IGNORECASE=1}
191-
{ sub(/<!--SIDEBAR_LINKS-->/, block); print }' index.html > index.html.tmp && mv index.html.tmp index.html
192-
# Remove original nav#TOC from main content
188+
189+
# Inject into sidebar: prefer placeholder; otherwise replace nav.toc contents
190+
if grep -q "<!--SIDEBAR_LINKS-->" index.html; then
191+
awk -v block="$TOC_CLEAN" 'BEGIN{IGNORECASE=1}
192+
{ sub(/<!--SIDEBAR_LINKS-->/, block); print }' index.html > index.html.tmp && mv index.html.tmp index.html
193+
else
194+
# Replace whatever is inside <nav class="toc">...</nav> with the fresh TOC
195+
perl -0777 -pe 's|(<nav\s+class="toc"[^>]*>).*?(</nav>)|$1'"$TOC_CLEAN"'$2|si' -i index.html
196+
fi
197+
198+
# Remove original nav#TOC from main content if it exists
193199
perl -0777 -pe 's|<nav\s+id="TOC"[^>]*>.*?</nav>||si' -i index.html
194200
else
195201
echo "No TOC found; leaving sidebar placeholder empty."

0 commit comments

Comments
 (0)