Skip to content

Commit 41318c5

Browse files
committed
fix
1 parent f409f3b commit 41318c5

4 files changed

Lines changed: 97 additions & 3 deletions

File tree

.github/toc-generator.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TOC Generator Configuration
2+
3+
# TOC settings
4+
TOC_TITLE: "## Table of Contents"
5+
FOLDING: false
6+
MAX_HEADER_LEVEL: 4
7+
8+
# Marker comment settings
9+
OPENING_COMMENT: "<!-- toc -->"
10+
CLOSING_COMMENT: "<!-- tocstop -->"

.github/workflows/update-toc.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ jobs:
1616
update-toc:
1717
runs-on: ubuntu-latest
1818
steps:
19-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
2020
with:
2121
fetch-depth: 0
22-
token: ${{ secrets.TOC_TOKEN }}
22+
token: ${{ github.token }}
2323

2424
- name: Generate TOC
2525
uses: technote-space/toc-generator@v4
2626
with:
27-
GITHUB_TOKEN: ${{ secrets.TOC_TOKEN }}
27+
GITHUB_TOKEN: ${{ github.token }}
2828
TOC_TITLE: "## Table of Contents"
2929
TARGET_PATHS: "group-syllabus/*.md"
3030
FOLDING: false

scripts/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Documentation Scripts
2+
3+
This directory contains utility scripts for maintaining the group documentation.
4+
5+
## Available Scripts
6+
7+
### add-toc-markers.sh
8+
9+
This script adds TOC markers to markdown files that have a "## Table of Contents" heading.
10+
11+
#### Usage
12+
13+
```bash
14+
./scripts/add-toc-markers.sh <file.md> [file2.md ...]
15+
```
16+
17+
Example:
18+
```bash
19+
# Add TOC markers to a specific file
20+
./scripts/add-toc-markers.sh group-syllabus/formatting.md
21+
22+
# Add TOC markers to all markdown files in group-syllabus
23+
./scripts/add-toc-markers.sh group-syllabus/*.md
24+
```
25+
26+
The script will:
27+
1. Look for files with a "## Table of Contents" heading
28+
2. Add `<!-- toc -->` and `<!-- tocstop -->` markers around the TOC
29+
3. Skip files that already have TOC markers
30+
31+
These markers are used by the GitHub Action workflow to automatically update the table of contents.

scripts/add-toc-markers.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# This script adds TOC markers to markdown files that have a "## Table of Contents" heading
4+
5+
# Check if a file path is provided
6+
if [ "$#" -eq 0 ]; then
7+
echo "Usage: $0 <file.md> [file2.md ...]"
8+
echo "Example: $0 group-syllabus/*.md"
9+
exit 1
10+
fi
11+
12+
# Process each file provided as an argument
13+
for file in "$@"; do
14+
# Check if file exists
15+
if [ -f "$file" ]; then
16+
echo "Processing $file..."
17+
18+
# Check if the file already has TOC markers
19+
if grep -q "<!-- toc -->" "$file"; then
20+
echo " TOC markers already exist in $file, skipping..."
21+
continue
22+
fi
23+
24+
# Find the line with "## Table of Contents"
25+
toc_line=$(grep -n "^## Table of Contents" "$file" | cut -d: -f1)
26+
27+
if [ -n "$toc_line" ]; then
28+
# Create a temporary file
29+
temp_file=$(mktemp)
30+
31+
# Extract content before TOC line
32+
head -n "$toc_line" "$file" > "$temp_file"
33+
34+
# Add TOC markers
35+
echo "<!-- toc -->" >> "$temp_file"
36+
echo "<!-- tocstop -->" >> "$temp_file"
37+
38+
# Extract content after TOC line
39+
tail -n +$((toc_line + 1)) "$file" >> "$temp_file"
40+
41+
# Replace original file
42+
mv "$temp_file" "$file"
43+
44+
echo " Added TOC markers to $file"
45+
else
46+
echo " No '## Table of Contents' found in $file"
47+
fi
48+
else
49+
echo "File $file does not exist"
50+
fi
51+
done
52+
53+
echo "Done adding TOC markers"

0 commit comments

Comments
 (0)