Browse Source

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

pull/11128/head
Payback159 6 months ago
parent
commit
5d01dfa179
3 changed files with 41 additions and 5 deletions
  1. 11
      .pre-commit-config.yaml
  2. 31
      scripts/gen_docs_sidebar.sh
  3. 4
      tests/scripts/md-table/test.sh

11
.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

31
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

4
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
Loading…
Cancel
Save