Skip to content

Commit 87a1ab4

Browse files
authored
Update pages.yml
1 parent 3f9a5ef commit 87a1ab4

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

.github/workflows/pages.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
PAGES_URL="https://${OWNER}.github.io/${REPO_NAME}/"
7272
fi
7373
74-
# Minimal Pandoc template (now includes $toc$)
74+
# Minimal Pandoc template — CORRECT TOC PLACEHOLDER
7575
cat > pandoc_template.html <<'TPL'
7676
<!doctype html>
7777
<html>
@@ -84,8 +84,15 @@ jobs:
8484
$for(include-before)$
8585
$include-before$
8686
$endfor$
87-
$toc$
87+
88+
$if(toc)$
89+
<nav id="TOC" role="doc-toc">
90+
$table-of-contents$
91+
</nav>
92+
$endif$
93+
8894
$body$
95+
8996
$for(include-after)$
9097
$include-after$
9198
$endfor$
@@ -133,7 +140,7 @@ jobs:
133140
if [ -f README.md ]; then
134141
echo "Generating index.html from README.md with a TOC..."
135142
rm -f index.html
136-
pandoc README.md -f markdown -t html -s \
143+
pandoc README.md -f gfm+yaml_metadata_block -t html -s \
137144
--template=pandoc_template.html \
138145
-o index.html \
139146
--metadata title="$REPO_HTML_TITLE" \
@@ -183,30 +190,25 @@ jobs:
183190
grep -niE '<nav[^>]+(id="TOC"|role="doc-toc"|class="[^"]*toc[^"]*")' index.html || echo "TOC not found pre-extraction"
184191
185192
# === Extract Pandoc TOC and move it into the sidebar ===
186-
# Try several known selectors for Pandoc's TOC output
187193
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)
188194
189-
# Count how many README headings will be eligible (for diagnostics)
195+
# Count README headings (diagnostics)
190196
if [ -f README.md ]; then
191197
HCOUNT=$(grep -E '^\s{0,3}#{1,6}\s' README.md | wc -l | tr -d ' ')
192198
else
193199
HCOUNT=0
194200
fi
195201
196202
if [ -n "$TOC_INNER" ]; then
197-
# Remove any heading labels inside the toc block
198203
TOC_CLEAN=$(printf "%s" "$TOC_INNER" | perl -0777 -pe 's|<h[1-6][^>]*>.*?</h[1-6]>||si')
199204
200-
# Inject into sidebar: prefer placeholder; otherwise replace nav.toc contents
201205
if grep -q "<!--SIDEBAR_LINKS-->" index.html; then
202206
awk -v block="$TOC_CLEAN" 'BEGIN{IGNORECASE=1}
203207
{ sub(/<!--SIDEBAR_LINKS-->/, block); print }' index.html > index.html.tmp && mv index.html.tmp index.html
204208
else
205-
# Replace whatever is inside <nav class="toc">...</nav> with the fresh TOC
206209
perl -0777 -pe 's|(<nav\s+class="toc"[^>]*>).*?(</nav>)|$1'"$TOC_CLEAN"'$2|si' -i index.html
207210
fi
208211
209-
# Remove original TOC from main content if it exists
210212
perl -0777 -pe 's|<(nav|div)\s+(id="TOC"|role="doc-toc")[^>]*>.*?</\1>||si' -i index.html
211213
212214
echo "TOC extracted and injected; README headings: $HCOUNT"
@@ -250,7 +252,6 @@ jobs:
250252
OWNER: ${{ github.repository_owner }}
251253
run: |
252254
set -e
253-
254255
REPO_NAME="${REPO#*/}"
255256
REPO_URL="https://github.com/$REPO"
256257
if [ "$REPO_NAME" = "${OWNER}.github.io" ]; then

0 commit comments

Comments
 (0)