Skip to content

Instantly share code, notes, and snippets.

@NickDeckerDevs
Last active February 15, 2018 05:35
Show Gist options
  • Save NickDeckerDevs/e32f3c81ef882c52c3711f3f22dfb49c to your computer and use it in GitHub Desktop.
Save NickDeckerDevs/e32f3c81ef882c52c3711f3f22dfb49c to your computer and use it in GitHub Desktop.
Hubspot hubl read time for blogs / content
{# RENDER READ TIME #}
{% macro render_read_time(body) %}
{% set str = body|lower %}
{% set img_count = str|split('<img')|length %}
{% set img_minutes = ((img_count * 12) / 60)|round(0, 'common') %}
{% set read_time = (str|striptags|wordcount / 275)|round(0, 'common') + img_minutes %}
{{ read_time|string|trim ~ ' ' ~ render_read_time_suffix()|trim }}
{% endmacro %}
{# And here's the meta info for the <head> of the custom template... #}
{% if !topic and !is_listing_view %}
{# BLOG POST #}
<meta name="twitter:label1" value="Reading time" />
<meta name="twitter:data1" value="{{ blogMacros.render_read_time(content.post_body)|replace('\n', '')|trim }}" />
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment