Skip to content

Commit

Permalink
Add: script to auto-generate table of content for NASL documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraemii authored and ArnoStiefvater committed Jan 9, 2023
1 parent df40c89 commit bfa75a3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions doc/toc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

make_toc_entry() {
name=${file##*/}
name=${name//.md/}
entry=$(grep "\*\*$name\*\* - " $file)
entry=${entry//${name}/[${name}](${name}.md)}
toc="$toc\n$entry"
}

make_tocs() {
for dir in "$root_dir_prefix"/*
do
if [[ -d $dir ]]; then
toc=""
for file in "$dir"/*
do
if [ ${file##*/} != "index.md" ]; then
make_toc_entry
fi
done
file_content=""
while read -r line
do
file_content="$file_content$line\n"
if [[ $line =~ "## TABLE OF CONTENT" ]]; then
break
fi
done < $dir/index.md
printf "$file_content$toc" > $dir/index.md
fi
done
}

base_dir=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
root_dir_prefix="$base_dir"/manual/nasl/built-in-functions

make_tocs

exit 0

0 comments on commit bfa75a3

Please sign in to comment.