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