forked from Apress/Developer-Relations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.sh
66 lines (50 loc) · 1.54 KB
/
index.sh
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
#!/bin/bash
# Create the markdown file and write the header
echo "# Document Index" > index.md
echo "" >> index.md
echo "## Table of Contents" >> index.md
echo "" >> index.md
echo "- [Images](#images)" >> index.md
echo "- [PDFs](#pdfs)" >> index.md
echo "" >> index.md
# Function to URL-encode filenames
urlencode() {
printf '%s' "$1" | jq -sRr @uri
}
# Images section
echo "## Images" >> index.md
echo "" >> index.md
for file in *.png; do
# Check if file exists (to handle the case when no PNG files are found)
[ -e "$file" ] || continue
# Remove the .png extension and create a link-friendly title
title="${file%.png}"
link=$(echo "$title" | sed 's/ /-/g' | tr '[:upper:]' '[:lower:]')
# Append the ToC entry
echo "- [${title}](#${link})" >> index.md
done
echo "" >> index.md
# Add image sections
for file in *.png; do
[ -e "$file" ] || continue
title="${file%.png}"
encoded_file=$(urlencode "$file")
echo "### ${title}" >> index.md
echo "" >> index.md
echo "![${title}](./${encoded_file})" >> index.md
echo "" >> index.md
done
# PDFs section
echo "## PDFs" >> index.md
echo "" >> index.md
for file in *.pdf; do
# Check if file exists (to handle the case when no PDF files are found)
[ -e "$file" ] || continue
# Remove the .pdf extension
title="${file%.pdf}"
encoded_file=$(urlencode "$file")
# Append the PDF entry
echo "- [${title}](./${encoded_file})" >> index.md
done
echo "" >> index.md
echo "Document index has been generated as 'index.md'"