01-generate-man.sh (2693B)
1 #!/bin/sh 2 3 # Copyright (C) 2017-2026 |Méso|Star> (contact@meso-star.com) 4 # 5 # This file is part of Méso-Web. 6 # 7 # Méso-Web is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 3 of the License, or 10 # (at your option) any later version. 11 # 12 # Méso-Web is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Méso-Web. If not, see <http://www.gnu.org/licenses/>. 19 20 . "sty.sh" 21 . "./config.sh.in" 22 23 set -e 24 25 ######################################################################## 26 # Helper function 27 ######################################################################## 28 man_pages() 29 { 30 find "${solstice_dir}/share/man" -type f -name "*.[1-9]" 31 } 32 33 # Man to convert is submitted on stdin 34 man2html() # output_filename 35 { 36 # Define the relative path to the root of the website 37 worktree="$(absdir "../")" 38 output="$(absdir "$1")" 39 root="$(relpath_to_dir "${output}" "${worktree}")" 40 41 { 42 cd .. 43 sty-genhead "${OLDPWD##*/}/$1" 44 mandoc -O man=../man%S/%N.%S.html,fragment -I os=UNIX -T html 45 cat ./templates/footer.html 46 cd "${OLDPWD}" 47 } \ 48 | sed \ 49 -e 's/<a class="Xr"[^>]\{0,\}>csplit(1)<\/a>/<a class "Xr">csplit(1)<\/a>/g' \ 50 -e 's/<a class="Xr"[^>]\{0,\}>feh(1)<\/a>/<a class "Xr">feh(1)<\/a>/g' \ 51 -e 's/<a class="Xr"[^>]\{0,\}>sed(1)<\/a>/<a class "Xr">sed(1)<\/a>/g' \ 52 > "$1" 53 } 54 55 ######################################################################## 56 # The script 57 ######################################################################## 58 man_pages | while read -r i; do 59 filename="$(basename "${i}")" 60 section="${filename##*.}" 61 62 if ! [ -d "./man/man${section}" ]; then 63 mkdir -p "./man/man${section}"; 64 fi 65 66 dst="man/man${section}/${filename}.html" 67 man2html "${dst}" < "${i}" 68 69 # Check the result of the HTML conversion. Do this operation from the 70 # parent directory so that tidy displays the file name relative to the 71 # location where the make command is invoked. This makes the message 72 # clearer for the user. 73 cd .. 74 if ! tidy --show-info no --show-filename yes -qe "${OLDPWD##*/}/${dst}"; then 75 >&2 printf '%s: error converting %s\n' "${0##*/}" "${i}" 76 exit 1 77 fi 78 cd "${OLDPWD}" 79 80 # Write the generated files to standard output to inform the build 81 # system which files it needs to handle during installation. 82 printf '%s/%s\n' "${PWD##*/}" "${dst}" 83 done