![]() ![]() | ![]() |
Make gen_index.sh create links for subsections, regen index.mdwn
1: #!/bin/sh 2: 3: if [ "${1}" = "" -o "${2}" = "" -o "${3}" = "" ]; then 4: echo "gen_index.sh <tocfile> <index_bare> <index.mdwn>" 5: echo "i.e.: gen_index.sh toc_order index_bare index.mdwn" 6: exit 1 7: fi 8: 9: echo > "${3}" 10: 11: cat "${2}" | while read line; do 12: if [ "${line}" = "%%TOC%%" ]; then 13: section=1 14: cat "${1}" | while read line; do 15: if echo "${line}" | grep -q "^\*"; then 16: echo 17: echo "${line}" 18: echo 19: continue 20: fi 21: 22: file="${line}.mdwn" 23: if [ -f "${file}" ]; then 24: sectionname=`grep "^# .*" "${file}" | grep -o " .*$"` 25: echo " * [[${section}.${sectionname}|guide/${line}]]" 26: subsection=1 27: cat "${file}" | while read subline; do 28: if echo "${subline}" | grep -q "^## "; then 29: subsectionname=`echo "${subline}" | grep -o " .*$"` 30: echo " * [[${section}.${subsection}.${subsectionname}|guide/${line}#index${subsection}h2]]" 31: subsection=$(( subsection + 1 )) 32: fi 33: done 34: fi 35: section=$(( section + 1 )) 36: done >> "${3}" 37: continue 38: fi 39: 40: echo "${line}" >> "${3}" 41: done