-
Notifications
You must be signed in to change notification settings - Fork 17
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 contents lists under specific conditions #719
Conversation
end | ||
|
||
def first_item_content | ||
element = Nokogiri::HTML(body).css('p').first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions about this part:
- what happens if the content begins with something that's not a paragraph, eg a table or image?
- is this relatively slow at the moment? how performant could we make it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point about the paragraphs - I'll try and find some Detailed Guides examples with other content and work something out.
Steve's got a suggestion for optimising the Nokogiri stuff below 👇
@@ -3,6 +3,7 @@ module ContentsList | |||
include ActionView::Helpers::UrlHelper | |||
include TypographyHelper | |||
|
|||
WORD_COUNT_LIMIT = 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if total word count is a useful heuristic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What @fofr said. Some formats will contain medical terminology with superlongtechnicalwords, some will contain more legalese. I think a char count might be a more honest metric.
Love this as a starting point. Are there some example URLs showing the effect? |
end | ||
|
||
def first_item_content | ||
element = Nokogiri::HTML(body).css('p').first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can optimise this a bit by only parsing the body once with Nokogiri, building the contents list as the existing implementation does, but also populating the first n chapters so we can check their length.
This https://stackoverflow.com/questions/3484874/how-to-split-a-html-document-using-nokogiri does something similar by building a hash of chapters.
|
||
def long_first_item_body | ||
"<div class='govspeak'><h2 id='response-in-the-uk'>Item 1</h2> | ||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean facilisis |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Faker gem is great for generating this sort of thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one! Will keep that in mind for production tests 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can also use the govuk_schema gem to generate random examples to test this with
We've got this as an example of the contents list not showing if there's only one item: https://government-frontend-pr-719.herokuapp.com/government/topical-events/ukraine-reform-conference/about |
<%= render "components/contents-list-with-body", { | ||
contents: @content_item.contents | ||
} do %> | ||
<% if @content_item.show_content_list? %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be better implemented in the contents-list-with-body
component as there's already a check for @content_item.contents.any?
which prevents the list and the contents link from displaying in the absence of any contents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah definitely - I've noted it's not an ideal implementation in the PR description, and would need to investigate other formats using this component before making changes to it in prod.
e121f0e
to
1a739c7
Compare
1a739c7
to
96338e2
Compare
96338e2
to
f359951
Compare
f359951
to
d8cc89d
Compare
d8cc89d
to
e8f642f
Compare
@fofr @steventux I've added a condition for showing a contents list when a table has a certain number of rows, and a condition for when an image is present (I imagine we could use the same idea for videos). Regarding images, I had a quick chat with Steve about this last night and we agreed that since it seems that images are always the same size, the simplest way to deal with them is to just show contents lists when they're present. |
e8f642f
to
7ef77a5
Compare
return unless table.present? | ||
|
||
row_count = table.css('tr').count | ||
row_count > 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this PR is still quite experimental, so a reminder to use the relevant constant TABLE_ROW_LIMIT
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that'll be me messing around with row numbers and not replacing the constant 🤦♀️
7ef77a5
to
5753322
Compare
row_count > 10 | ||
end | ||
|
||
def find_table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very similar to the following method, wonder if the logic is similar enough for one method.
5753322
to
5bc0ef2
Compare
5bc0ef2
to
9afbb85
Compare
b5e4cd2
to
c22e4b6
Compare
c22e4b6
to
8f38941
Compare
8f38941
to
4253f27
Compare
4253f27
to
8f38941
Compare
In order to generate lorem ipsum for longer pieces of content in tests.
We have found instances where displaying a contents list on a page isn't always appropriate, such as when there is only one item in the list. We have decided to not show the contents list if there are fewer than three items, with an additional condition that we do show the contents list if the first item's content is more than 100 characters.
We now show the contents list in cases where there are only two content items if the first item contains a table with more than 13 rows.
We now show the contents list when there are 2 items on a contents lists and the first item has both an image and content over 50 characters.
We now show the contents list when there are 2 items on a contents lists and the first item has both an image and a table with more than 6 rows.
We update test coverage to reflect that contents lists are shown under certain conditions.
We update test coverage to reflect that contents lists are shown under certain conditions.
We update test coverage to reflect that contents lists are shown under certain conditions.
We update test coverage to reflect that contents lists are shown under certain conditions.
We update test coverage to reflect that contents lists are shown under certain conditions. We have found that Working Groups with policies don't always have a body, which caused problems in the current code implementation when it came to checking content length in the first item of a contents list. Therefore we now check if a "first item" is present in the body before carrying out the content checks.
We update test coverage to reflect that contents lists are shown under certain conditions.
We update test coverage to reflect that contents lists are shown under certain conditions.
8f38941
to
5ebd42f
Compare
For https://trello.com/c/2UIR4Sen/210-investigate-how-to-deal-with-short-content-lists
We have identified that there are occasions where it's not appropriate to display a contents list, for example when there is only one item on the list. Having spiked an approach for displaying a contents list dependent on certain conditions, this PR implements the approach. We've reached the below criteria for displaying a contents list in conjunction with Si Stephens-Manassiev in the content team:
To Do
Component guide for this PR:
https://government-frontend-pr-719.herokuapp.com/component-guide