Skip to content

Commit

Permalink
WIP - publish a more reasonable history pages content object
Browse files Browse the repository at this point in the history
  • Loading branch information
KludgeKML committed Oct 1, 2024
1 parent 3af259d commit 4a50791
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 0 deletions.
61 changes: 61 additions & 0 deletions app/services/publish_history_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
class PublishHistoryPage
attr_reader :history_page_content_item, :content_id

def initialize(history_page_details)
@history_page_content_item = make_content_item(history_page_details)
@content_id = history_page_details[:content_it]
end

def self.call(history_page_details)
new(history_page_details).call
end

def call
send_to_publishing_api
end

private

def make_content_item(details)
govspeak = Govspeak::Document.new(details[:govspeak])

{
base_path: details[:base_path],
title: details[:title],
description: details[:description],
locale: "en",
document_type: "history",
schema_name: "history",
publishing_app: "whitehall",
rendering_app: "frontend",
public_updated_at: Time.zone.now.iso8601,
update_type: "minor",
details: {
image: {
src: details[:image],
alt: details[:image_alt],
},
headers: extract_headers(govspeak),
body: govspeak.to_html,
},
routes: [
{
type: "exact",
path: details[:base_path],
},
],
}
end

def extract_headers(govspeak)
govspeak.headers.select{ |h| h.level == 2 }.map { |h| { title: h.text, id: h.id } }

Check failure on line 51 in app/services/publish_history_page.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Layout/SpaceBeforeBlockBraces: Space missing to the left of {.
end

def send_to_publishing_api
Services.publishing_api.put_content(
content_id,
history_page_content_item,
)
Services.publishing_api.publish(content_id)
end
end
Loading

0 comments on commit 4a50791

Please sign in to comment.