mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2025-12-13 21:34:40 +03:00
add auto generate documentation sidebar script, introduce script as pre-commit-hook, adapt existing scripts to work with documentation structure
This commit is contained in:
31
scripts/gen_docs_sidebar.sh
Executable file
31
scripts/gen_docs_sidebar.sh
Executable file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Generate documentation
|
||||
# This script generates a list of all the markdown files in the docs folder
|
||||
# and prints them in a markdown list format.
|
||||
# The script will print the name of the folder and the files inside it.
|
||||
# The script will also convert the folder and file names to a more human-readable format.
|
||||
# The script will ignore any files that are not markdown files.
|
||||
# Usage: bash scripts/gen_docs_sidebar.sh > docs/_sidebar.md
|
||||
|
||||
echo "* [Readme](/)"
|
||||
|
||||
for folder in $(find docs/*/ | sort -f); do
|
||||
# Check if it is a directory
|
||||
if [ -d "$folder" ]; then
|
||||
subdir=$(basename "$folder")
|
||||
subdir=${subdir//_/ } # Replace "_" with empty string
|
||||
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
|
||||
if [ -n "$(find "$folder" -name '*.md' -type f)" ]; then
|
||||
echo "* $subdir"
|
||||
fi
|
||||
for file in $(find docs/"$(basename "$folder")"/*.md | sort -f); do
|
||||
if [ -f "$file" ]; then
|
||||
FILE=$(basename "$file" .md)
|
||||
FILE=${FILE//_/ } # Replace "_" with empty string
|
||||
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
|
||||
echo " * [$FILE](/$file)"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user