add auto generate documentation sidebar script, introduce script as pre-commit-hook, adapt existing scripts to work with documentation structure

pull/11128/head
Payback159 2024-05-16 17:49:24 +02:00
parent 4dbfd42f1d
commit 5d01dfa179
3 changed files with 41 additions and 5 deletions

View File

@ -1,6 +1,5 @@
--- ---
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0 rev: v3.4.0
hooks: hooks:
@ -25,14 +24,14 @@ repos:
rev: v0.11.0 rev: v0.11.0
hooks: hooks:
- id: markdownlint - id: markdownlint
args: [ -r, "~MD013,~MD029" ] args: [-r, "~MD013,~MD029"]
exclude: "^.git" exclude: "^.git"
- repo: https://github.com/jumanjihouse/pre-commit-hooks - repo: https://github.com/jumanjihouse/pre-commit-hooks
rev: 3.0.0 rev: 3.0.0
hooks: hooks:
- id: shellcheck - id: shellcheck
args: [ --severity, "error" ] args: [--severity, "error"]
exclude: "^.git" exclude: "^.git"
files: "\\.sh$" files: "\\.sh$"
@ -64,6 +63,12 @@ repos:
language: script language: script
pass_filenames: false pass_filenames: false
- id: generate-docs-sidebar
name: generate-docs-sidebar
entry: scripts/gen_docs_sidebar.sh
language: script
pass_filenames: false
- id: ci-matrix - id: ci-matrix
name: ci-matrix name: ci-matrix
entry: tests/scripts/md-table/test.sh entry: tests/scripts/md-table/test.sh

View 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

View File

@ -7,5 +7,5 @@ pip install -r ./tests/scripts/md-table/requirements.txt
echo "Generate current file..." echo "Generate current file..."
./tests/scripts/md-table/main.py > tmp.md ./tests/scripts/md-table/main.py > tmp.md
echo "Compare docs/ci.md with actual tests in tests/files/*.yml ..." echo "Compare docs/developers/ci.md with actual tests in tests/files/*.yml ..."
cmp docs/ci.md tmp.md cmp docs/developers/ci.md tmp.md