Skip to content

Commit

Permalink
+changelog-ignore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdcdev committed Jan 7, 2024
0 parents commit c3d16a1
Show file tree
Hide file tree
Showing 83 changed files with 10,237 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Contributing Guidelines

Contributions to this package are most welcome!

There is a test site in the solution to make working with this repository easier.
51 changes: 51 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Bug report"
description: "File a bug report to help improve this package."
labels: "bug"
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to report this issue as thoroughly as possible.
- type: input
id: "PackageVersion"
attributes:
label: "Which jcdcdev.Umbraco.ReadingTime version are you using?"
description: "Leave blank if you're not sure: the latest version will be assumed."
validations:
required: false
- type: input
id: "umbracoVersion"
attributes:
label: "Which Umbraco version are you using? For example: 10.4.0 - don't just write v10"
description: "Use the help icon in the Umbraco backoffice to find the version you're using."
validations:
required: true
- type: textarea
id: "summary"
attributes:
label: "Bug summary"
description: "Write a summary of the bug. Remember that you can format code and logs nicely with the `<>` button"
placeholder: >
Try to pinpoint it as much as possible.
Try to state the actual problem, and not just what you think the solution might be.
validations:
required: true
- type: textarea
attributes:
label: "Steps to reproduce"
id: "reproduction"
description: "How can we reproduce the problem on a clean AdminOnlyPackage + Umbraco install?"
placeholder: >
Please include any links, screenshots, stack-traces, etc.
validations:
required: true
- type: textarea
attributes:
label: "Expected result / actual result"
id: "result"
description: "What did you expect that would happen on your Umbraco site and what is the actual result of the above steps?"
placeholder: >
Describe the intended/desired outcome after you did the steps mentioned.
Describe the behaviour of the bug
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "Feature request"
description: "Suggest an idea for this package."
labels: "enhancement"
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to suggest this feature request!
- type: textarea
id: "summary"
attributes:
label: "Feature summary"
description: "Write a brief summary of the feature"
validations:
required: true
- type: textarea
id: "details"
attributes:
label: "Additional details"
description: "Provide any additional details or comments about the feature you are suggesting"
validations:
required: false
102 changes: 102 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# jcdcdev.Umbraco.ReadingTime

[![Umbraco Version](https://img.shields.io/badge/Umbraco-10.4+-%233544B1?style=flat&logo=umbraco)](https://umbraco.com/products/umbraco-cms/)
[![NuGet](https://img.shields.io/nuget/vpre/jcdcdev.Umbraco.ReadingTime?color=0273B3)](https://www.nuget.org/packages/jcdcdev.Umbraco.ReadingTime)
[![GitHub license](https://img.shields.io/github/license/jcdcdev/jcdcdev.Umbraco.ReadingTime?color=8AB803)](../LICENSE)
[![Downloads](https://img.shields.io/nuget/dt/jcdcdev.Umbraco.ReadingTime?color=cc9900)](https://www.nuget.org/packages/jcdcdev.Umbraco.ReadingTime/)

Custom Data Type for calculating reading time.

The following editors are currently supported:

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

## Quick Start

1. Install the [NuGet package](https://www.nuget.org/packages/jcdcdev.Umbraco.ReadingTime) in your Umbraco CMS website project.
2. Add the Reading Time data type to a document type.
- Note: You can configure the words per minute in the data type settings.
3. Save and publish content.
4. Reading Time will display in the backoffice

![A screenshot of the BackOffice showing Reading Time](https://raw.githubusercontent.com/jcdcdev/jcdcdev.Umbraco.ReadingTime/main/docs/screenshots/backoffice.png)

## Using the value in your templates

In your template, you can accessing the Reading Time property.

```csharp
<div class="alert alert-info">
Read in @Model.ReadingTime.DisplayTime()
</div>
```

## 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:

```json
{
"ReadingTime": {
"WordsPerMinute": 200
}
}
```

## Limitations

**Values are derived from published content only.**

Draft content is _not_ included in the calculation.

## Extending

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

```csharp
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:

```csharp
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](CONTRIBUTING.md).

## Acknowledgments (thanks!)

- LottePitcher - [opinionated-package-starter](https://github.com/LottePitcher/opinionated-package-starter)
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Build
on:
pull_request:
branches: "*"
workflow_dispatch:
jobs:
build:
uses: jcdcdev/jcdcdev.Github.UmbracoSimpleDeploy/.github/workflows/build-template.yml@main
with:
project-name: 'jcdcdev.Umbraco.ReadingTime'
project-path: './src/jcdcdev.Umbraco.ReadingTime/jcdcdev.Umbraco.ReadingTime.csproj'
23 changes: 23 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Release
on:
pull_request:
branches: "main"
types: [ closed ]
workflow_dispatch:
jobs:
build:
uses: jcdcdev/jcdcdev.Github.UmbracoSimpleDeploy/.github/workflows/build-template.yml@main
with:
project-name: 'jcdcdev.Umbraco.ReadingTime'
project-path: './src/jcdcdev.Umbraco.ReadingTime/jcdcdev.Umbraco.ReadingTime.csproj'
release:
needs:
- build
permissions:
contents: write
uses: jcdcdev/jcdcdev.Github.UmbracoSimpleDeploy/.github/workflows/release-template.yml@main
with:
artifact-name: ${{ needs.build.outputs.artifact-name }}
version: ${{ needs.build.outputs.version }}
secrets:
nuget-api-key: ${{ secrets.NUGET_API_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 jcdcdev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Binary file added docs/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[*]
max_line_length = 200
indent_style = tab
indent_size = 4
tab_width = 4

# ReSharper properties
resharper_braces_redundant = false
resharper_csharp_indent_style = space
resharper_csharp_wrap_after_declaration_lpar = true
resharper_csharp_wrap_parameters_style = chop_if_long
resharper_instance_members_qualify_declared_in = base_class
resharper_method_or_operator_body = expression_body
resharper_place_expr_method_on_single_line = true
resharper_braces_for_ifelse = required
10 changes: 10 additions & 0 deletions src/TestSite.10/Composer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Umbraco.Cms.Core.Composing;

namespace TestSite.Ten;

public class Composer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
}
}
19 changes: 19 additions & 0 deletions src/TestSite.10/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace TestSite.Ten
{
public class Program
{
public static void Main(string[] args)
=> CreateHostBuilder(args)
.Build()
.Run();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureUmbracoDefaults()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStaticWebAssets();
webBuilder.UseStartup<Startup>();
});
}
}
29 changes: 29 additions & 0 deletions src/TestSite.10/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:16958",
"sslPort": 44316
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Umbraco.Web.UI": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:44316;http://localhost:16958",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
65 changes: 65 additions & 0 deletions src/TestSite.10/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace TestSite.Ten
{
public class Startup
{
private readonly IWebHostEnvironment _env;
private readonly IConfiguration _config;

/// <summary>
/// Initializes a new instance of the <see cref="Startup" /> class.
/// </summary>
/// <param name="webHostEnvironment">The web hosting environment.</param>
/// <param name="config">The configuration.</param>
/// <remarks>
/// Only a few services are possible to be injected here https://github.com/dotnet/aspnetcore/issues/9337.
/// </remarks>
public Startup(IWebHostEnvironment webHostEnvironment, IConfiguration config)
{
_env = webHostEnvironment ?? throw new ArgumentNullException(nameof(webHostEnvironment));
_config = config ?? throw new ArgumentNullException(nameof(config));
}

/// <summary>
/// Configures the services.
/// </summary>
/// <param name="services">The services.</param>
/// <remarks>
/// This method gets called by the runtime. Use this method to add services to the container.
/// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940.
/// </remarks>
public void ConfigureServices(IServiceCollection services)
{
services.AddUmbraco(_env, _config)
.AddBackOffice()
.AddWebsite()
.AddComposers()
.Build();
}

/// <summary>
/// Configures the application.
/// </summary>
/// <param name="app">The application builder.</param>
/// <param name="env">The web hosting environment.</param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseUmbraco()
.WithMiddleware(u =>
{
u.UseBackOffice();
u.UseWebsite();
})
.WithEndpoints(u =>
{
u.UseInstallerEndpoints();
u.UseBackOfficeEndpoints();
u.UseWebsiteEndpoints();
});
}
}
}
Loading

0 comments on commit c3d16a1

Please sign in to comment.