|
1 | 1 | # jcdcdev.Umbraco.ReadingTime |
2 | 2 |
|
3 | | -[](https://marketplace.umbraco.com/package/jcdcdev.umbraco.readingtime) |
4 | | -[](https://github.com/jcdcdev/jcdcdev.Umbraco.ReadingTime/blob/main/LICENSE) |
5 | | -[](https://www.nuget.org/packages/jcdcdev.Umbraco.ReadingTime/) |
6 | | - |
7 | | -Custom Data Type for calculating reading time. With full variant support! |
8 | | - |
9 | | -The following editors are currently supported: |
10 | | - |
11 | | -- Rich Text |
12 | | -- Markdown |
13 | | -- Block Grid |
14 | | -- Block List |
15 | | -- Nested Content |
16 | | -- Textstring |
| 3 | +[](https://marketplace.umbraco.com/package/jcdcdev.Umbraco.ReadingTime) |
| 4 | +[](https://github.com/jcdcdev/jcdcdev.Umbraco.ReadingTime?tab=MIT-1-ov-file) |
| 5 | +[](https://www.nuget.org/packages/jcdcdev.Umbraco.ReadingTime) |
| 6 | +[](https://jcdc.dev/umbraco-packages/reading-time) |
| 7 | + |
| 8 | + |
| 9 | +Custom Data Type for calculating reading time. With full variant support! |
| 10 | + |
| 11 | +The following editors are currently supported: |
| 12 | + |
| 13 | +- Rich Text |
| 14 | +- Markdown |
| 15 | +- Block Grid |
| 16 | +- Block List |
| 17 | +- Nested Content |
| 18 | +- Textstring |
17 | 19 | - Textarea |
18 | 20 |
|
19 | 21 | ## Quick Start |
20 | 22 |
|
21 | | -1. Install the [NuGet package](https://www.nuget.org/packages/jcdcdev.Umbraco.ReadingTime) in your Umbraco CMS website project. |
22 | | - ``` |
23 | | - dotnet add package jcdcdev.Umbraco.ReadingTime |
24 | | - ``` |
25 | | -2. Add the Reading Time data type to a document type. You can configure: |
26 | | - - `Words per minute` (default is 200) |
27 | | - - `Min Unit` (default is Minute) |
28 | | - - `Max Unit` (default is Minute) |
29 | | -  |
30 | | -3. Save and publish content. |
31 | | -4. Reading Time will display in the backoffice |
32 | | - |
33 | | -  |
34 | | - |
35 | | -## Using the value in your templates |
36 | | - |
37 | | -In your template, you can accessing the Reading Time property value like any other property: |
38 | | - |
39 | | -```html |
40 | | - @Model.ReadingTime.DisplayTime() |
| 23 | +1. Install the [NuGet package](https://www.nuget.org/packages/jcdcdev.Umbraco.ReadingTime) in your Umbraco CMS website project. |
| 24 | + ``` |
| 25 | + dotnet add package jcdcdev.Umbraco.ReadingTime |
| 26 | + ``` |
| 27 | +2. Add the Reading Time data type to a document type. You can configure: |
| 28 | + - `Words per minute` (default is 200) |
| 29 | + - `Min Unit` (default is Minute) |
| 30 | + - `Max Unit` (default is Minute) |
| 31 | +3. Save and publish content. |
| 32 | +4. Reading Time will display in the backoffice |
| 33 | + |
| 34 | +### Using the value in your templates |
| 35 | + |
| 36 | +In your template, you can accessing the Reading Time property value like any other property: |
| 37 | + |
| 38 | +```html |
| 39 | + @Model.ReadingTime.DisplayTime() |
41 | 40 | ``` |
42 | 41 |
|
43 | | - |
44 | | - |
45 | | -### Overriding the default display |
46 | | -The `DisplayTime` method will format the reading time as a string using [Humanizer](https://github.com/Humanizr/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"). |
47 | | - |
48 | | -Min and max `TimeUnit` values are derived from the Data Type settings. The below example shows how you can ensure only seconds are displayed. |
49 | | - |
50 | | -```csharp |
51 | | - Model.ReadingTime.DisplayTime(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Second) |
52 | | -``` |
53 | | - |
54 | | - |
55 | | - |
56 | 42 | ## Configuration |
57 | 43 |
|
58 | | -You can change the average words per minute in the data type settings. |
59 | | - |
60 | | -When creating a new data type, the default will be 200 words per minute. To change this default, adjust your `appsettings.json` file: |
61 | | - |
62 | | -```json |
63 | | -{ |
64 | | - "ReadingTime": { |
65 | | - "WordsPerMinute": 200 |
66 | | - } |
67 | | -} |
68 | | -``` |
69 | | - |
70 | | -## Limitations |
71 | | - |
72 | | -**Values are derived from published content only.** |
73 | | - |
74 | | -Draft content is _not_ included in the calculation. |
75 | | - |
76 | | -**Words per minute applies to all variants.** |
77 | | - |
78 | | -It is not currently possible to configure words per minute per culture. |
| 44 | +You can change the average words per minute in the data type settings. |
| 45 | + |
| 46 | +When creating a new data type, the default will be 200 words per minute. |
79 | 47 |
|
80 | 48 | ## Extending |
81 | 49 |
|
82 | | -You can extend the data type to support additional editors by implementing the `IReadingTimeValueProvider` interface. |
83 | | - |
84 | | -```csharp |
85 | | -public class MyCustomReadingTimeValueProvider : IReadingTimeValueProvider |
86 | | -{ |
87 | | - public bool CanConvert(IPropertyType type) |
88 | | - { |
89 | | - return type.EditorAlias == "MyCustomEditorAlias"; |
90 | | - } |
91 | | - |
92 | | - public TimeSpan? GetReadingTime(IProperty property, string? culture, string? segment, IEnumerable<string> availableCultures, ReadingTimeConfiguration config) |
93 | | - { |
94 | | - var value = property.GetValue(culture, segment, true); |
95 | | - if (value is string text) |
96 | | - { |
97 | | - return text.GetReadingTime(config.WordsPerMinute); |
98 | | - } |
99 | | - |
100 | | - return null; |
101 | | - } |
102 | | - } |
| 50 | +The `DisplayTime` method will format the reading time as a string using [Humanizer](https://github.com/Humanizr/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"). |
| 51 | + |
| 52 | +Min and max `TimeUnit` values are derived from the Data Type settings. The below example shows how you can ensure only seconds are displayed. |
| 53 | + |
| 54 | +```csharp |
| 55 | + Model.ReadingTime.DisplayTime(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Second) |
103 | 56 | ``` |
104 | 57 |
|
105 | | -Don't forget to register your custom value provider: |
| 58 | +## Contributing |
| 59 | + |
| 60 | +Contributions to this package are most welcome! Please visit the [Contributing](https://github.com/jcdcdev/jcdcdev.Umbraco.ReadingTime/contribute) page. |
106 | 61 |
|
107 | | -```csharp |
108 | | -public class Composer : IComposer |
109 | | -{ |
110 | | - public void Compose(IUmbracoBuilder builder) |
111 | | - { |
112 | | - builder.ReadingTimeValueProviders().Append<MyCustomReadingTimeValueProvider>(); |
113 | | - } |
114 | | -} |
115 | | -``` |
| 62 | +## Acknowledgements (Thanks) |
116 | 63 |
|
117 | | -## Contributing |
| 64 | +- LottePitcher - [opinionated-package-starter](https://github.com/LottePitcher/opinionated-package-starter) |
118 | 65 |
|
119 | | -Contributions to this package are most welcome! Please read the [Contributing Guidelines](https://github.com/jcdcdev/jcdcdev.Umbraco.ReadingTime/blob/main/.github/CONTRIBUTING.md). |
120 | 66 |
|
121 | | -## Acknowledgments (thanks!) |
122 | 67 |
|
123 | | -- LottePitcher - [opinionated-package-starter](https://github.com/LottePitcher/opinionated-package-starter) |
0 commit comments