make-index.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. _(Alphabetically sorted, so it might seem a bit strange.)_
  17. EOF
  18. # Add categories and pages
  19. for dir in $(find . -mindepth 1 -type d | sort | sed 's|^\./||'); do
  20. # Check if the dir contains a name file
  21. if [[ ! -f $dir/_name ]]; then
  22. continue
  23. fi
  24. dir_name="$(head -n1 "$dir/_name")"
  25. echo >> "$index_file"
  26. echo "## $dir_name" >> "$index_file"
  27. echo >> "$index_file"
  28. for file in $(find "$dir" -type f -name '*.md' | sort -t. -k1,1); do
  29. link="$(echo $file | sed 's|^|/|' | sed 's|\.md$|/|')"
  30. name="$(grep -Po -m1 '(?<=^title: ).+$' $file | sed -e 's|^\"||' -e "s|^'||" -e 's|\"$||' -e "s|'$||" || true)"
  31. if [[ $name == "" ]]; then
  32. echo "Missing name for page: $file" >&2
  33. exit 1
  34. fi
  35. echo "- [$name]($link)" >> "$index_file"
  36. done
  37. done
  38. # Add footer
  39. cat >> "$index_file" <<EOF
  40. {% include footer.md %}
  41. EOF