Update update sdk docs script to be more robust

Signed-off-by: Marc Duiker <marcduiker@users.noreply.github.com>
This commit is contained in:
Marc Duiker 2025-07-08 12:10:31 +02:00
parent 69f0a59234
commit 871465fba7
No known key found for this signature in database
GPG Key ID: 6A36EA7754473DD7
1 changed files with 16 additions and 14 deletions

View File

@ -65,11 +65,11 @@ process_file() {
echo " - Replaced [codetabs] with [tabpane]" echo " - Replaced [codetabs] with [tabpane]"
fi fi
# Step 2: Change {{< ref file.md >}} to {{% ref file.md %}} # Step 2: Change {{< ref filename >}} to {{% ref filename %}}
# Handle both formats: with and without space before >}} # Handle both formats: with and without space before >}}
# Use non-greedy matching to handle multiple links on the same line # Use non-greedy matching to handle multiple links on the same line
if grep -q '{{< ref [^}]*\.md[^}]*>}}' "$temp_file"; then if grep -q '{{< ref [^}]*>}}' "$temp_file"; then
sed -i 's/{{< ref \([^}]*\.md[^}]*\) >}}/{{% ref \1 %}}/g; s/{{< ref \([^}]*\.md[^}]*\)>}}/{{% ref \1 %}}/g' "$temp_file" sed -i 's/{{< ref \([^}]*\) >}}/{{% ref \1 %}}/g; s/{{< ref \([^}]*\)>}}/{{% ref \1 %}}/g' "$temp_file"
changes_made=true changes_made=true
echo " - Updated ref links from {{< >}} to {{% %}}" echo " - Updated ref links from {{< >}} to {{% %}}"
fi fi
@ -118,13 +118,14 @@ process_file() {
# Extract everything after "tabs" and before ">}}" # Extract everything after "tabs" and before ">}}"
line = $0 line = $0
# Remove the opening {{< tabs part (with optional space) # Remove the opening {{< tabs part (handle optional space after tabs)
# This handles cases like "{{< tabs SDK HTTP>}}" and "{{< tabs SDK HTTP >}}"
gsub(/^{{< tabs */, "", line) gsub(/^{{< tabs */, "", line)
gsub(/>}}$/, "", line) gsub(/>}}$/, "", line)
gsub(/^ +/, "", line) # Remove leading spaces gsub(/^ +/, "", line) # Remove leading spaces
gsub(/ +$/, "", line) # Remove trailing spaces gsub(/ +$/, "", line) # Remove trailing spaces
# Parse quoted and unquoted strings # Parse quoted and unquoted strings with improved logic
languages_count = 0 languages_count = 0
i = 1 i = 1
while (i <= length(line)) { while (i <= length(line)) {
@ -137,7 +138,7 @@ process_file() {
# Check if this token starts with a quote # Check if this token starts with a quote
if (substr(line, i, 1) == "\"") { if (substr(line, i, 1) == "\"") {
# Find the closing quote # Find the closing quote - handle quoted strings with spaces
i++ # Skip opening quote i++ # Skip opening quote
start = i start = i
while (i <= length(line) && substr(line, i, 1) != "\"") { while (i <= length(line) && substr(line, i, 1) != "\"") {
@ -153,6 +154,7 @@ process_file() {
} }
} else { } else {
# Unquoted token - read until space or end # Unquoted token - read until space or end
# This handles single words and dash-separated words
start = i start = i
while (i <= length(line) && substr(line, i, 1) != " ") { while (i <= length(line) && substr(line, i, 1) != " ") {
i++ i++
@ -170,7 +172,7 @@ process_file() {
} }
# Step 7: Replace {{< /tabs >}} with {{< /tabpane >}} # Step 7: Replace {{< /tabs >}} with {{< /tabpane >}}
/^{{< \/tabs >}}$/ { /^{{< \/tabs *>}}$/ {
in_tabs = 0 in_tabs = 0
print "{{< /tabpane >}}" print "{{< /tabpane >}}"
file_has_changes = 1 file_has_changes = 1
@ -178,7 +180,7 @@ process_file() {
} }
# Update {{% tab %}} within tabs to include header parameter # Update {{% tab %}} within tabs to include header parameter
/^{{% tab %}}$/ && in_tabs { /^{{% tab *%}}$/ && in_tabs {
if (tab_index < languages_count) { if (tab_index < languages_count) {
tab_index++ tab_index++
print "{{% tab header=\"" languages[tab_index] "\" %}}" print "{{% tab header=\"" languages[tab_index] "\" %}}"
@ -215,11 +217,11 @@ process_file() {
if [ "$tabs_processed" = true ]; then if [ "$tabs_processed" = true ]; then
echo " - Running validation checks..." echo " - Running validation checks..."
# Get counts safely # Get counts safely from the processed temp file
local opening_tabs=$(safe_count '{{% tab' "$file") local opening_tabs=$(safe_count '{{% tab' "$temp_file")
local closing_tabs=$(safe_count '{{% /tab' "$file") local closing_tabs=$(safe_count '{{% /tab' "$temp_file")
local opening_tabpanes=$(safe_count '{{< tabpane' "$file") local opening_tabpanes=$(safe_count '{{< tabpane' "$temp_file")
local closing_tabpanes=$(safe_count '{{< /tabpane' "$file") local closing_tabpanes=$(safe_count '{{< /tabpane' "$temp_file")
# Check for mismatches only if elements exist # Check for mismatches only if elements exist
local validation_issues=false local validation_issues=false
@ -298,7 +300,7 @@ fi
echo "" echo ""
echo "Summary of transformations applied:" echo "Summary of transformations applied:"
echo "1. ✅ [codetabs] → [tabpane]" echo "1. ✅ [codetabs] → [tabpane]"
echo "2. ✅ {{< ref file.md>}} → {{% ref file.md %}}" echo "2. ✅ {{< ref filename>}} → {{% ref filename %}}"
echo "3. ✅ Conditional processing based on presence of codetab/tabs elements" echo "3. ✅ Conditional processing based on presence of codetab/tabs elements"
echo "4. ✅ {{% codetab %}} → {{% tab %}} (if codetabs found)" echo "4. ✅ {{% codetab %}} → {{% tab %}} (if codetabs found)"
echo "5. ✅ {{% /codetab %}} → {{% /tab %}} (if codetabs found)" echo "5. ✅ {{% /codetab %}} → {{% /tab %}} (if codetabs found)"