1
0

make-index.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/bash
  2. # Script to generate the index page.
  3. # Must be run at the root of the site.
  4. set -eu -o pipefail
  5. index_file="index.md"
  6. # Create/clean the current index file
  7. > "$index_file"
  8. # Add header
  9. cat >> "$index_file" <<EOF
  10. ---
  11. no_breadcrumbs: true
  12. no_toc: true
  13. ---
  14. {% include header.md %}
  15. Random collection of config notes and miscellaneous stuff. _Technically not a wiki._
  16. EOF
  17. # Add categories and pages
  18. for dir in $(find . -mindepth 1 -type d); do
  19. # Check if the dir contains a name file
  20. if [[ ! -f $dir/_name ]]; then
  21. continue
  22. fi
  23. dir_name="$(head -n1 "$dir/_name")"
  24. echo >> "$index_file"
  25. echo "## $dir_name" >> "$index_file"
  26. echo >> "$index_file"
  27. for file in $(find "$dir" -type f -name '*.md'); do
  28. link="$(echo $file | sed 's|^\./|/|' | sed 's|\.md$|/|')"
  29. name="$(grep -Po -m1 '(?<=^title: ).+$' $file | sed -e 's|^\"||' -e "s|^'||" -e 's|\"$||' -e "s|'$||" || true)"
  30. if [[ $name == "" ]]; then
  31. echo "Missing name for page: $file" >&2
  32. exit 1
  33. fi
  34. echo "- [$name]($link)" >> "$index_file"
  35. done
  36. done
  37. # Add footer
  38. cat >> "$index_file" <<EOF
  39. {% include footer.md %}
  40. EOF