@@ -178,12 +178,18 @@ jobs:
178178 fi
179179
180180 # === Extract Pandoc TOC and move it into the sidebar ===
181- # Grab inner HTML of <nav id="TOC"> ... </nav>
182- TOC_INNER=$(perl -0777 -ne 'if (m|<nav\s+id="TOC"[^>]*>(.*?)</nav>|si){print $1}' index.html || true)
181+ # Try several known selectors for Pandoc's TOC output
182+ TOC_INNER=$(perl -0777 -ne 'if (m|<(nav|div)\s+[^>]*(id="TOC"|role="doc-toc")[^>]*>(.*?)</\1>|si){print $3} elsif (m|<nav\s+id="TOC"[^>]*>(.*?)</nav>|si){print $1} elsif (m|<nav\s+role="doc-toc"[^>]*>(.*?)</nav>|si){print $1}' index.html || true)
183+
184+ # Count how many README headings will be eligible (for diagnostics)
185+ if [ -f README.md ]; then
186+ HCOUNT=$(grep -E '^\s{0,3}#{1,6}\s' README.md | wc -l | tr -d ' ')
187+ else
188+ HCOUNT=0
189+ fi
183190
184- # If a TOC exists, clean it and inject; then remove original TOC
185191 if [ -n "$TOC_INNER" ]; then
186- # Remove any <h2>Contents</h2> title inside the nav
192+ # Remove any heading labels inside the toc block
187193 TOC_CLEAN=$(printf "%s" "$TOC_INNER" | perl -0777 -pe 's|<h[1-6][^>]*>.*?</h[1-6]>||si')
188194
189195 # Inject into sidebar: prefer placeholder; otherwise replace nav.toc contents
@@ -195,10 +201,29 @@ jobs:
195201 perl -0777 -pe 's|(<nav\s+class="toc"[^>]*>).*?(</nav>)|$1'"$TOC_CLEAN"'$2|si' -i index.html
196202 fi
197203
198- # Remove original nav#TOC from main content if it exists
199- perl -0777 -pe 's|<nav\s+id="TOC"[^>]*>.*?</nav>||si' -i index.html
204+ # Remove original TOC from main content if it exists
205+ perl -0777 -pe 's|<(nav|div)\s+(id="TOC"|role="doc-toc")[^>]*>.*?</\1>||si' -i index.html
206+
207+ echo "TOC extracted and injected; README headings: $HCOUNT"
208+ {
209+ echo "### Sidebar TOC status"
210+ echo ""
211+ echo "- README headings detected: $HCOUNT"
212+ echo "- TOC injected into sidebar ✅"
213+ } >> "$GITHUB_STEP_SUMMARY"
200214 else
201215 echo "No TOC found; leaving sidebar placeholder empty."
216+ {
217+ echo "### Sidebar TOC status"
218+ echo ""
219+ echo "- README headings detected: $HCOUNT"
220+ echo "- Pandoc TOC not found in built HTML ❌"
221+ echo ""
222+ echo "Hints:"
223+ echo "1) Ensure your README uses Markdown ATX headings like: #, ##, ###"
224+ echo "2) Headings inside HTML blocks or code fences are ignored"
225+ echo "3) Confirm this job installed Pandoc and used --toc --toc-depth=6"
226+ } >> "$GITHUB_STEP_SUMMARY"
202227 fi
203228
204229 # Replace any placeholders, just in case
@@ -314,3 +339,4 @@ jobs:
314339 run : |
315340 echo "### Deployed Pages URL" >> "$GITHUB_STEP_SUMMARY"
316341 echo "${{ steps.deployment.outputs.page_url }}" >> "$GITHUB_STEP_SUMMARY"
342+
0 commit comments