Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions scripts/sync-general-content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ cat > "$ROOT_DIR/content/docs/specification/meta.json" <<EOF
{
"title": "Specification",
"pages": [
"identity",
"margo-management-interface",
"applications",
"margo-devices",
Expand Down Expand Up @@ -135,30 +136,47 @@ find "$ROOT_DIR/content/docs" -type f -name "*.md" -print0 | while IFS= read -r
done

echo "Generating SwaggerUI MDX files..."
rm -f "$ROOT_DIR/content/docs/specification/margo-management-interface/management-interface-swagger.md"
find "$ROOT_DIR/content/docs" -type f \( -name "workload-management-api-1.0.0.yaml" -o -name "workload-management-api-1.0.0.yml" \) -print0 | while IFS= read -r -d '' yaml; do
find "$ROOT_DIR/content/docs" -type f -name "*-swagger.md" -delete
find "$ROOT_DIR/content/docs" -type f \( -name "*.yaml" -o -name "*.yml" \) -print0 | while IFS= read -r -d '' yaml; do
grep -qiE '^openapi:' "$yaml" || continue
mdx="${yaml%.*}.mdx"
base="$(basename "$yaml")"
# Page title from the document's info.title (falls back to the file name).
# Strip a surrounding pair of quotes from the scalar; the frontmatter re-quotes it.
title="$(awk '
/^info:/ { in_info = 1; next }
in_info && /^[^[:space:]]/ { in_info = 0 }
in_info && /^[[:space:]]+title:[[:space:]]*/ {
sub(/^[[:space:]]+title:[[:space:]]*/, "")
sub(/\r$/, ""); sub(/[[:space:]]+$/, "")
if ($0 ~ /^".*"$/ || $0 ~ /^\047.*\047$/) $0 = substr($0, 2, length($0) - 2)
print; exit
}' "$yaml")"
title="${title:-${base%.*}} - Swagger UI"
title="${title//\"/\\\"}" # escape double quotes for the YAML frontmatter string
cat > "$mdx" <<EOF
---
title: "Management Interface - Swagger UI"
title: "$title"
---
<SwaggerUI url="./$base" />
EOF
done

echo "Rewriting legacy Swagger UI links..."
legacy_swagger_target="../margo-management-interface/management-interface-swagger.md"
current_swagger_target="../margo-management-interface/workload-management-api-1.0.0"
find "$ROOT_DIR/content/docs" -type f \( -name "*.md" -o -name "*.mdx" \) -print0 | while IFS= read -r -d '' doc; do
if grep -q "$legacy_swagger_target" "$doc"; then
while read -r legacy current; do
[ -n "$legacy" ] || continue
find "$ROOT_DIR/content/docs" -type f \( -name "*.md" -o -name "*.mdx" \) -print0 | while IFS= read -r -d '' doc; do
grep -q "$legacy" "$doc" || continue
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s|$legacy_swagger_target|$current_swagger_target|g" "$doc"
sed -i '' "s|${legacy}\.md|${current}|g; s|${legacy}|${current}|g" "$doc"
else
sed -i "s|$legacy_swagger_target|$current_swagger_target|g" "$doc"
sed -i "s|${legacy}\.md|${current}|g; s|${legacy}|${current}|g" "$doc"
fi
fi
done
done
done <<'PAIRS'
management-interface-swagger workload-management-api-1.0.0
trust-bundle-api-swagger trust-bundle-api-1.0.0
PAIRS

echo "Copying OpenAPI specs to public..."
find "$ROOT_DIR/content/docs" -type f \( -name "*.yaml" -o -name "*.yml" \) -print0 | while IFS= read -r -d '' yaml; do
Expand Down