summaryrefslogtreecommitdiff
path: root/lib/notes.source.sh
blob: 08af3e51f5cb378f8c5a356ba49e450bcf145ae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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"
    if [ ! -d "$notes_dir" ]; then
        log INFO "Capsule without Notes section"
        return
    fi

    log INFO "Generating Notes index for $notes_dir"

    log INFO "Hello world"

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)

cat <<NOTES >> "$notes_dir/index.gmi.tmp"

That were all notes. Hope they were useful!

=> ../ Go back to main site
NOTES

    # Only overwrite if content changed, preserving mtime for template skip logic
    generate::safe_overwrite "$notes_dir/index.gmi.tmp" "$notes_dir/index.gmi"
}