File:  [NetBSD Developer Wiki] / wikisrc / guide / gen_index.sh
Revision 1.2: download - view: text, annotated - select for diffs
Mon Mar 4 00:24:10 2013 UTC (7 years, 6 months ago) by jdf
Branches: MAIN
CVS tags: HEAD
Cosmetics.

    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: # XXX: Add anchor conversion
   31: 						echo "   * [[${section}.${subsection}.${subsectionname}]]"
   32: 						subsection=$(( subsection + 1 ))
   33: 					fi
   34: 				done
   35: 			fi
   36: 			section=$(( section + 1 ))
   37: 		done >> "${3}"
   38: 		continue
   39: 	fi
   40: 
   41: 	echo "${line}" >> "${3}"
   42: done

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb