File: toc.sh

package info (click to toggle)
openvas-scanner 23.40.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 22,692 kB
  • sloc: ansic: 41,669; xml: 6,251; pascal: 3,723; yacc: 1,287; sh: 1,101; makefile: 333; sql: 282; javascript: 12
file content (43 lines) | stat: -rwxr-xr-x 1,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Greenbone AG
#
# SPDX-License-Identifier: GPL-2.0-or-later

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\n" > $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