Page Builder: Reading time component
leandrocp opened this issue · 1 comments
leandrocp commented
Provide a component to display a "reading time" component as:
<BeaconWeb.Components.reading_time />
That component should return the amount in minutes, in the the example below it would return the value 8
. Formatting is up to who is building the page.
Use the following logic to calculate the reading time:
WORDS_PER_MINUTE = 270
estimated_time_in_minutes = trunc((String.split(content, " ") |> length()) / WORDS_PER_MINUTE)
That formula needs the page content
but a component doesn't have access to such value, so it will require adding the page path in the LiveView process as:
Process.put(:__beacon_page_path__, path)
Similar to
beacon/lib/beacon_web/live/page_live.ex
Line 83 in cbe3bf7
Then in the component you're able to lookup the route from that path.