From 0094ac43341d8f039da51f3728c6bd3d1ff49406 Mon Sep 17 00:00:00 2001 From: Daniel Nitsikopoulos Date: Sat, 24 Feb 2024 14:48:09 +1100 Subject: [PATCH] Handle alternate forms of photo and content passing --- slices/micropub/request_parser.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/slices/micropub/request_parser.rb b/slices/micropub/request_parser.rb index 6eef278..ae3d5e5 100644 --- a/slices/micropub/request_parser.rb +++ b/slices/micropub/request_parser.rb @@ -52,14 +52,27 @@ module Micropub publish_time = params[:published_at] || Time.now 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({ published_at: (params[:"post-status"] == "draft") ? nil : publish_time, category: params[:properties][:category] || [], name: params[:properties][:name]&.first, - content: params[:properties][:content]&.first&.tr("\n", " "), + content: content, slug: params[:slug] || params[:"mp-slug"], syndicate_to: Array(params[:properties][:"mp-syndicate-to"]) || [], - photos: params[:properties][:photo] || [], + photos: photos, location: params[:properties][:location] }) else