build-manpages-website.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # shellcheck disable=SC1004 # literal backslash+linefeed is intended
  3. set -e
  4. script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
  5. cd "${script_path}/.."
  6. export LC_ALL=C # Make the directory order reproducible
  7. export MAN_DIR=Base/usr/share/man/
  8. if [[ -e output ]]; then
  9. echo "Directory 'output/' already exists. Delete it first."
  10. exit 1
  11. fi
  12. # Prepare output directories
  13. for d in "${MAN_DIR}"*/; do
  14. dir_name=$(basename "$d")
  15. section="${dir_name/man}"
  16. mkdir -p "output/${dir_name}"
  17. done
  18. # Convert markdown to html
  19. # If you're here because your local results are different from the website:
  20. # Check that your pandoc version matches the pandoc-version specified in manpages.yaml.
  21. for md_file in "${MAN_DIR}"*/*.md; do
  22. relative_path="$(realpath --relative-to="${MAN_DIR}" "${md_file}")"
  23. section="${relative_path%%/*}"
  24. section_number="${section#man}"
  25. filename="${relative_path#*/}"
  26. name="${filename%.md}"
  27. pandoc -f gfm -t html5 -s \
  28. -B Meta/Websites/man.serenityos.org/banner-preamble.inc \
  29. --lua-filter=Meta/convert-markdown-links.lua \
  30. --metadata title="${name}(${section_number}) - SerenityOS man pages" \
  31. -o "output/${section}/${name}.html" \
  32. "${md_file}"
  33. done
  34. # Generate man page listings through pandoc
  35. for d in output/*/; do
  36. section=$(basename "$d")
  37. section_number="${section#man}"
  38. pandoc -f gfm -t html5 -s \
  39. -B Meta/Websites/man.serenityos.org/banner-preamble.inc \
  40. --metadata title="Section ${section_number} - SerenityOS man pages" \
  41. -o "output/${section}/index.html" \
  42. <(
  43. for f in "$d"/*; do
  44. filename=$(basename "$f")
  45. name="${filename%.html}"
  46. if [[ "$filename" == "index.html" ]]; then
  47. continue
  48. fi
  49. echo "- [${name}](${filename})"
  50. done
  51. )
  52. done
  53. # Generate man page listings through pandoc
  54. for d in output/*/; do
  55. section=$(basename "$d")
  56. section_number="${section#man}"
  57. case "${section_number}" in
  58. 1) section_title="User Programs";;
  59. 2) section_title="System Calls";;
  60. 3) section_title="Library Functions";;
  61. 4) section_title="Special Files";;
  62. 5) section_title="User Programs";;
  63. 6) section_title="Games";; # TODO: Populate this section
  64. 7) section_title="Miscellanea";;
  65. 8) section_title="Sysadmin Tools";;
  66. *) section_title="SerenityOS man pages"; echo "WARNING: Unrecognized section ${section_number}?!";;
  67. esac
  68. pandoc -f gfm -t html5 -s \
  69. -B Meta/Websites/man.serenityos.org/banner-preamble.inc \
  70. --metadata title="Section ${section_number} - ${section_title}" \
  71. -o "output/${section}/index.html" \
  72. <(
  73. for f in "$d"/*; do
  74. filename=$(basename "$f")
  75. name="${filename%.html}"
  76. if [[ "$filename" == "index.html" ]]; then
  77. continue
  78. fi
  79. echo "- [${name}](${filename})"
  80. done
  81. )
  82. done
  83. # Generate main landing page listings through pandoc
  84. pandoc -f gfm -t html5 -s \
  85. -B Meta/Websites/man.serenityos.org/banner-preamble.inc \
  86. --metadata title="SerenityOS man pages" \
  87. -o output/index.html \
  88. Meta/Websites/man.serenityos.org/index.md
  89. # Copy pre-made files
  90. cp Meta/Websites/man.serenityos.org/banner.png output/