@cryptotaxi247 / netdata-1 / commits / f4423a361

/docs/generator: add an option to use last dir name for page name (#7997)

* /docs/generator/buildyaml.sh: add `useLastDirAsPageName` option to the navpart and use it for go.d.plugin and python.d.plugin modules * /docs/generator/buildyaml.sh: do not use negative array indexes

Ilya Mashchenko committed Feb 9, 2020 at 02:45 UTC f4423a361bcae40ceef7ca13a441d54154e45d86
1 file changed +20 -5
docs/generator/buildyaml.sh
+20 -5
@@ -8,6 +8,14 @@ language="${3}"
8
9 cd ${GENERATOR_DIR}/${docs_dir}
10
11 +# getlastdir parses file path and returns last directory name.
12 +# It expects path to be not empty , '/' as a delimeter and at least one '/' in the path.
13 +getlastdir() {
14 + local IFS=/
15 + read -ra array <<< "$1"
16 + echo "${array[((${#array[@]} - 2))]}"
17 +}
18 +
19 # create yaml nav subtree with all the files directly under a specific directory
20 # arguments:
21 # tabs - how deep do we show it in the hierarchy. Level 1 is the top level, max should probably be 3
@@ -24,6 +32,7 @@ navpart() {
32 section=$4
33 maxdepth=$5
34 excludefirstlevel=$6
35 + useLastDirAsPageName=$7
36 spc=""
37
38 i=1
@@ -37,12 +46,18 @@ navpart() {
46 if [ -z "$maxdepth" ]; then maxdepth=1; fi
47 if [[ -n $excludefirstlevel ]]; then mindepth=2; else mindepth=1; fi
48
40 - for f in $(find $dir -mindepth $mindepth -maxdepth $maxdepth -name "${file}.md" -printf '%h|%d|%p\n' | sort -t '|' -n | awk -F '|' '{print $3}'); do
49 + local pagename
50 + for f in $(find "$dir" -mindepth $mindepth -maxdepth $maxdepth -name "${file}.md" -printf '%h|%d|%p\n' | sort -t '|' -n | awk -F '|' '{print $3}'); do
51 # If I'm adding a section, I need the child links to be one level deeper than the requested level in "tabs"
52 + pagename="'$f'"
53 + if [ -n "$useLastDirAsPageName" ]; then
54 + pagename="'$(getlastdir "$f")' : '$f'"
55 + fi
56 +
57 if [ -z "$section" ]; then
43 - echo "$spc- '$f'"
58 + echo "$spc- $pagename"
59 else
45 - echo "$spc - '$f'"
60 + echo "$spc - $pagename"
61 fi
62 done
63 }
@@ -223,12 +238,12 @@ navpart 2 collectors/plugins.d "" "External plugins"
238 echo -ne " - Go:
239 - 'collectors/go.d.plugin/README.md'
240 "
226 -navpart 4 collectors/go.d.plugin "" "Modules" 3 excludefirstlevel
241 +navpart 4 collectors/go.d.plugin "" "Modules" 3 excludefirstlevel useLastDirAsPageName
242
243 echo -ne " - Python:
244 - 'collectors/python.d.plugin/README.md'
245 "
231 -navpart 4 collectors/python.d.plugin "" "Modules" 3 excludefirstlevel
246 +navpart 4 collectors/python.d.plugin "" "Modules" 3 excludefirstlevel useLastDirAsPageName
247
248 echo -ne " - Node.js:
249 - 'collectors/node.d.plugin/README.md'