-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-index.sh
executable file
·51 lines (40 loc) · 1.21 KB
/
make-index.sh
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
47
48
49
50
51
#!/bin/bash
# Script to generate the index page.
# Must be run at the root of the site.
set -eu -o pipefail
index_file="${1:-index.md}"
# Create/clean the current index file
> "$index_file"
# Add header
cat >> "$index_file" <<EOF
---
no_breadcrumbs: true
no_toc: false
---
{% include header.md %}
Random collection of config notes and Miscellanea. _Technically not a wiki._
EOF
# Add categories and pages
for dir in $(find . -mindepth 1 -type d | LC_ALL=C sort | sed 's|^\./||'); do
# Check if the dir contains a name file
if [[ ! -f $dir/_name ]]; then
continue
fi
dir_name="$(head -n1 "$dir/_name")"
echo >> "$index_file"
echo "## $dir_name" >> "$index_file"
echo >> "$index_file"
for file in $(find "$dir" -type f -name '*.md' | LC_ALL=C sort -t. -k1,1); do
link="$(echo $file | sed 's|^|/|' | sed 's|\.md$|/|')"
name="$(grep -Po -m1 '(?<=^title: ).+$' $file | sed -e 's|^\"||' -e "s|^'||" -e 's|\"$||' -e "s|'$||" || true)"
if [[ $name == "" ]]; then
echo "Missing name for page: $file" >&2
exit 1
fi
echo "- [$name]($link)" >> "$index_file"
done
done
# Add footer
cat >> "$index_file" <<EOF
{% include footer.md %}
EOF