Skip to content

Commit

Permalink
Provide medium and high resolution images for features
Browse files Browse the repository at this point in the history
In order to orchestrate a release in conjunction with `collections` application, url field has to be legacy url path temporarily.

Medium and High resolution images are required because `collections` app is expecting s465 and s712 versions of images. Previously the url of different versions of images were guessable from the original legacy path.

Co-authored-by: Laura Ghiorghisor <[email protected]>
Co-authored-by: Tuomas Nylund <[email protected]>
  • Loading branch information
3 people committed Nov 28, 2023
1 parent 3f82b5b commit d11b289
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
25 changes: 13 additions & 12 deletions app/presenters/publishing_api/featured_documents_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def featured_documents_editioned(feature)
{
title: edition.title,
href: edition.public_path(locale: feature.feature_list.locale),
image: {
url: feature.image.url,
alt_text: feature.alt_text.presence || "",
},
image: get_image(feature),
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(edition.summary),
public_updated_at: edition.public_timestamp,
document_type: edition.display_type,
Expand All @@ -39,10 +36,7 @@ def featured_documents_topical_event(feature)
{
title: topical_event.name,
href: topical_event.public_path(locale: feature.feature_list.locale),
image: {
url: feature.image.url,
alt_text: feature.alt_text,
},
image: get_image(feature),
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(topical_event.summary),
public_updated_at: topical_event.start_date,
document_type: nil, # We don't want a type for topical events
Expand All @@ -55,14 +49,21 @@ def featured_documents_offsite_link(feature)
{
title: offsite_link.title,
href: offsite_link.url,
image: {
url: feature.image.url,
alt_text: feature.alt_text,
},
image: get_image(feature),
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(offsite_link.summary),
public_updated_at: offsite_link.date,
document_type: offsite_link.display_type,
}
end

def get_image(feature)
legacy_url_path = feature.image.file.path
{
url: URI.join(Plek.asset_root, Addressable::URI.encode(legacy_url_path)).to_s,
medium_resolution_url: feature.image.url(:s465),
high_resolution_url: feature.image.url(:s712),
alt_text: feature.alt_text.presence || "",
}
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ class PublishingApi::FeaturedDocumentsPresenterTest < ActiveSupport::TestCase
expected_ordered_featured_documents = [
{ title: case_study.title,
href: "/government/case-studies/case-study-title#{locale[:suffix]}",
image: { url: first_feature.image.url,
image: { url: "#{Plek.asset_root}/government/uploads/system/uploads/featured_image_data/file/#{first_feature.image.id}/minister-of-funk.960x640.jpg",
medium_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s465/s465_minister-of-funk.960x640.jpg",
high_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s712/s712_minister-of-funk.960x640.jpg",
alt_text: "" },
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(case_study.summary),
public_updated_at: case_study.public_timestamp,
document_type: I18n.t("document.type.case_study.one") },
{ title: news_article.title,
href: "/government/news/news-title#{locale[:suffix]}",
image: { url: second_feature.image.url,
image: { url: "#{Plek.asset_root}/government/uploads/system/uploads/featured_image_data/file/#{second_feature.image.id}/minister-of-funk.960x640.jpg",
medium_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s465/s465_minister-of-funk.960x640.jpg",
high_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s712/s712_minister-of-funk.960x640.jpg",
alt_text: "" },
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(news_article.summary),
public_updated_at: news_article.public_timestamp,
Expand Down Expand Up @@ -62,8 +66,10 @@ class PublishingApi::FeaturedDocumentsPresenterTest < ActiveSupport::TestCase
expected_ordered_featured_documents = [
{ title: topical_event.name,
href: "/government/topical-events/topical_event_1#{locale[:suffix]}",
image: { url: feature.image.url,
alt_text: feature.alt_text },
image: { url: "#{Plek.asset_root}/government/uploads/system/uploads/featured_image_data/file/#{feature.image.id}/minister-of-funk.960x640.jpg",
medium_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s465/s465_minister-of-funk.960x640.jpg",
high_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s712/s712_minister-of-funk.960x640.jpg",
alt_text: "" },
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(topical_event.summary),
public_updated_at: topical_event.start_date,
document_type: nil },
Expand All @@ -90,8 +96,10 @@ class PublishingApi::FeaturedDocumentsPresenterTest < ActiveSupport::TestCase
expected_ordered_featured_documents = [
{ title: offsite_link.title,
href: offsite_link.url,
image: { url: feature.image.url,
alt_text: feature.alt_text },
image: { url: "#{Plek.asset_root}/government/uploads/system/uploads/featured_image_data/file/#{feature.image.id}/minister-of-funk.960x640.jpg",
medium_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s465/s465_minister-of-funk.960x640.jpg",
high_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s712/s712_minister-of-funk.960x640.jpg",
alt_text: "" },
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(offsite_link.summary),
public_updated_at: offsite_link.date,
document_type: offsite_link.display_type },
Expand Down Expand Up @@ -132,7 +140,9 @@ class PublishingApi::FeaturedDocumentsPresenterTest < ActiveSupport::TestCase
{
title: case_study.title,
href: "/government/case-studies/case-study-title",
image: { url: first_feature.image.url,
image: { url: "#{Plek.asset_root}/government/uploads/system/uploads/featured_image_data/file/#{first_feature.image.id}/minister-of-funk.960x640.jpg",
medium_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s465/s465_minister-of-funk.960x640.jpg",
high_resolution_url: "#{Plek.asset_root}/media/asset_manager_id_s712/s712_minister-of-funk.960x640.jpg",
alt_text: "" },
summary: Whitehall::GovspeakRenderer.new.govspeak_to_html(case_study.summary),
public_updated_at: case_study.public_timestamp,
Expand Down

0 comments on commit d11b289

Please sign in to comment.