all repos — site @ ef756fa738c2757d20021cde081797e86879389d

source for my site, found at icyphox.sh

bin/wiki.sh (view raw)

 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
#!/usr/bin/env bash

# wiki.sh -- helper script to generate a wiki
# does all kinds of weird shit. this is NOT how you engineer software, people.

WIKI_PATH="pages/wiki"
ROOT_INDEX_MD="pages/wiki/_index.md"

generate_index() {
    mapfile -d $'\0' entries < <(find "$WIKI_PATH" ! -path "$WIKI_PATH" -print0)
    prevdir=''
    for r in "${entries[@]}"; do
        path="$(basename "$r")"
        [ "$path" != "_index.md" ] && {
            if [ -d "$r" ]; then
                printf '%s\n' "- [$path](/wiki/$path)"
                prevdir="$path"
            elif [ "$(basename "$(dirname "$r")")" == "$prevdir" ]; then
                noext="${path%%'.md'}"
                printf '  %s\n' "- [$noext](/wiki/$prevdir/$noext)"
            else
                printf '%s\n' "- [$path](/wiki/$path)"
            fi
        }
    done
}

printf '%s' "---
title: wiki
subtitle: Ideas, beliefs and thoughts.
template: page.html
---

# The wiki.

" > "$ROOT_INDEX_MD"
generate_index >> "$ROOT_INDEX_MD"

exit 0