dev-master
9999999-devText Statistics plugin for Craft CMS
The Requires
v1.0.1
1.0.1.0Text Statistics plugin for Craft CMS
The Requires
v1.0.0
1.0.0.0Text Statistics plugin for Craft CMS
The Requires
Text Statistics plugin for Craft CMS
This Craft plugin provides Twig functions to display information about your texts. It allows you to measure the readability of your content, calculate the average reading time or access other text statistics like sentence count., (*1)
The plugin is available on Packagist and can be installed using Composer. You can also download the latest release and copy the files into craft/plugins/textstatistics/., (*2)
$ composer require carlcs/craft-textstatistics
The plugin can be configured with a craft/config/textstatistics.php config file to set the default template used to render the reading time string and to set a default words per minute value., (*3)
When you generate text statistics using the getTextStatistics function the plugin returns a TextStatisticsModel with the following properties populated. Most of the data is calculated with the excellent Text Statistics library by Dave Child. For information about the provided readability scores have a look these Wikipedia articles:, (*4)
textLength
letterCount
syllableCount
wordCount
sentenceCount
readingTime
readingTimeMinutes
readingTimeString
gunningFog
fleschKincaid
{% do addToTextStatistics(entry.text) %} {% set statistics = getTextStatistics() %} {{ statistics.readingTimeString }} {# outputs "21 minutes" #}
{% set wpm = { 'en': 200, 'fr': 180, } %} {% set statistics = getTextStatistics(null, wpm[craft.locale]) %} {{ statistics.readingTimeString }} {# outputs "moins de 5 minutes" #}
{% for block in entry.article %} {% if block.type == 'text' %} {% do addToTextStatistics(block.text) %} {{ block.text }} {% endif %} {% if block.type == 'image' %} {% set image = block.image.first() %} {% if image %} {% do addToReadingTime(10) %} <img src="{{ image.getUrl() }}" alt="{{ image.title }}"> {% endif %} {% endif %} {% endfor %} {% set statistics = getTextStatistics() %}
Adds text to the data storage so you can later perform text statistics calculations from it., (*5)
text
(required) – The text to add to the data storage for text statistics. It can contain HTML tags, the plugin removes them before doing its calculations.articleId
(default ''
) – An ID to identify the article. Only required if you have multiple articles for text statistics on the same page.{% do addToTextStatistics(entry.myRichTextField) %}
Alternativly you can use the Twig filter., (*6)
{{ entry.myRichTextField|addToTextStatistics }}
Adds time to the data storage to further influence the reading time returned with the text statistics., (*7)
seconds
(required) – Time in seconds to add to the data storage for text statistics.articleId
(default ''
) – An ID to identify the article. Only required if you have multiple articles for text statistics on the same page.{% do addToReadingTime(15) %}
Performs the text statistics calculations for an article and returns the result as a TextStatisticsModel., (*8)
articleId
(default ''
) – An ID to identify the article. Only required if you have multiple articles for text statistics on the same page.wpm
(default 200
) – The average reading speed used for the reading time calculations in words per minute units.readingTimeTemplate
(default ) – The Twig template code used to render for the reading time string.{% set statistics = getTextStatistics() %} {{ statistics.gunningFog }} {# outputs "12.1" #}
Text Statistics plugin for Craft CMS
Text Statistics plugin for Craft CMS
Text Statistics plugin for Craft CMS