lol autofetch from man page
This commit is contained in:
parent
f04161096c
commit
6b0ddd9d95
3 changed files with 17 additions and 14 deletions
15
README.md
15
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`.
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -64,8 +64,8 @@ Team TBD.</p>
|
|||
<h1>COPYRIGHT</h1>
|
||||
<p>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.</p>
|
||||
<div class="formatted">
|
||||
<p>3.2.4</p>
|
||||
<p>2019-04-11</p>
|
||||
<p>4.3.2</p>
|
||||
<p>2019-04-10</p>
|
||||
<p>EDWARD-SHEN(7)</p>
|
||||
</div>
|
||||
</body>
|
||||
|
|
12
man-to-html
12
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"
|
||||
|
|
Loading…
Reference in a new issue