gronk/notes2web

70 lines
1.7 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
2021-05-01 10:48:04 +00:00
for configpath in "$HOME/.notes2web.conf" "$HOME/.config/notes2web/config" ".notes2web.conf"
do
[[ -f "$configpath" ]] && source "$configpath"
done
2021-05-01 10:29:48 +00:00
function _renderarticle {
2021-04-30 20:55:13 +00:00
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 _adddirtoindex {
dir="$(dirname "$1")"
2021-05-01 10:48:41 +00:00
echo "<h2>$(basename "$dir") notes</h2>" >> 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
}
2021-05-01 10:29:48 +00:00
export -f _renderarticle
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
2021-05-01 10:29:48 +00:00
find "$file" -name '*.md' -exec bash -c "_renderarticle '{}'" \;
2021-04-30 20:55:13 +00:00
done
# create an intermediate markdown file of links to each article
2021-05-01 10:48:04 +00:00
echo "---" > index.md
[[ -z "$name" ]] && echo "title: notes" >> index.md || echo "title: ${name}'s notes" >> index.md
echo "---" >> index.md
2021-04-30 20:55:13 +00:00
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
2021-05-01 10:29:48 +00:00
# add articles to index
find -name '.2web' -exec bash -c "_adddirtoindex '{}'" \;
2021-05-01 10:29:48 +00:00
echo "rendering index.md"
pandoc\
-t html\
--template /opt/notes2web/templates/index.html\
-o index.html\
"index.md"
2021-04-30 20:55:13 +00:00
echo "copying styles.css to current directory"
2021-04-30 21:08:15 +00:00
cp /opt/notes2web/styles.css .