diff --git a/README.md b/README.md index f663e58..c366b55 100644 --- a/README.md +++ b/README.md @@ -5,17 +5,22 @@ Opinionated man page (roff) to html converter. ### Usage Here's how [my man page](https://man.eddie.sh) is created: ```bash -./man-to-html edward-shen.man index.html edward-shen "Edward Shen Manual" +./man-to-html edward-shen.man index.html ``` -You can also specify version number, page number, and date: -```bash -./man-to-html edward-shen.man index.html edward-shen "Edward Shen Manual" 4.2.0 1 "January 1st, 1970" +This script will automatically fetch in metadata information from the +man page. Specifically, it'll parse the first line: + +```roff +.TH cmd-name page date version title ``` +This might not work and will likely break if the man page's first line +isn't in that exact format. + ### Prereqs -- `pandoc` +Install `pandoc`. diff --git a/index.html b/index.html index c204b61..ff82147 100644 --- a/index.html +++ b/index.html @@ -64,8 +64,8 @@ Team TBD.

COPYRIGHT

This man page is under GPLv3 or later. To use Edward Shen for any purpose, please contact Edward Shen <code@eddie.sh> to request a license.

-

3.2.4

-

2019-04-11

+

4.3.2

+

2019-04-10

EDWARD-SHEN(7)

diff --git a/man-to-html b/man-to-html index 25abf68..e46e516 100755 --- a/man-to-html +++ b/man-to-html @@ -1,18 +1,16 @@ #!/usr/bin/env bash -if [[ $# -ne 4 ]]; then - echo "USAGE: ./man-to-html INPUT OUTPUT COMMAND TITLE [ VERSION PAGE DATE ]" +if [[ $# -ne 2 ]]; then + echo "USAGE: ./man-to-html INPUT OUTPUT" exit 1 fi set -euo pipefail -version=${5:-"3.2.4"} -page=${6:-"7"} -date=${7:-"$(date +"%Y-%m-%d")"} +eval "meta=($(head -n 1 "$1" | sed "s/.TH //"))" pandoc -f man -t html \ --template man-template \ - -M title="$4" -M date="$date" \ - -M version="$version" -M cmd="${3^^}($page)" \ + -M title="${meta[4]}" -M date="${meta[2]}" \ + -M version="${meta[3]}" -M cmd="${meta[0]^^}(${meta[1]})" \ "$1" > "$2"