-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: sphinx reference doc index generation (#853)
Run a pre-hook to create index file in policy reference. To be able to list the whole policy reference definition, we needs index file for each category. Create them on the fly, listing the reference policies generated in the reference destination directory, before generating the finale documentation. ----- UDENG-1450
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
# Generate our toc tree for Computer and User policies to reflect the hierarchy in reference | ||
# That way, each key have a complete hierarchy folder structure. | ||
set -eu | ||
|
||
# Function to create index.md in a directory | ||
create_index() { | ||
local dir=$1 | ||
local index_file="$dir/index.md" | ||
|
||
# Get the name of the directory for the title | ||
local title=$(basename "$dir") | ||
|
||
cat <<EOF > "${index_file}" | ||
# $title | ||
\`\`\`{toctree} | ||
:maxdepth: 99 | ||
EOF | ||
|
||
# List directories and files, excluding index.md | ||
for item in "$dir"/*; do | ||
if [ -d "$item" ]; then | ||
# It's a directory, add its index file | ||
echo "$(basename "$item")/index" >> "$index_file" | ||
elif [ -f "$item" ] && [ "$(basename "$item")" != "index.md" ]; then | ||
# It's a file, add it directly to the index | ||
echo "$(basename "$item" .md)" >> "$index_file" | ||
fi | ||
done | ||
|
||
echo '```' >> "$index_file" | ||
} | ||
|
||
# Recursive function to walk through directories | ||
walk_dirs() { | ||
local current_dir=${1%/} | ||
|
||
# Create index in the current directory | ||
create_index "$current_dir" | ||
|
||
# Recursively walk into subdirectories | ||
for subdir in "$current_dir"/*/; do | ||
if [ -d "$subdir" ]; then | ||
walk_dirs "$subdir" | ||
fi | ||
done | ||
} | ||
|
||
for d in "$@"; do | ||
walk_dirs "$d" | ||
done |