2021-04-30 20:55:13 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-05-01 09:57:16 +00:00
|
|
|
[[ "$1" == "--help" ]] && echo "USAGE: $0 [NOTES_DIRECTORY_1 [NOTES_DIRECTORY_2 [...]]]" && exit 0
|
2021-04-30 20:55:13 +00:00
|
|
|
|
|
|
|
function _render {
|
|
|
|
echo "rendering $1"
|
|
|
|
pandoc\
|
|
|
|
--toc\
|
|
|
|
--standalone\
|
|
|
|
-t html\
|
2021-04-30 21:08:15 +00:00
|
|
|
--template /opt/notes2web/templates/article.html\
|
2021-04-30 20:55:13 +00:00
|
|
|
-o "$(dirname "$1")/index.html"\
|
|
|
|
"$1"\
|
|
|
|
--mathjax
|
|
|
|
}
|
|
|
|
|
|
|
|
function _renderindex {
|
|
|
|
echo "rendering $1"
|
|
|
|
pandoc\
|
|
|
|
-t html\
|
2021-04-30 21:08:15 +00:00
|
|
|
--template /opt/notes2web/templates/index.html\
|
2021-04-30 20:55:13 +00:00
|
|
|
-o index.html\
|
|
|
|
"$1"
|
|
|
|
}
|
|
|
|
|
2021-05-01 09:57:16 +00:00
|
|
|
function _adddirtoindex {
|
|
|
|
dir="$(dirname "$1")"
|
|
|
|
echo "<h1>$(basename "$dir") notes</h1>" >> index.md
|
|
|
|
find "$dir" -name '*.md' -exec bash -c "_addarticletoindex '{}'" \;
|
|
|
|
}
|
|
|
|
|
|
|
|
function _addarticletoindex {
|
2021-04-30 20:55:13 +00:00
|
|
|
echo "adding $1 to list of notes"
|
|
|
|
pandoc\
|
|
|
|
-t html\
|
|
|
|
-V "filepath=$(dirname "$1")"\
|
2021-04-30 21:08:15 +00:00
|
|
|
--template /opt/notes2web/templates/listitem.html\
|
2021-04-30 20:55:13 +00:00
|
|
|
"$1"\
|
|
|
|
>> index.md
|
|
|
|
}
|
|
|
|
|
|
|
|
export -f _render
|
2021-05-01 09:57:16 +00:00
|
|
|
export -f _adddirtoindex
|
|
|
|
export -f _addarticletoindex
|
2021-04-30 20:55:13 +00:00
|
|
|
|
|
|
|
#render each markdown file
|
2021-05-01 09:57:16 +00:00
|
|
|
for file in "$@"
|
2021-04-30 20:55:13 +00:00
|
|
|
do
|
2021-05-01 09:57:16 +00:00
|
|
|
find "$file" -name '*.md' -exec bash -c "_render '{}'" \;
|
2021-04-30 20:55:13 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# create an intermediate markdown file of links to each article
|
|
|
|
echo "---
|
|
|
|
title: alv's notes
|
|
|
|
---" > index.md
|
|
|
|
|
2021-05-01 09:57:16 +00:00
|
|
|
for file in "$@"
|
2021-04-30 20:55:13 +00:00
|
|
|
do
|
2021-05-01 09:57:16 +00:00
|
|
|
[[ ! -f "$file" ]] && echo "the presence of this files tells notes2web that it should be added to the notes2web index" > "$file/.2web"
|
2021-04-30 20:55:13 +00:00
|
|
|
done
|
|
|
|
|
2021-05-01 09:57:16 +00:00
|
|
|
find -name '.2web' -exec bash -c "_adddirtoindex '{}'" \;
|
|
|
|
|
2021-04-30 20:55:13 +00:00
|
|
|
_renderindex index.md
|
|
|
|
|
|
|
|
echo "copying styles.css to current directory"
|
2021-04-30 21:08:15 +00:00
|
|
|
cp /opt/notes2web/styles.css .
|