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

Display image credit for lead images #1190

Merged
merged 3 commits into from
Dec 19, 2018
Merged

Conversation

leenagupte
Copy link
Contributor

@leenagupte leenagupte commented Dec 18, 2018

Trello: https://trello.com/c/hGmJ5BfV
Related to:

Motivation

Content Publisher allows publishers to add an image credit, but we are not displaying this data on the frontend

Expected changes

Desktop

screen shot 2018-12-18 at 15 22 35

Mobile

screen shot 2018-12-18 at 16 24 09

Paired with @DilwoarH

@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 18, 2018 15:42 Inactive
@leenagupte leenagupte changed the title Add image credit to news Display image credit for lead images Dec 18, 2018
@@ -9,4 +10,10 @@
<%= caption %>
</figcaption>
<% end %>

<% if credit.present? %>
<figcredit class="app-c-figure__figcredit">
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this wasn't meant to be custom element but rather part of the <figcaption> or a separate <span>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is figcaption? We were trying to follow the pattern defined by captions, but weren't sure where this element is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we just make it a span?

Copy link
Contributor

Choose a reason for hiding this comment

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

<figcaption> is a defined element representing a caption or a legend associated with an image/figure. They must be placed inside a <figure> element to be semantically correct. There is no html element for credits though, so we can use a generic tag (i.e. <span> or we can include the credits inside the <figcaption> element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL! I thought figcaption was something we'd made up!

I'll use figcaption for consistency.

Copy link
Contributor

@alex-ju alex-ju Dec 19, 2018

Choose a reason for hiding this comment

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

As @vanitabarrett mentioned, <figure> should only have one <figcaption> so it probably makes more sense to be included in the existing tag.

@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 18, 2018 16:17 Inactive
@leenagupte leenagupte force-pushed the add-image-credit-to-news branch from 97ab837 to d9e8ed1 Compare December 18, 2018 16:31
@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 18, 2018 16:31 Inactive
@leenagupte leenagupte force-pushed the add-image-credit-to-news branch from d9e8ed1 to 3d17a39 Compare December 18, 2018 16:35
@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 18, 2018 16:35 Inactive
@vanitabarrett
Copy link
Contributor

vanitabarrett commented Dec 19, 2018

@leenagupte Would it make more sense to just include the credit as part of the original image figcaption element? E.g:

<figcaption class="app-c-figure__figcaption">
      <%= caption %>

     <% if credit.present? %>
          <p>Image credit: <%= credit %></p>
     <% end %>
    </figcaption>
  <% end %>

Copy link
Contributor

@vanitabarrett vanitabarrett left a comment

Choose a reason for hiding this comment

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

I'm not sure about having 2 figcaption elements when there is both a caption and a credit. I think it would make more sense to include the credit text inside the figcaption?

@leenagupte leenagupte force-pushed the add-image-credit-to-news branch from 3d17a39 to 82b95cf Compare December 19, 2018 13:27
@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 19, 2018 13:28 Inactive
@leenagupte
Copy link
Contributor Author

@vanitabarrett @alex-ju I've made the changes you recommended and fixed-up.

@leenagupte leenagupte force-pushed the add-image-credit-to-news branch from 82b95cf to 778ec0f Compare December 19, 2018 13:30
@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 19, 2018 13:30 Inactive
.app-c-figure__figcaption-text {
margin-bottom: $gutter-one-third;

@include media(mobile) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We normally try and do mobile-first development, which means our CSS should be based on mobile devices and we should add any other styling for larger screen sizes in media queries. So in this case, it would mean swapping round the CSS you've added here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vanitabarrett Updated and fixed up.

<figcaption class="app-c-figure__figcaption">
<%= caption %>
<% unless caption.blank? %>
<div class="app-c-figure__figcaption-text">
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use paragraph tags here instead of divs? For both app-c-figure__figcaption-text and app-c-figure__figcaption-credit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Not sure what the difference re: <p> and <div> is to be honest.

Copy link
Contributor

@vanitabarrett vanitabarrett Dec 19, 2018

Choose a reason for hiding this comment

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

Visually, they probably look the same unless you add your own styling. It's more about the semantics - a <p> (paragraph tag) is designed to wrap text, whereas a <div> is just a general containing element (which we tend to use for grouping or layout). Using semantic HTML means we are properly describing what the document/page is made up of: a load of div elements won't tell you a lot, but things like p, image, a etc give you more information.

Copy link
Contributor

Choose a reason for hiding this comment

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

I hope that makes sense! 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vanitabarrett updated and fixed up.


<% if credit.present? %>
<div class="app-c-figure__figcaption-credit">
Image credit: <%= credit %>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should "Image credit" come from a translation file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you know what happens if there isn't a translation available for the other languages?

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought it fell back to the english one... but you can provide a default too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right.

The I18n library will use English as a default locale, i.e. if a different locale is not set, :en will be used for looking up translations.

From: https://guides.rubyonrails.org/i18n.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vanitabarrett I've added a translation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vanitabarrett Updated and fixed up.

Adds a margin to the bottom of the caption in desktop view. This works
as a line-break between the caption and in the image credit.

The extra line isn't displayed on mobiles as this follows the pattern
being developed for displaying image credits on inline images
@leenagupte leenagupte force-pushed the add-image-credit-to-news branch from 778ec0f to 54ab422 Compare December 19, 2018 14:07
@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 19, 2018 14:07 Inactive
@leenagupte leenagupte force-pushed the add-image-credit-to-news branch from 54ab422 to e995617 Compare December 19, 2018 14:25
@benthorner benthorner temporarily deployed to government-frontend-pr-1190 December 19, 2018 14:26 Inactive
@@ -14,7 +14,7 @@

<% if credit.present? %>
<p class="app-c-figure__figcaption-credit">
Image credit: <%= credit %>
<%= I18n.t("components.figure.image_credit") %>: <%= credit %>
Copy link
Contributor

Choose a reason for hiding this comment

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

You could make the credit part of the translation string. E.g: I18n.t("component.figure.image_credit, credit: credit) and then in the translation file something like image_credit: "Image credit: %{credit}"

But that's not necessary, this is fine too 👍

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 like that better!

The translations default to English if there isn't an entry for a locale.
Content Items affected:

* Case Study
* Fatality Notice
* News Articles
* Speech
* Take Part
* World Location News Article

At the moment only the Content Publisher app supports image credits, so they will only be
displayed on news articles for the time being.
@vanitabarrett
Copy link
Contributor

Looks great! 💯

@leenagupte leenagupte merged commit 8c80471 into master Dec 19, 2018
@leenagupte leenagupte deleted the add-image-credit-to-news branch December 19, 2018 15:11
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.

4 participants