From 5d01dfa1790b531ad51c0edac729e6de89d01c8b Mon Sep 17 00:00:00 2001 From: Payback159 Date: Thu, 16 May 2024 17:49:24 +0200 Subject: [PATCH] add auto generate documentation sidebar script, introduce script as pre-commit-hook, adapt existing scripts to work with documentation structure --- .pre-commit-config.yaml | 11 ++++++++--- scripts/gen_docs_sidebar.sh | 31 +++++++++++++++++++++++++++++++ tests/scripts/md-table/test.sh | 4 ++-- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 scripts/gen_docs_sidebar.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c2380522a..337b484f1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,5 @@ --- repos: - - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.4.0 hooks: @@ -25,14 +24,14 @@ repos: rev: v0.11.0 hooks: - id: markdownlint - args: [ -r, "~MD013,~MD029" ] + args: [-r, "~MD013,~MD029"] exclude: "^.git" - repo: https://github.com/jumanjihouse/pre-commit-hooks rev: 3.0.0 hooks: - id: shellcheck - args: [ --severity, "error" ] + args: [--severity, "error"] exclude: "^.git" files: "\\.sh$" @@ -64,6 +63,12 @@ repos: language: script 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 name: ci-matrix entry: tests/scripts/md-table/test.sh diff --git a/scripts/gen_docs_sidebar.sh b/scripts/gen_docs_sidebar.sh new file mode 100755 index 000000000..c7e0d29bf --- /dev/null +++ b/scripts/gen_docs_sidebar.sh @@ -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 diff --git a/tests/scripts/md-table/test.sh b/tests/scripts/md-table/test.sh index 46daa6384..cf9df9085 100755 --- a/tests/scripts/md-table/test.sh +++ b/tests/scripts/md-table/test.sh @@ -7,5 +7,5 @@ pip install -r ./tests/scripts/md-table/requirements.txt echo "Generate current file..." ./tests/scripts/md-table/main.py > tmp.md -echo "Compare docs/ci.md with actual tests in tests/files/*.yml ..." -cmp docs/ci.md tmp.md +echo "Compare docs/developers/ci.md with actual tests in tests/files/*.yml ..." +cmp docs/developers/ci.md tmp.md