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
|
### Usage
|
||||||
Here's how [my man page](https://man.eddie.sh) is created:
|
Here's how [my man page](https://man.eddie.sh) is created:
|
||||||
```bash
|
```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:
|
This script will automatically fetch in metadata information from the
|
||||||
```bash
|
man page. Specifically, it'll parse the first line:
|
||||||
./man-to-html edward-shen.man index.html edward-shen "Edward Shen Manual" 4.2.0 1 "January 1st, 1970"
|
|
||||||
|
```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
|
### Prereqs
|
||||||
|
|
||||||
- `pandoc`
|
Install `pandoc`.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,8 @@ Team TBD.</p>
|
||||||
<h1>COPYRIGHT</h1>
|
<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>
|
<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">
|
<div class="formatted">
|
||||||
<p>3.2.4</p>
|
<p>4.3.2</p>
|
||||||
<p>2019-04-11</p>
|
<p>2019-04-10</p>
|
||||||
<p>EDWARD-SHEN(7)</p>
|
<p>EDWARD-SHEN(7)</p>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
12
man-to-html
12
man-to-html
|
@ -1,18 +1,16 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [[ $# -ne 4 ]]; then
|
if [[ $# -ne 2 ]]; then
|
||||||
echo "USAGE: ./man-to-html INPUT OUTPUT COMMAND TITLE [ VERSION PAGE DATE ]"
|
echo "USAGE: ./man-to-html INPUT OUTPUT"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
version=${5:-"3.2.4"}
|
eval "meta=($(head -n 1 "$1" | sed "s/.TH //"))"
|
||||||
page=${6:-"7"}
|
|
||||||
date=${7:-"$(date +"%Y-%m-%d")"}
|
|
||||||
|
|
||||||
pandoc -f man -t html \
|
pandoc -f man -t html \
|
||||||
--template man-template \
|
--template man-template \
|
||||||
-M title="$4" -M date="$date" \
|
-M title="${meta[4]}" -M date="${meta[2]}" \
|
||||||
-M version="$version" -M cmd="${3^^}($page)" \
|
-M version="${meta[3]}" -M cmd="${meta[0]^^}(${meta[1]})" \
|
||||||
"$1" > "$2"
|
"$1" > "$2"
|
||||||
|
|
Loading…
Reference in a new issue