gronk/notes2web

68 lines
1.4 KiB
Plaintext
Raw Normal View History

2021-04-30 20:55:13 +00:00
#!/usr/bin/env bash
[[ "$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"
}
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
export -f _adddirtoindex
export -f _addarticletoindex
2021-04-30 20:55:13 +00:00
#render each markdown file
for file in "$@"
2021-04-30 20:55:13 +00:00
do
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
for file in "$@"
2021-04-30 20:55:13 +00:00
do
[[ ! -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
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 .