Created
December 18, 2014 12:12
-
-
Save warpech/8a1279f057083ad51635 to your computer and use it in GitHub Desktop.
Find Gollum linked pages and orphans
This file contains 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
#!/bin/bash | |
#Usage: | |
#./find-links.sh #shows linked pages and orphans | |
#./find-links.sh --html #shows linked pages and orphans with HTML links | |
#./find-links.sh --md #shows linked pages and orphans with Markdown links | |
#./find-links.sh --orphans #shows only orphans | |
#./find-links.sh --orphans --html #shows only orphans with HTML links | |
#./find-links.sh --linked #shows only linked pages | |
#./find-links.sh --linked --html #shows only linked pages with HTML links | |
outputOrphans=1 | |
outputLinked=1 | |
outputHtml="" | |
outputMarkdown="" | |
while test $# -gt 0 | |
do | |
case "$1" in | |
--orphans) outputLinked="" | |
;; | |
--linked) outputOrphans="" | |
;; | |
--html) outputHtml=1 | |
;; | |
--md) outputMarkdown=1 | |
esac | |
shift | |
done | |
found="" | |
find . -name HelpPages -prune -o -name '*.md' -type f -print0 | while IFS= read -r -d '' f; do | |
escaped=$(echo $f | sed -e "s/.md//g") | |
escaped=$(echo $escaped | sed -e "s/.\///g") | |
escaped=$(echo $escaped | sed -e "s/(/\\\\(/g") | |
escaped=$(echo $escaped | sed -e "s/)/\\\\)/g") | |
escaped=$(echo $escaped | sed -e "s/\.\///g") | |
escaped=$(echo $escaped | sed -E 's/[- ]/\[- \/\]/g') | |
escaped=$(echo $escaped | sed -E 's/ /\\ /g') | |
if [ -n "$outputHtml" ]; then | |
linktext=$(echo $f | sed -e "s/.md//g") | |
linktext=$(echo $linktext | sed -e "s/.\///g") | |
linktext=$(echo $linktext | sed -E 's/[- ]/ /g') | |
url=$(echo $f | sed -e "s/.md//g") | |
url=$(echo $url | sed -e "s/.\///g") | |
url=$(echo https://github.com/Starcounter/Starcounter/wiki/$url) | |
output=$(echo "<a href='$url'>$linktext</a>") | |
elif [ -n "$outputMarkdown" ]; then | |
linktext=$(echo $f | sed -e "s/.md//g") | |
linktext=$(echo $linktext | sed -e "s/.\///g") | |
linktext=$(echo $linktext | sed -E 's/[- ]/ /g') | |
url=$(echo $f | sed -e "s/.md//g") | |
url=$(echo $url | sed -e "s/.\///g") | |
url=$(echo https://github.com/Starcounter/Starcounter/wiki/$url) | |
output=$(echo "- [$linktext]($url)") | |
else | |
output=$f | |
fi | |
found=$(grep -E -i -r "[\|\[]$escaped\]" *.md) | |
if [ -n "$found" ]; then | |
if [ -n "$outputLinked" ]; then | |
echo $output | |
found=$(echo "$found" | sed "s/^/ /g") #indent | |
echo "$found" | |
fi | |
else | |
if [ -n "$outputOrphans" ]; then | |
echo $output | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment