File:  [NetBSD Developer Wiki] / wikisrc / guide / gen_index.sh
Revision 1.4: download - view: text, annotated - select for diffs
Thu Mar 21 11:21:48 2013 UTC (8 years, 8 months ago) by jdf
Branches: MAIN
CVS tags: HEAD
Make gen_index.sh create links for subsections, regen index.mdwn

#!/bin/sh

if [ "${1}" = "" -o "${2}" = "" -o "${3}" = "" ]; then
	echo "gen_index.sh <tocfile> <index_bare> <index.mdwn>"
	echo "i.e.: gen_index.sh toc_order index_bare index.mdwn"
	exit 1
fi

echo > "${3}"

cat "${2}" | while read line; do
	if [ "${line}" = "%%TOC%%" ]; then
		section=1
		cat "${1}" | while read line; do
			if echo "${line}" | grep -q "^\*"; then
				echo
				echo "${line}"
				echo
				continue
			fi

			file="${line}.mdwn"
			if [ -f "${file}" ]; then
				sectionname=`grep "^# .*" "${file}" | grep -o " .*$"`
				echo " * [[${section}.${sectionname}|guide/${line}]]"
				subsection=1
				cat "${file}" | while read subline; do
					if echo "${subline}" | grep -q "^## "; then
						subsectionname=`echo "${subline}" | grep -o " .*$"`
						echo "   * [[${section}.${subsection}.${subsectionname}|guide/${line}#index${subsection}h2]]"
						subsection=$(( subsection + 1 ))
					fi
				done
			fi
			section=$(( section + 1 ))
		done >> "${3}"
		continue
	fi

	echo "${line}" >> "${3}"
done

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