Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - add tasks to publish history pages content object #9487

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
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
Loading