Skip to content
Open
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
102 changes: 65 additions & 37 deletions docs/scripts/publish-portal-content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ function portal_product_toc_markdown_upsert() {
portal_product_toc_markdown_post "$section_id" "$markdown_title" "$markdown_slug" "$content_order" "$parent_toc_id" "$type" "$source"
else
log_message $INFO "Patching markdown TOC: $section_id, $product_toc_id, $markdown_title, $markdown_slug, $content_order, $parent_toc_id"
portal_product_toc_markdown_patch "$section_id" "$product_toc_id" "$markdown_title" "$markdown_slug" "$content_order" "$product_toc_slug" "$parent_toc_id" "$type"
portal_product_toc_markdown_patch "$section_id" "$product_toc_id" "$markdown_title" "$markdown_slug" "$content_order" "$product_toc_slug" "$parent_toc_id"
fi

log_message $DEBUG "Returning document_id: $document_id"
Expand All @@ -706,21 +706,39 @@ function portal_product_toc_markdown_post() {
local source=$7

log_message $INFO "Creating markdown TOC: $markdown_title in product $product_id with parent $parent_toc_id ..."
local response=$(curl -s --request POST \
--url "$PORTAL_URL/sections/$product_section_id/table-of-contents" \
--header "Authorization: Bearer $SWAGGERHUB_API_KEY" \
--header "Content-Type: application/json" \
--data "{
\"type\": \"new\",
\"title\": \"$markdown_title\",
\"slug\": \"$markdown_slug\",
\"order\": $content_order,
\"parentId\": \"$parent_toc_id\",
\"content\": {
\"type\": \"$type\",
\"source\": \"$source\"
}
}")

if [ -z "$source" ] || [ "$source" = "" ]; then
local response=$(curl -s --request POST \
--url "$PORTAL_URL/sections/$product_section_id/table-of-contents" \
--header "Authorization: Bearer $SWAGGERHUB_API_KEY" \
--header "Content-Type: application/json" \
--data "{
\"type\": \"new\",
\"title\": \"$markdown_title\",
\"slug\": \"$markdown_slug\",
\"order\": $content_order,
\"parentId\": \"$parent_toc_id\",
\"content\": {
\"type\": \"$type\"
}
}")
else
local response=$(curl -s --request POST \
--url "$PORTAL_URL/sections/$product_section_id/table-of-contents" \
--header "Authorization: Bearer $SWAGGERHUB_API_KEY" \
--header "Content-Type: application/json" \
--data "{
\"type\": \"new\",
\"title\": \"$markdown_title\",
\"slug\": \"$markdown_slug\",
\"order\": $content_order,
\"parentId\": \"$parent_toc_id\",
\"content\": {
\"type\": \"$type\",
\"source\": \"$source\"
}
}")
fi

log_message $DEBUG "Response: $response"
product_toc_id=$(echo "$response" | jq -r .id)
Expand All @@ -738,7 +756,6 @@ function portal_product_toc_markdown_patch() {
local content_order=$5
local product_toc_slug=$6
local parent_toc_id=$7
local type=$8

log_message $INFO "Updating markdown TOC: $markdown_title in product $product_id with parent $parent_toc_id ..."
if [ "$markdown_slug" == "$product_toc_slug" ]; then
Expand All @@ -750,10 +767,7 @@ function portal_product_toc_markdown_patch() {
--data "{
\"title\": \"$markdown_title\",
\"order\": $content_order,
\"parentId\": \"$parent_toc_id\",
\"content\": {
\"type\": \"$type\"
}
\"parentId\": \"$parent_toc_id\"
}")
else
local response=$(curl -s --request PATCH \
Expand All @@ -764,10 +778,7 @@ function portal_product_toc_markdown_patch() {
\"title\": \"$markdown_title\",
\"slug\": \"$markdown_slug\",
\"order\": $content_order,
\"parentId\": \"$parent_toc_id\",
\"content\": {
\"type\": \"$type\"
}
\"parentId\": \"$parent_toc_id\"
}")
fi

Expand All @@ -791,22 +802,39 @@ function portal_product_document_markdown_patch() {
log_message $DEBUG "Enter portal_product_document_markdown_patch"
local contents=$1
local type=$2
local source=$3

log_message $INFO "Updating markdown document in product $product_id for document $document_id..."
local escaped_contents=$(jq -Rs . <<< "$contents")

local response=$(curl -s --request PATCH \
--url "$PORTAL_URL/documents/$document_id" \
--header "Authorization: Bearer $SWAGGERHUB_API_KEY" \
--header "Content-Type: application/json" \
--data "{
\"content\": $escaped_contents,
\"type\": \"$type\",
\"source\": \"$source\"
}")
if [ -z "$document_id" ] || [ "$document_id" = "" ]; then
log_message $INFO "Document ID is null or empty. Skipping the update of the document."
else

log_message $DEBUG "Document patch response: $response"
log_message $INFO "Done updating $type document."
local escaped_contents=$(jq -Rs . <<< "$contents")
if [ -z "$source" ] || [ "$source" = "" ]; then
local response=$(curl -s --request PATCH \
--url "$PORTAL_URL/documents/$document_id" \
--header "Authorization: Bearer $SWAGGERHUB_API_KEY" \
--header "Content-Type: application/json" \
--data "{
\"content\": $escaped_contents,
\"type\": \"$type\"
}")
else
local response=$(curl -s --request PATCH \
--url "$PORTAL_URL/documents/$document_id" \
--header "Authorization: Bearer $SWAGGERHUB_API_KEY" \
--header "Content-Type: application/json" \
--data "{
\"content\": $escaped_contents,
\"type\": \"$type\",
\"source\": \"$source\"
}")
fi

log_message $DEBUG "Document patch response: $response"
log_message $INFO "Done updating $type document."
fi
log_message $DEBUG "Exit portal_product_document_markdown_patch"
}

Expand Down
Loading