-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmake_page
executable file
·98 lines (82 loc) · 2.03 KB
/
make_page
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
set -e
export LC_COLLATE=C
TOP=$(pwd)
PANDOC=${PANDOC:-pandoc}
STYLESHEET=web_style.css
check_for_pandoc () {
if ! which "$PANDOC" >/dev/null 2>&1
then
# Make things a little easier on SF.net servers.
export PATH="$PATH:/home/groups/a/al/alleg/pandoc/bin"
if ! which "$PANDOC" >/dev/null 2>&1
then
echo "$PANDOC not found in PATH"
exit 1
fi
fi
}
page_files () {
revdatesort $1/*
echo _include/links
}
# Reverse any series of filenames containing dates.
revdatesort () {(
acc=
for x in "$@"
do
case "$x" in
*[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]*)
acc="$x $acc"
;;
*)
echo "$acc"
acc=
echo "$x"
;;
esac
done
echo "$acc"
)}
get_title () {
grep -e "^$1=" "$TOP/en/_meta/title" | cut -d '=' -f 2-
}
# main
#-------
if test $# -ne 2
then
echo "usage: $0 <input file> <output directory>"
exit 1
fi
check_for_pandoc
indir="$( dirname $1 )"
inpage="$( basename $1 )"
case "$2" in
/*) outdir="$2" ;;
*) outdir="$PWD/$2" ;;
esac
outpage="${outdir}/${inpage}.html"
# Sanity check that don't overwrite an input file by passing wrong args.
case "$outpage" in
*/OUT/*)
;;
*)
echo "Refusing to write to ${outpage}."
exit 2
;;
esac
test -d "$outdir" || mkdir "$outdir"
cd "$indir"
page_files=$( page_files "$inpage" )
title="$( get_title $inpage )"
"$PANDOC" $page_files \
--include-in-header _include/in-header \
--include-before-body _include/before-body.html \
--include-after-body _include/after-body.html \
--metadata title="$title" \
--css "$STYLESHEET" \
--standalone \
--from markdown+fenced_divs \
--lua-filter ../filter_example.lua \
--output "$outpage"
# vim: ft=sh sts=4 sw=4 et: