You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.3 KiB

  1. #!/usr/bin/env bash
  2. # Generate documentation
  3. # This script generates a list of all the markdown files in the docs folder
  4. # and prints them in a markdown list format.
  5. # The script will print the name of the folder and the files inside it.
  6. # The script will also convert the folder and file names to a more human-readable format.
  7. # The script will ignore any files that are not markdown files.
  8. # Usage: bash scripts/gen_docs_sidebar.sh > docs/_sidebar.md
  9. export LANG=C
  10. {
  11. echo "* [Readme](/)"
  12. for folder in $(find docs/*/ | sort -f); do
  13. # Check if it is a directory
  14. if [ -d "$folder" ]; then
  15. subdir=$(basename "$folder")
  16. subdir=${subdir//_/ } # Replace "_" with empty string
  17. subdir=$(echo "$subdir" | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1') # Convert first letter of each word to uppercase
  18. if [ -n "$(find "$folder" -name '*.md' -type f)" ]; then
  19. echo "* $subdir"
  20. fi
  21. for file in $(find docs/"$(basename "$folder")"/*.md | sort -f); do
  22. if [ -f "$file" ]; then
  23. FILE=$(basename "$file" .md)
  24. FILE=${FILE//_/ } # Replace "_" with empty string
  25. FILE=$(echo "$FILE" | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1') # Convert first letter of each word to uppercase
  26. echo " * [$FILE](/$file)"
  27. fi
  28. done
  29. fi
  30. done
  31. } > docs/_sidebar.md