-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish
executable file
·57 lines (47 loc) · 1.52 KB
/
publish
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
#!/bin/bash
echo -e "\n"
CMD="node ejs-cli.js"
# find instances of `.md` and replace with `.md.html`:
MARKDOWN_EXTENSION_REPLACER="sed s/\.md/\.md\.html/"
# find instances of `src` and replace with nothing:
SRC_PATH_REMOVER="sed s/src\///"
generateMarkup () {
# if generateMarkup has no arguments, bail:
if [ -z $1 ]
then
echo "no file given."
return 1
fi
# print what we're going to do:
echo "generating markup for $1"
# if we're dealing with the index, add header and footer as addn'l arguments.
# push them all through the ejs combiner, along with combing for `.md` in the
# index (replacing with `.md.html`) and create `index.html`:
if [ $1 = "src/index.md" ]
then
RETVAL=`$CMD $1 "src/header.html" "src/footer.html" | $MARKDOWN_EXTENSION_REPLACER > index.html`
return $RETVAL
fi
# if we're still here, and we have multiple arguments,
# proceed with multi-arg approach and write to a filename similar
# to the input file (but in the root directory and `.md.html`
# instead of `.md`:
if [ $# -gt 1 ]
then
RETVAL=`$CMD $1 $2 $3 | $MARKDOWN_EXTENSION_REPLACER > $(echo $1 | $MARKDOWN_EXTENSION_REPLACER | $SRC_PATH_REMOVER)`
return $RETVAL
fi
# if we just have one argument, run the single-arg procedure:
RETVAL=`$CMD $1 > $(echo $1 | $MARKDOWN_EXTENSION_REPLACER | $SRC_PATH_REMOVER)`
return $RETVAL
}
if [ -n "$1" ]
then
generateMarkup $1
echo -e "\ndone.\n\n"
exit
fi
for document in $(find src -iname \*.md); do
generateMarkup $document
done
echo -e "\ndone.\n\n"