File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed
Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -19,15 +19,18 @@ for file in $(ls *.md | grep -v -i 'README.md' | sort); do
1919 number=" ${BASH_REMATCH[2]} "
2020 title=" ${BASH_REMATCH[5]} "
2121 level=$(( ${# hashes} - 1 ))
22- indent=$( printf ' %.0s ' $( seq 1 $(( level * 2 )) ) )
22+ indent=$( printf ' %*s ' $(( level * 2 )) " " )
2323 anchor=$( echo " $number -$title " | tr ' [:upper:]' ' [:lower:]' | tr ' ' ' -' | tr -cd ' [:alnum:]-' )
2424 echo " ${indent} - [$number . $title ](./$file #$anchor )" >> " $INDEX_TMP "
2525 fi
2626 done < " $file "
2727done
2828
29- # Generate the new README content
30- awk -v table_of_contents=" $( cat $INDEX_TMP ) " ' {gsub(/\[table_of_contents\]/, table_of_contents)}1' " $TEMPLATE " > " $README_TMP "
29+ # Replace [table_of_contents] with generated index
30+ sed " /\[table_of_contents\]/{
31+ r $INDEX_TMP
32+ d
33+ }" " $TEMPLATE " > " $README_TMP "
3134
3235if [[ " $1 " == " --check" ]]; then
3336 if ! diff --color=auto -u " $OUTFILE " " $README_TMP " ; then
@@ -46,4 +49,5 @@ elif [[ "$1" == "--bless" ]]; then
4649else
4750 rm " $INDEX_TMP " " $README_TMP "
4851 echo -e " ${GREEN} No changes made. Use --check to verify or --bless to update README.md.${NC} "
49- fi
52+ fi
53+
Original file line number Diff line number Diff line change 1+
2+ # README Generator Script
3+
4+ This ` generate-readme.sh ` script updates ` README.md ` by generating a Table of Contents (ToC) from all Markdown files in the repository.
5+ It replaces the ` [table_of_contents] ` placeholder in ` README.template.md ` with the generated index.
6+
7+ ## Usage
8+
9+ ``` bash
10+ ./scripts/generate-readme.sh [option]
11+ ```
12+
13+ Options:
14+
15+ * ` --check ` : verify if ` README.md ` is up to date (exit 1 if not).
16+ * ` --bless ` : regenerate and overwrite ` README.md ` .
17+
18+ ## Notes
19+
20+ * ` README.template.md ` must contain ` [table_of_contents] ` .
21+ * Run ` --check ` before committing to ensure the ToC is current.
22+
You can’t perform that action at this time.
0 commit comments