2021-10-20 22:35:46 +03:00
|
|
|
#!/bin/bash
|
|
|
|
# shellcheck disable=SC1004 # literal backslash+linefeed is intended
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
|
|
|
|
cd "${script_path}/.."
|
|
|
|
|
|
|
|
export LC_ALL=C # Make the directory order reproducible
|
|
|
|
export MAN_DIR=Base/usr/share/man/
|
|
|
|
|
|
|
|
if [[ -e output ]]; then
|
|
|
|
echo "Directory 'output/' already exists. Delete it first."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-01-02 18:20:31 +03:00
|
|
|
# Use case-insensitive sorting, which will lead to more intuitive index pages.
|
|
|
|
SORT="sort -f"
|
|
|
|
|
2021-10-20 22:35:46 +03:00
|
|
|
# Prepare output directories
|
|
|
|
for d in "${MAN_DIR}"*/; do
|
|
|
|
dir_name=$(basename "$d")
|
|
|
|
section="${dir_name/man}"
|
2021-10-20 22:46:39 +03:00
|
|
|
mkdir -p "output/${dir_name}"
|
2021-10-20 22:35:46 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
# Convert markdown to html
|
|
|
|
|
|
|
|
# If you're here because your local results are different from the website:
|
|
|
|
# Check that your pandoc version matches the pandoc-version specified in manpages.yaml.
|
|
|
|
|
2023-01-02 18:20:31 +03:00
|
|
|
for md_file in $(find "${MAN_DIR}" -iname '*.md' | ${SORT}); do
|
2021-10-20 22:46:39 +03:00
|
|
|
relative_path="$(realpath --relative-to="${MAN_DIR}" "${md_file}")"
|
|
|
|
section="${relative_path%%/*}"
|
|
|
|
section_number="${section#man}"
|
|
|
|
filename="${relative_path#*/}"
|
|
|
|
name="${filename%.md}"
|
2023-01-02 18:20:31 +03:00
|
|
|
output_file="output/${section}/${name}.html"
|
|
|
|
|
2023-01-02 18:22:55 +03:00
|
|
|
echo "Generating $md_file -> $output_file"
|
2023-01-02 18:20:31 +03:00
|
|
|
mkdir -p "$(dirname "${output_file}")"
|
2021-10-20 22:52:34 +03:00
|
|
|
pandoc -f gfm -t html5 -s \
|
|
|
|
-B Meta/Websites/man.serenityos.org/banner-preamble.inc \
|
|
|
|
--lua-filter=Meta/convert-markdown-links.lua \
|
2023-10-23 19:17:43 +03:00
|
|
|
--lua-filter=Meta/Websites/man.serenityos.org/add-anchors.lua \
|
2021-10-20 22:52:34 +03:00
|
|
|
--metadata title="${name}(${section_number}) - SerenityOS man pages" \
|
2023-01-02 18:20:31 +03:00
|
|
|
-o "${output_file}" \
|
2023-01-02 18:30:21 +03:00
|
|
|
"${md_file}" &
|
2021-10-20 22:46:39 +03:00
|
|
|
done
|
2021-10-20 22:35:46 +03:00
|
|
|
|
2023-01-02 18:30:21 +03:00
|
|
|
# Wait for all pandoc executions to finish so that man page indices are always correct.
|
|
|
|
# shellcheck disable=SC2046 # Word splitting is intentional here
|
|
|
|
wait $(jobs -p)
|
|
|
|
|
2021-10-20 22:52:34 +03:00
|
|
|
# Generate man page listings through pandoc
|
2023-01-02 18:20:31 +03:00
|
|
|
for section_directory in output/*/; do
|
|
|
|
section=$(basename "${section_directory}")
|
2021-10-20 22:52:34 +03:00
|
|
|
section_number="${section#man}"
|
2021-10-20 22:52:34 +03:00
|
|
|
case "${section_number}" in
|
|
|
|
1) section_title="User Programs";;
|
|
|
|
2) section_title="System Calls";;
|
|
|
|
3) section_title="Library Functions";;
|
|
|
|
4) section_title="Special Files";;
|
2022-02-25 02:04:22 +03:00
|
|
|
5) section_title="File Formats";;
|
2023-01-02 18:20:31 +03:00
|
|
|
6) section_title="Games";;
|
2021-10-20 22:52:34 +03:00
|
|
|
7) section_title="Miscellanea";;
|
|
|
|
8) section_title="Sysadmin Tools";;
|
|
|
|
*) section_title="SerenityOS man pages"; echo "WARNING: Unrecognized section ${section_number}?!";;
|
|
|
|
esac
|
2023-01-02 18:20:31 +03:00
|
|
|
output="output/${section}/index.html"
|
2023-01-02 18:22:55 +03:00
|
|
|
|
|
|
|
echo "Generating section ${section_number} index -> ${output}"
|
2021-10-20 22:52:34 +03:00
|
|
|
pandoc -f gfm -t html5 -s \
|
|
|
|
-B Meta/Websites/man.serenityos.org/banner-preamble.inc \
|
2021-10-20 22:52:34 +03:00
|
|
|
--metadata title="Section ${section_number} - ${section_title}" \
|
2023-01-02 18:20:31 +03:00
|
|
|
-o "${output}" \
|
2021-10-20 22:52:34 +03:00
|
|
|
<(
|
2023-01-02 18:20:31 +03:00
|
|
|
for f in $(find "${section_directory}" -iname '*.html' | ${SORT}); do
|
|
|
|
filename=$(realpath --relative-to="${section_directory}" "$f")
|
2021-10-20 22:52:34 +03:00
|
|
|
if [[ "$filename" == "index.html" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
2023-01-02 19:13:53 +03:00
|
|
|
filename_no_extension="${filename%.html}"
|
|
|
|
# Generate indentation by subdirectory count: Replace each slash by the two Markdown indentation spaces, then remove all non-space characters.
|
|
|
|
indentation=$(echo "${filename_no_extension}" | sed -e 's/ //g' -e 's/\// /g' -e 's/[^ ]//g')
|
|
|
|
name="$(basename "${filename}")"
|
|
|
|
name="${name%.html}"
|
|
|
|
echo "${indentation}- [${name}](${filename})"
|
2021-10-20 22:52:34 +03:00
|
|
|
done
|
2023-01-02 18:30:21 +03:00
|
|
|
) &
|
2021-10-20 22:52:34 +03:00
|
|
|
done
|
|
|
|
|
|
|
|
# Generate main landing page listings through pandoc
|
2023-01-02 18:22:55 +03:00
|
|
|
echo 'Generating main pages'
|
2021-10-20 22:52:34 +03:00
|
|
|
pandoc -f gfm -t html5 -s \
|
|
|
|
-B Meta/Websites/man.serenityos.org/banner-preamble.inc \
|
|
|
|
--metadata title="SerenityOS man pages" \
|
|
|
|
-o output/index.html \
|
2023-01-02 18:30:21 +03:00
|
|
|
Meta/Websites/man.serenityos.org/index.md &
|
2022-01-11 00:28:43 +03:00
|
|
|
pandoc -f gfm -t html5 -s \
|
|
|
|
-B Meta/Websites/man.serenityos.org/banner-preamble.inc \
|
|
|
|
--metadata title="Can't run applications" \
|
|
|
|
-o output/cant-run-application.html \
|
2023-01-02 18:30:21 +03:00
|
|
|
Meta/Websites/man.serenityos.org/cant-run-application.md &
|
2021-10-20 22:52:34 +03:00
|
|
|
|
2021-10-20 22:35:46 +03:00
|
|
|
# Copy pre-made files
|
2023-01-02 18:22:55 +03:00
|
|
|
echo 'Copying images'
|
2023-01-02 18:39:41 +03:00
|
|
|
rsync -a Meta/Websites/man.serenityos.org/banner.png output/ &
|
|
|
|
rsync -a Base/usr/share/man/man7/LibDSP_classes.svg output/ &
|
2023-01-07 19:00:24 +03:00
|
|
|
find Base/usr/share/man/ -iname '*.png' -exec rsync -a {} output/ \; &
|
2022-01-17 12:43:28 +03:00
|
|
|
|
|
|
|
# Copy icons
|
|
|
|
mkdir output/icons
|
|
|
|
|
|
|
|
while read -r p; do
|
|
|
|
rsync -a --relative Base/res/icons/./"$p" output/icons/
|
|
|
|
done < icons.txt
|
|
|
|
|
|
|
|
rm icons.txt
|
2023-01-02 18:30:21 +03:00
|
|
|
|
|
|
|
# shellcheck disable=SC2046 # Word splitting is intentional here
|
|
|
|
wait $(jobs -p)
|