Skip to content

Commit 871465f

Browse files
committed
Update update sdk docs script to be more robust
Signed-off-by: Marc Duiker <[email protected]>
1 parent 69f0a59 commit 871465f

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

scripts/update-sdk-docs.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ process_file() {
6565
echo " - Replaced [codetabs] with [tabpane]"
6666
fi
6767

68-
# Step 2: Change {{< ref file.md >}} to {{% ref file.md %}}
68+
# Step 2: Change {{< ref filename >}} to {{% ref filename %}}
6969
# Handle both formats: with and without space before >}}
7070
# Use non-greedy matching to handle multiple links on the same line
71-
if grep -q '{{< ref [^}]*\.md[^}]*>}}' "$temp_file"; then
72-
sed -i 's/{{< ref \([^}]*\.md[^}]*\) >}}/{{% ref \1 %}}/g; s/{{< ref \([^}]*\.md[^}]*\)>}}/{{% ref \1 %}}/g' "$temp_file"
71+
if grep -q '{{< ref [^}]*>}}' "$temp_file"; then
72+
sed -i 's/{{< ref \([^}]*\) >}}/{{% ref \1 %}}/g; s/{{< ref \([^}]*\)>}}/{{% ref \1 %}}/g' "$temp_file"
7373
changes_made=true
7474
echo " - Updated ref links from {{< >}} to {{% %}}"
7575
fi
@@ -118,13 +118,14 @@ process_file() {
118118
119119
# Extract everything after "tabs" and before ">}}"
120120
line = $0
121-
# Remove the opening {{< tabs part (with optional space)
121+
# Remove the opening {{< tabs part (handle optional space after tabs)
122+
# This handles cases like "{{< tabs SDK HTTP>}}" and "{{< tabs SDK HTTP >}}"
122123
gsub(/^{{< tabs */, "", line)
123124
gsub(/>}}$/, "", line)
124125
gsub(/^ +/, "", line) # Remove leading spaces
125126
gsub(/ +$/, "", line) # Remove trailing spaces
126127
127-
# Parse quoted and unquoted strings
128+
# Parse quoted and unquoted strings with improved logic
128129
languages_count = 0
129130
i = 1
130131
while (i <= length(line)) {
@@ -137,7 +138,7 @@ process_file() {
137138
138139
# Check if this token starts with a quote
139140
if (substr(line, i, 1) == "\"") {
140-
# Find the closing quote
141+
# Find the closing quote - handle quoted strings with spaces
141142
i++ # Skip opening quote
142143
start = i
143144
while (i <= length(line) && substr(line, i, 1) != "\"") {
@@ -153,6 +154,7 @@ process_file() {
153154
}
154155
} else {
155156
# Unquoted token - read until space or end
157+
# This handles single words and dash-separated words
156158
start = i
157159
while (i <= length(line) && substr(line, i, 1) != " ") {
158160
i++
@@ -170,15 +172,15 @@ process_file() {
170172
}
171173
172174
# Step 7: Replace {{< /tabs >}} with {{< /tabpane >}}
173-
/^{{< \/tabs >}}$/ {
175+
/^{{< \/tabs *>}}$/ {
174176
in_tabs = 0
175177
print "{{< /tabpane >}}"
176178
file_has_changes = 1
177179
next
178180
}
179181
180182
# Update {{% tab %}} within tabs to include header parameter
181-
/^{{% tab %}}$/ && in_tabs {
183+
/^{{% tab *%}}$/ && in_tabs {
182184
if (tab_index < languages_count) {
183185
tab_index++
184186
print "{{% tab header=\"" languages[tab_index] "\" %}}"
@@ -215,11 +217,11 @@ process_file() {
215217
if [ "$tabs_processed" = true ]; then
216218
echo " - Running validation checks..."
217219

218-
# Get counts safely
219-
local opening_tabs=$(safe_count '{{% tab' "$file")
220-
local closing_tabs=$(safe_count '{{% /tab' "$file")
221-
local opening_tabpanes=$(safe_count '{{< tabpane' "$file")
222-
local closing_tabpanes=$(safe_count '{{< /tabpane' "$file")
220+
# Get counts safely from the processed temp file
221+
local opening_tabs=$(safe_count '{{% tab' "$temp_file")
222+
local closing_tabs=$(safe_count '{{% /tab' "$temp_file")
223+
local opening_tabpanes=$(safe_count '{{< tabpane' "$temp_file")
224+
local closing_tabpanes=$(safe_count '{{< /tabpane' "$temp_file")
223225

224226
# Check for mismatches only if elements exist
225227
local validation_issues=false
@@ -298,7 +300,7 @@ fi
298300
echo ""
299301
echo "Summary of transformations applied:"
300302
echo "1. ✅ [codetabs] → [tabpane]"
301-
echo "2. ✅ {{< ref file.md>}} → {{% ref file.md %}}"
303+
echo "2. ✅ {{< ref filename>}} → {{% ref filename %}}"
302304
echo "3. ✅ Conditional processing based on presence of codetab/tabs elements"
303305
echo "4. ✅ {{% codetab %}} → {{% tab %}} (if codetabs found)"
304306
echo "5. ✅ {{% /codetab %}} → {{% /tab %}} (if codetabs found)"

0 commit comments

Comments
 (0)