1#!/bin/bash 2# 3# Handy script to rebuild the markdown version of the man pages. 4# This uses pandoc if it is installed. 5# 6# For rendering the md, we can use a different command: 7# 8# cd md; for x in *.md ; do pandoc -s $x --metadata pagetitle="${x%.md}" -o ${x%.md}.html --lua-filter=../md2html.lua ; done 9 10if [[ -z "$(which pandoc)" ]]; then 11 echo "pandoc not found - skipping conversion" 12 exit 0 13fi 14 15outdir="$1" 16if [[ -z "${outdir}" ]]; then 17 echo "usage $0 <outdir>" 18 exit 1 19fi 20 21mkdir -p "${outdir}" 22if [[ $? -ne 0 ]]; then 23 echo "failed to make output directory: ${outdir}" 24 exit 1 25fi 26 27index="${outdir}/index.md" 28 29function do_page () { 30 m="$1" 31 base="${m%.*}" 32 sect="${m#*.}" 33 output="${base}-${sect}.md" 34 35 redir="$(grep '^.so man' "${m}")" 36 if [[ $? -eq 0 ]]; then 37 r="${redir#*/}" 38 rbase="${r%.*}" 39 rsect="${r#*.}" 40 echo "* [${base}(${sect})](${rbase}-${rsect}.md)" >> "${index}" 41 return 42 fi 43 44 pandoc -f man -t markdown < "${m}" | sed 's/\*\*\([^*]\+\)\*\*(\([138]\+\))/[\1(\2)](\1-\2.md)/g' > "${outdir}/${base}-${sect}.md" 45 echo "* [${base}(${sect})](${base}-${sect}.md)" >> "${index}" 46} 47 48cat > "${index}" <<EOF 49# Manpages for libcap and libpsx 50 51## Individual reference pages 52EOF 53 54# Assumes the m's are listed alphabetically. 55for n in 1 3 8 ; do 56 cat >> "${index}" <<EOF 57 58### Section ${n} 59 60EOF 61 for m in *.${n}; do 62 do_page "${m}" 63 done 64done 65 66cat >> "${index}" <<EOF 67 68## More information 69 70For further information, see the 71[FullyCapable](https://sites.google.com/site/fullycapable/) homepage 72for libcap. 73 74## MD page generation 75 76These official man pages for libcap and libpsx were converted to 77markdown using [pandoc](https://pandoc.org). 78 79EOF 80