-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdocs.sh
executable file
·60 lines (50 loc) · 1.97 KB
/
docs.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
#!/bin/sh
set -e
typedoc --treatWarningsAsErrors
# We need to fix the links in the generated markdown files.
# Typedoc generates anchors for properties in tables which can collide with anchors for types.
# For example we can have property `logger` and type `Logger` which will both have anchor `logger`.
# typedoc-plugin-markdown will generate links trying to deduplicate the anchors by adding a number at the end.
# Example: `globals.md#logger-1` and `globals.md#logger-2`.
#
# We don't need the anchors for properties in the markdown files
# and they won't even work in Gitbook because they are generated as html <a> anchors.
# We can fix this by removing the number at the end of the anchor.
SEDCOMMAND='s/globals.md#(.*)-[0-9]+/globals.md#\1/g'
# Find all markdown files including globals.md
FILES=$(find dist/docs/@bucketco -name "*.md")
echo "Processing markdown files..."
for file in $FILES
do
echo "Processing $file..."
# Fix anchor links in globals.md files
if [[ "$file" == *"globals.md" ]]; then
sed -r "$SEDCOMMAND" "$file" > "$file.fixed"
rm "$file"
mv "$file.fixed" "$file"
fi
# Create a temporary file for processing
tmp_file="${file}.tmp"
# Process NOTE blocks - handle multi-line
awk '
BEGIN { in_block = 0; content = ""; }
/^> \[!NOTE\]/ { in_block = 1; print "{% hint style=\"info\" %}"; next; }
/^> \[!TIP\]/ { in_block = 1; print "{% hint style=\"success\" %}"; next; }
/^> \[!IMPORTANT\]/ { in_block = 1; print "{% hint style=\"warning\" %}"; next; }
/^> \[!WARNING\]/ { in_block = 1; print "{% hint style=\"warning\" %}"; next; }
/^> \[!CAUTION\]/ { in_block = 1; print "{% hint style=\"danger\" %}"; next; }
in_block && /^>/ {
content = content substr($0, 3) "\n";
next;
}
in_block && !/^>/ {
printf "%s", content;
print "{% endhint %}";
in_block = 0;
content = "";
}
!in_block { print; }
' "$file" > "$tmp_file"
mv "$tmp_file" "$file"
done
echo "Processing complete!"