-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfix-docs.sh
More file actions
153 lines (134 loc) · 3.31 KB
/
fix-docs.sh
File metadata and controls
153 lines (134 loc) · 3.31 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
#!/bin/bash
# fix-docs.sh - Script to fix documentation issues
echo "🔄 Processing documentation files..."
if sed --version 2>&1 | grep -q GNU; then
SED_INPLACE=(-i)
else
SED_INPLACE=(-i "")
fi
# IMPORTANT: Process both current directory AND docs/ directory for root files
echo "🔄 Processing root markdown files..."
for location in "." "docs"; do
if [ -d "$location" ]; then
echo " Checking $location directory"
for file in "$location"/*.md; do
if [ -f "$file" ]; then
echo " Processing $file"
temp_file="${file}.tmp"
awk '
/^> \[!NOTE\]/ {
print "{: .note }";
in_note = 1;
next;
}
/^> \[!TIP\]/ {
print "{: .highlight }";
in_note = 1;
next;
}
/^> \[!IMPORTANT\]/ {
print "{: .important }";
in_note = 1;
next;
}
/^> \[!WARNING\]/ {
print "{: .warning }";
in_note = 1;
next;
}
/^> \[!CAUTION\]/ {
print "{: .warning }";
in_note = 1;
next;
}
/^> / {
if(in_note) {
print substr($0, 3);
next;
}
}
{
in_note = 0;
print;
}
' "$file" > "$temp_file"
if [[ "$file" =~ GETTING_STARTED.md ]]; then
sed "${SED_INPLACE[@]}" 's|\[examples\](test/form/definitions)|\[examples\](https://github.com/DEFRA/forms-engine-plugin/tree/main/test/form/definitions)|g' "$temp_file"
fi
sed "${SED_INPLACE[@]}" 's|/forms-engine-plugin/forms-engine-plugin/|/forms-engine-plugin/|g' "$temp_file"
mv "$temp_file" "$file"
fi
done
fi
done
# Determine the correct docs path
if [ -d "docs/features" ]; then
DOCS_PATH="docs/features"
elif [ -d "../docs/features" ]; then
DOCS_PATH="../docs/features"
elif [ -d "features" ]; then
DOCS_PATH="features"
else
echo "❌ Cannot find docs/features directory!"
exit 1
fi
echo "Using docs path: $DOCS_PATH"
# Process each directory
for dir in code-based configuration-based; do
dir_path="$DOCS_PATH/$dir"
echo "Processing $dir_path directory..."
if [ ! -d "$dir_path" ]; then
echo "❌ Directory $dir_path not found!"
continue
fi
pushd "$dir_path" > /dev/null || exit 1
for file in *.md; do
echo " Processing $file"
temp_file="${file}.tmp"
awk '
/^> \[!NOTE\]/ {
print "{: .note }";
in_note = 1;
next;
}
/^> \[!TIP\]/ {
print "{: .highlight }";
in_note = 1;
next;
}
/^> \[!IMPORTANT\]/ {
print "{: .important }";
in_note = 1;
next;
}
/^> \[!WARNING\]/ {
print "{: .warning }";
in_note = 1;
next;
}
/^> \[!CAUTION\]/ {
print "{: .warning }";
in_note = 1;
next;
}
/^> / {
if(in_note) {
print substr($0, 3);
next;
}
}
{
in_note = 0;
print;
}
' "$file" > "$temp_file"
lowercase_file=$(echo "$file" | tr '[:upper:]' '[:lower:]')
if [ "$file" != "$lowercase_file" ]; then
echo " Creating lowercase copy: $lowercase_file"
cp "$temp_file" "$lowercase_file"
fi
mv "$temp_file" "$file"
done
popd > /dev/null
done
echo "✅ Documentation fixes applied successfully!"