Last active
July 30, 2021 16:59
-
-
Save monkpit/a1709899ce633a0e383c9214c2f838df to your computer and use it in GitHub Desktop.
Build Markdown TOC for entire repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
# Made to work on Mac version of `stat` | |
rm -f readme.md | |
# Static header contents go in readme.header.md | |
cat readme.header.md >> readme.md | |
mdFiles=$(find ./*/ -name \*.md) | |
for mdFile in $mdFiles; do | |
# we will just take the first line that starts with "# " | |
# then strip off the "# " and we just assume that's a good title | |
title=$(sed -n "s/^# \(.*\)/\1/p" "$mdFile") | |
updated=$(stat -f "%Sm" "$mdFile") | |
printf "* [%s](%s) - updated %s\n" "$title" "$mdFile" "$updated" >> readme.md | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment