mirror of
https://github.com/alvierahman90/gronk.git
synced 2024-12-23 12:21:58 +00:00
65 lines
1.4 KiB
Bash
Executable File
65 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
[[ "$1" == "--help" ]] && echo "USAGE: $0 [NOTES_DIRECTORY_1 [NOTES_DIRECTORY_2 [...]]]" && exit 0
|
|
|
|
function _renderarticle {
|
|
echo "rendering $1"
|
|
pandoc\
|
|
--toc\
|
|
--standalone\
|
|
-t html\
|
|
--template /opt/notes2web/templates/article.html\
|
|
-o "$(dirname "$1")/index.html"\
|
|
"$1"\
|
|
--mathjax
|
|
}
|
|
|
|
function _adddirtoindex {
|
|
dir="$(dirname "$1")"
|
|
echo "<h1>$(basename "$dir") notes</h1>" >> index.md
|
|
find "$dir" -name '*.md' -exec bash -c "_addarticletoindex '{}'" \;
|
|
}
|
|
|
|
function _addarticletoindex {
|
|
echo "adding $1 to list of notes"
|
|
pandoc\
|
|
-t html\
|
|
-V "filepath=$(dirname "$1")"\
|
|
--template /opt/notes2web/templates/listitem.html\
|
|
"$1"\
|
|
>> index.md
|
|
}
|
|
|
|
export -f _renderarticle
|
|
export -f _adddirtoindex
|
|
export -f _addarticletoindex
|
|
|
|
#render each markdown file
|
|
for file in "$@"
|
|
do
|
|
find "$file" -name '*.md' -exec bash -c "_renderarticle '{}'" \;
|
|
done
|
|
|
|
# create an intermediate markdown file of links to each article
|
|
echo "---
|
|
title: alv's notes
|
|
---" > index.md
|
|
|
|
for file in "$@"
|
|
do
|
|
[[ ! -f "$file" ]] && echo "the presence of this files tells notes2web that it should be added to the notes2web index" > "$file/.2web"
|
|
done
|
|
|
|
# add articles to index
|
|
find -name '.2web' -exec bash -c "_adddirtoindex '{}'" \;
|
|
|
|
echo "rendering index.md"
|
|
pandoc\
|
|
-t html\
|
|
--template /opt/notes2web/templates/index.html\
|
|
-o index.html\
|
|
"index.md"
|
|
|
|
echo "copying styles.css to current directory"
|
|
cp /opt/notes2web/styles.css .
|