diff options
Diffstat (limited to 'lib/notes.source.sh')
| -rw-r--r-- | lib/notes.source.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/notes.source.sh b/lib/notes.source.sh new file mode 100644 index 0000000..559b218 --- /dev/null +++ b/lib/notes.source.sh @@ -0,0 +1,34 @@ +notes::_get_notes () { + local -r notes_dir="$CONTENT_BASE_DIR/gemtext/notes" + local -r gmi_pattern='.*\.gmi$' + + ls "$notes_dir" | + $GREP -E "$gmi_pattern" | + $GREP -v '^index.gmi$' | + sort -r +} + +# Generate a index.gmi in the ./notes subdir. +notes::generate () { + local -r notes_dir="$CONTENT_BASE_DIR/gemtext/notes" + log INFO "Generating Notes index for $notes_dir" + +cat <<NOTES > "$notes_dir/index.gmi.tmp" +# Notes on $DOMAIN + +## $SUBTITLE + +NOTES + + while read -r gmi_file; do + # Extract first heading as post title. + local title=$($SED -n '/^# / { s/# //; p; q; }' \ + "$notes_dir/$gmi_file" | tr '"' "'") + + echo "=> ./$gmi_file $title" >> \ + "$notes_dir/index.gmi.tmp" + done < <(notes::_get_notes) + + mv "$notes_dir/index.gmi.tmp" "$notes_dir/index.gmi" + git::add gemtext "$notes_dir/index.gmi" +} |
