Handle alternate forms of photo and content passing

This commit is contained in:
2024-02-24 14:48:09 +11:00
parent 13577aa538
commit 0094ac4334

View File

@@ -52,14 +52,27 @@ module Micropub
publish_time = params[:published_at] || Time.now publish_time = params[:published_at] || Time.now
new_params = if req_type == :json new_params = if req_type == :json
content = if params[:properties][:content]
if params[:properties][:content].is_a?(Hash) && params[:properties][:content][:html]
params[:properties][:content][:html]
else
params[:properties][:content].first&.tr("\n", " ")
end
end
photos = if params[:properties][:photo].is_a?(String)
{value: params[:properties][:photo], alt: ""}
else
params[:properties][:photo] || []
end
new_params.merge({ new_params.merge({
published_at: (params[:"post-status"] == "draft") ? nil : publish_time, published_at: (params[:"post-status"] == "draft") ? nil : publish_time,
category: params[:properties][:category] || [], category: params[:properties][:category] || [],
name: params[:properties][:name]&.first, name: params[:properties][:name]&.first,
content: params[:properties][:content]&.first&.tr("\n", " "), content: content,
slug: params[:slug] || params[:"mp-slug"], slug: params[:slug] || params[:"mp-slug"],
syndicate_to: Array(params[:properties][:"mp-syndicate-to"]) || [], syndicate_to: Array(params[:properties][:"mp-syndicate-to"]) || [],
photos: params[:properties][:photo] || [], photos: photos,
location: params[:properties][:location] location: params[:properties][:location]
}) })
else else