Skip to content

Commit 56940ca

Browse files
committed
Add table of contents update to readme update script
1 parent f9d0b9c commit 56940ca

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

scripts/update_readme_methods.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,19 @@ echo '```' >> "README.md"
2626
echo >> "README.md"
2727

2828
echo "${after}" >> "README.md"
29+
30+
# Update table of contents.
31+
script=$(cat <<'EOF'
32+
$data = file_get_contents('README.md');
33+
preg_match_all('/^### ([\w ]+)/m', $data, $matches);
34+
$toc = array();
35+
foreach ($matches['1'] as $match) {
36+
$href = '#' . str_replace(' ', '-', strtolower($match));
37+
$toc[] = '- [' . $match . '](' . $href . ')';
38+
}
39+
$toc = implode("\n", $toc);
40+
$toc = '---' . "\n\n" . $toc . "\n\n" . '---' . "\n\n";
41+
$data = preg_replace('/---\n\n(?:- .*\n)+?\n---\n\n/', $toc, $data);
42+
file_put_contents('README.md', $data);
43+
EOF)
44+
php --run "${script}"

0 commit comments

Comments
 (0)