Repository navigation
Expand file tree
/
Copy pathgenerate-mkdocs-config
More file actions
executable file
·157 lines (135 loc) · 3.68 KB
/
Copy pathgenerate-mkdocs-config
File metadata and controls
executable file
·157 lines (135 loc) · 3.68 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
set -euo pipefail
MKDOCS_FILE="./mkdocs.yml"
DOCS_DIR="./docs"
EXCLUDE_DIRS=(
"venv"
".git"
".github"
"."
"ai"
"ai/chatgpt_prompts"
"proxmox"
"skilstak"
"pi"
"nix"
"api"
"killercoda"
"android"
"api/product_manager"
"api/security_architect"
"api/design"
"hax/htb"
"hax/thm"
"linux/mint"
"linux/lfcs"
"linux/labs"
"linux/labs/linux"
"linux/labs/hashicorp"
"aws/cloud_quest"
""
)
generate_mkdocs_header() {
cat <<EOF
site_name: Tech Notes by Kolkhis
repo_url: https://github.com/kolkhis/tech-notes
theme:
name: material
palette:
scheme: slate
features:
- navigation.sections
- navigation.expand
- navigation.top
- navigation.tabs
- navigation.footer
- content.tabs.link
- content.action.edit
- content.action.view
- content.code.annotate
- content.code.copy
- content.code.select
plugins:
- search
markdown_extensions:
- codehilite
- admonition
- toc:
permalink: true
- pymdownx.superfences
- pymdownx.keys
- pymdownx.details
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.blocks.caption
- tables
- attr_list
- md_in_html
- def_list
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.emoji:
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg
nav:
- Home: index.md
EOF
}
sanitize_title() {
# Lowercase, replace _ or - with spaces
tr -- '-_' ' ' <<< "$1" | awk '{for(i=1;i<=NF;++i) $i=(substr($i,1,1)) substr($i,2)} 1'
}
generate_nav_entries() {
local base_dir="$1"
local indent=" "
# find "$base_dir" -type d | sort |
while read -r dir; do
local rel_dir="${dir#./docs/}"
[[ "${EXCLUDE_DIRS[*]}" =~ [[:space:]]${rel_dir}[[:space:]] || "$dir" == "$base_dir" ||
-z "$rel_dir" || "$rel_dir" == "." ]] && continue
local section_title
section_title=$(sanitize_title "$rel_dir")
local -a ENTRIES=()
while read -r file; do
local filename
filename=$(basename "$file")
[[ -z "$filename" ]] && continue
# Let mkdocs infer titles from headers
# local title
# title=$(sanitize_title "${filename%%.*}")
local relpath="${file#./docs/}"
[[ -z "$relpath" ]] && continue
ENTRIES+=("${indent} - $relpath")
done < <(find "$dir" -maxdepth 1 -type f -name "*.md" | sort)
if [[ ${#ENTRIES[@]} -gt 0 ]]; then
# Make 3 letter titles caps (AWS, VIM, SSH)
[[ ${#section_title} -le 3 ]] &&
section_title=${section_title^^} || section_title=${section_title^}
if grep -qi '/' <<< "$section_title"; then # Section is in a subdirectory.
# section_title=$(perl -pe 's,/, - ,g' <<< "${section_title^}")
section_title=$(perl -pe 's,.*?/,,g' <<< "${section_title}")
printf "%s - %s:\n" "${indent}" "${section_title^}"
printf ' %s\n' "${ENTRIES[@]}"
else
printf "%s- %s:\n" "${indent}" "${section_title^}"
printf '%s\n' "${ENTRIES[@]}"
fi
fi
done < <(find "$base_dir" -type d | sort)
}
main() {
printf "Generating mkdocs.yml at: %s\n" "$MKDOCS_FILE..."
{
generate_mkdocs_header
generate_nav_entries "$DOCS_DIR"
} > "$MKDOCS_FILE"
printf "Done!\n"
}
main