jcdcdev.Umbraco.ReadingTime 10.0.0-alpha0001

This is a prerelease version of jcdcdev.Umbraco.ReadingTime.
There is a newer version of this package available.
See the version list below for details.
dotnet add package jcdcdev.Umbraco.ReadingTime --version 10.0.0-alpha0001
NuGet\Install-Package jcdcdev.Umbraco.ReadingTime -Version 10.0.0-alpha0001
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="jcdcdev.Umbraco.ReadingTime" Version="10.0.0-alpha0001" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add jcdcdev.Umbraco.ReadingTime --version 10.0.0-alpha0001
#r "nuget: jcdcdev.Umbraco.ReadingTime, 10.0.0-alpha0001"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install jcdcdev.Umbraco.ReadingTime as a Cake Addin
#addin nuget:?package=jcdcdev.Umbraco.ReadingTime&version=10.0.0-alpha0001&prerelease

// Install jcdcdev.Umbraco.ReadingTime as a Cake Tool
#tool nuget:?package=jcdcdev.Umbraco.ReadingTime&version=10.0.0-alpha0001&prerelease

jcdcdev.Umbraco.ReadingTime

Umbraco Version GitHub license NuGet Downloads

Custom Data Type for calculating reading time. With full variant support!

The following editors are currently supported:

  • Rich Text
  • Markdown
  • Block Grid
  • Block List
  • Nested Content
  • Textstring
  • Textarea

Quick Start

  1. Install the NuGet package in your Umbraco CMS website project.

     dotnet add package jcdcdev.Umbraco.ReadingTime
    
  2. Add the Reading Time data type to a document type. You can configure:

    • Words per minute (default is 200)
    • Min Unit (default is Minute)
    • Max Unit (default is Minute) A screenshot of the BackOffice showing Reading Time data type
  3. Save and publish content.

  4. Reading Time will display in the backoffice

    A screenshot of the BackOffice showing Reading Time

Using the value in your templates

In your template, you can accessing the Reading Time property value like any other property:

 @Model.ReadingTime.DisplayTime()

A screenshot of page showing Reading Time

Overriding the default display

The DisplayTime method will format the reading time as a string using Humanizer. This supports variants, meaning the reading time will be displayed based on the pluralisation rules of the current culture (e.g. "1 minute", "2 minutes", "0 minuter").

Min and max TimeUnit values are derived from the Data Type settings. The below example shows how you can ensure only seconds are displayed.

 Model.ReadingTime.DisplayTime(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Second)

Configuration

You can change the average words per minute in the data type settings.

When creating a new data type, the default will be 200 words per minute. To change this default, adjust your appsettings.json file:

{
  "ReadingTime": {
    "WordsPerMinute": 200
  }
}

Limitations

Values are derived from published content only.

Draft content is not included in the calculation.

Words per minute applies to all variants.

It is not currently possible to configure words per minute per culture.

Extending

You can extend the data type to support additional editors by implementing the IReadingTimeValueProvider interface.

public class MyCustomReadingTimeValueProvider : IReadingTimeValueProvider
{
    public bool CanConvert(IPropertyType type)
    {
        return type.EditorAlias == "MyCustomEditorAlias";
    }

    public TimeSpan? GetReadingTime(IProperty property, string? culture, string? segment, IEnumerable<string> availableCultures, ReadingTimeConfiguration config)
    {
        var value = property.GetValue(culture, segment, true);
        if (value is string text)
        {
            return text.GetReadingTime(config.WordsPerMinute);
        }

        return null;
     }
 }

Don't forget to register your custom value provider:

public class Composer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.ReadingTimeValueProviders().Append<MyCustomReadingTimeValueProvider>();
    }
}

Contributing

Contributions to this package are most welcome! Please read the Contributing Guidelines.

Acknowledgments (thanks!)

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
14.0.1-alpha0003 41 6/24/2024
14.0.0 78 6/6/2024
14.0.0-alpha0008 64 6/6/2024
14.0.0-alpha0005 66 6/6/2024
14.0.0-alpha0003 58 6/4/2024
14.0.0-alpha0001 60 5/25/2024
13.0.1 153 5/25/2024
13.0.0 79 5/25/2024
13.0.0-alpha0001 61 5/25/2024
12.0.1 69 5/25/2024
12.0.0 73 5/25/2024
12.0.0-alpha0001 61 5/25/2024
10.0.1 75 5/25/2024
10.0.0 72 5/25/2024
10.0.0-alpha0001 68 5/25/2024
0.3.1 449 4/5/2024
0.3.0 113 4/2/2024
0.2.0 115 3/31/2024
0.1.1 566 1/8/2024
0.1.0 91 1/8/2024