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

Landing page images from content item #4375

Closed
wants to merge 5 commits into from

Conversation

KludgeKML
Copy link
Contributor

Hero and Featured blocks will now take their image sets from the content item, and can understand the difference between hardcoded images that have to be pathed and remote images where the url can be used directly.

Related to: alphagov/whitehall#9579

https://trello.com/c/00bwdpYL/124-images-from-whitehall

- Because we might now get images from the content item or locally-supplied, we check the url is a url - if it is, we return it, if not, we try to make an image_path for it and return that.
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4375 November 5, 2024 15:42 Inactive
@KludgeKML KludgeKML force-pushed the landing-page-hero-asset-images branch from daa6f77 to 9eca4eb Compare November 6, 2024 09:46
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4375 November 6, 2024 09:46 Inactive
"tablet" => "landing_page/tablet.jpeg",
"tablet_2x" => "landing_page/tablet_2x.jpeg",
},
"sources" => [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably do a much better job of structuring this payload on the whitehall side. All the way down to this if we wanted:

      "image" => {
        "alt" => "some alt text",
        "sources" => {
          "hero_desktop_1x" => "landing_page/desktop.jpeg",
          "hero_desktop_2x" => "landing_page/desktop_2x.jpeg",
          "hero_tablet_1x" => "landing_page/tablet.jpeg",
          "hero_tablet_2x" => "landing_page/tablet_2x.jpeg",
          "hero_mobile_1x" => "landing_page/mobile.jpeg",
          "hero_mobile_2x" => "landing_page/mobile_2x.jpeg",
        },

... and whitehall could validate that the alt text is nil or the same for all of the images etc.

The other metadata (created_at, caption etc.) is always going to be a bit confusing while we're uploading three separate images (mobile, tablet, desktop) with 2 variants each.

alphagov/whitehall#9579 does produce the payload in the current format - I haven't attempted to improve it yet. I'm happy to stick with the current format if you like, but I'd probably vote to improve it before the two PRs merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, let's simplify it. I was hoping that maybe leaving the code the way it is would give us some more general support in the future, but I'm forgetting YAGNI. Let's make the code simpler now, and we can complicate it later if we need to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll confirm what the structure will be once I've updated my second PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are we losing the alt text entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated, but kept the top-level alt.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I'm pulling the alt text out and setting at the top level only, so that frontend doesn't have to handle the "what if different images have different alt texts" edge case.

In actual fact, Whitehall doesn't seem to let people provide alt text for new images, so we might have to have a think about whether hero images should have alt text, or whether they're purely decorative. I'm on the fence personally.

- this will replace individual image handling in hero and featured blocks.
  Tests to be added in the commits for the consuming block types.
- to simplify calls, we load the sources into an OpenStruct. This is
  close to how they're currently handled in the blocks, but removes the
  Dataclass strictness (which allows this to be used more generally).
- Update tests and fixtures (local files to be updated in a later commit)
@KludgeKML KludgeKML force-pushed the landing-page-hero-asset-images branch from 9eca4eb to ea8ca2a Compare November 7, 2024 16:34
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4375 November 7, 2024 16:34 Inactive
@KludgeKML KludgeKML force-pushed the landing-page-hero-asset-images branch from ea8ca2a to 83e008f Compare November 7, 2024 16:49
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4375 November 7, 2024 16:50 Inactive
end

def load_image
FeaturedImage.new(alt: data["image"]["alt"], sources: OpenStruct.new(data["image"]["sources"]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FeaturedImage.new(alt: data["image"]["alt"], sources: OpenStruct.new(data["image"]["sources"]))
FeaturedImage.new(alt: data.dig("image", "alt"), sources: OpenStruct.new(data.dig("image", "sources")))

<%= tag.source srcset: "#{image_path(block.image.sources.tablet)}, #{image_path(block.image.sources.tablet_2x)} 2x", media: "(min-width: 641px) and (max-width: 768px)" %>
<%= tag.source srcset: "#{image_path(block.image.sources.mobile)}, #{image_path(block.image.sources.mobile_2x)} 2x", media: "(max-width: 640px)" %>
<%= image_tag(block.image.sources.desktop, alt: block.image.alt, class: "app-b-hero__image") %>
<%= tag.source srcset: "#{block_image_path(block.image.sources.hero_desktop_1x)}, #{block_image_path(block.image.sources.hero_desktop_2x)} 2x", media: "(min-width: 769px)" %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently my branch drops the hero_ prefix from the sources hash, so they're just desktop_2x etc. That was just because it felt like duplication to be doing - type: "hero" and then reiterating hero_ a bunch of times. But it does introduce an inconsistency with the version names configured in whitehall, as those have to be globally unique, so they do need prefixes.

I don't mind either way really - I'd be happy to update my branch to put back the hero_s if you think its more consistent to have them. Or we could update them here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 actually maybe I can get it to match whats currently there exactly, and we can lose this PR 🤔

@@ -35,14 +35,14 @@ blocks:
navigation_group_id: Top Menu
- type: hero
image:
alt: "Placeholder alt text"
alt_text: "Placeholder alt text"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't mean to change this from alt to alt_text 😓

@KludgeKML
Copy link
Contributor Author

Closing because changes to Whitehall have made this PR obsolete (Whitehall is now giving us the images in the format we were already expecting).

@KludgeKML KludgeKML closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants