@wordpress/editor: Add estimated time to read to table of contents in editor#41611
Conversation
There was a problem hiding this comment.
Is there a better way to leave a space between the number and the text, is CSS more appropriate for this?
There was a problem hiding this comment.
Maybe using sprintf from @wordpress/i18n would be the way to go. It would also cover those languages that would put the word minutes after the number.
There was a problem hiding this comment.
There is also createInterpolateElement from @wordpress/element that can cover using React components:
https://github.com/WordPress/gutenberg/tree/trunk/packages/element#createinterpolateelement
Example usage:
|
@opr I'd like to accessibility review this PR but have no idea where the table of contents is. What is the aria-label on the button? Thanks. |
|
Hi @alexstine thank you - sure the |
alexstine
left a comment
There was a problem hiding this comment.
@opr Accessibility is good and I think the spacing reflects how other items are listed. I only checked this for keyboard navigation and general usability/code quality, I am unable to do visual testing. No idea how it looks. A sighted review would probably be good for this.
gziolo
left a comment
There was a problem hiding this comment.
Excellent addition. I left some minor feedback, but overall this looks great 💯
There was a problem hiding this comment.
Maybe using sprintf from @wordpress/i18n would be the way to go. It would also cover those languages that would put the word minutes after the number.
There was a problem hiding this comment.
Should we add a special case for minutes to read less than 1 (or 0.5)? In that case, we could display: Less than a minute. Otherwise, we might see 0 minutes.
There was a problem hiding this comment.
@gziolo I went with < 1 minute because without there being a number there it looks kind of weird.
Compared to:
|
@gziolo awesome thanks for the reminder about |
|
By the way, @richtabor created a WordPress plugin with a Post Reading Time block that is available at https://github.com/richtabor/post-reading-time-block. It could be a good addition to the core as well. |
Your suggestion looks good to me. |
|
@gziolo and @jameskoster thanks for your input. I've made the changes you suggested and re-ordered the panel. As for the time to read block, I think it would be better to bring that in in a separate PR, do you agree? |
Surely, it's outside of the scope of this PR. We want to keep it small. It's a good opportunity to discuss further work though before we jump into opening issues.
Looks good to me! I re-trigger one of the CI job to see if the test (unrelated to this PR) passes. |



What?
Adds an estimated time to read to the table of contents in the post editor.
Why?
It would be a useful tool for editors to know how long their article will take (the average) reader to read.
Closes #38593.
How?
I took an average of the reading rate (words per minute, but characters per minute for Chinese) from this source: https://irisreading.com/average-reading-speed-in-various-languages/. A lot of other sources cite 200 wpm is the average reading rate but I think they didn't account for other languages. Using the average of 189 should get us a pretty good estimate.
Using this, I created a
TimeToReadfunction, which usescountfrom@wordpress/wordcountto calculate how many minutes to display.The number is styled larger than the text. Please guide me on styling if we should do something different.
Testing Instructions
iabove the editor).Screenshots or screencast
Additional thoughts
If #41598 gets merged then we could possibly use
humanTimeDiffto get the locale specific time between now and the estimated minutes to read. This displays time differences including froma few seconds,x minutes,x hours,x days,x monthsandx years.The challenge here would be identifying how to split the resulting string into its locale-correct constituent parts (number of units of time, and string describing the unit of time) and styling the number and string differently. We also need to consider the case of the text only option, where the words are such that the post will take a single unit of time to read (i.e.
a minute) and how we would stylea minutewhere no number is present vs2 minuteswhere the number being larger than the text looks alright.