Skip to content

Commit

Permalink
Merge pull request #3 from wiredviews/fix/page-link-retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
seangwright authored Oct 10, 2022
2 parents af8c48f + c2ea6a6 commit a9a0e69
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<Authors>$(Company)</Authors>
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
<Trademark>$(Company)™</Trademark>
<Product>XperienceCommunity.PageLinkTagHelpers</Product>
<VersionPrefix>2.0.0</VersionPrefix>
<Product>XperienceCommunity.PageLinks</Product>
<VersionPrefix>3.0.0</VersionPrefix>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Title>$(Product)</Title>
<PackageProjectUrl>https://github.com/wiredviews/xperience-page-link-tag-helpers</PackageProjectUrl>
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Xperience Page Link Tag Helpers
# Xperience Page Links

[![GitHub Actions CI: Build](https://github.com/wiredviews/xperience-page-link-tag-helpers/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/wiredviews/xperience-page-link-tag-helpers/actions/workflows/ci.yml)

Expand Down Expand Up @@ -34,6 +34,10 @@ This package is compatible with ASP.NET Core 3.1+ applications or libraries inte

> Populate the `Guid` values with the `NodeGUID` of each page in the content tree that you need to link to in your application.

```csharp
using XperienceCommunity.LinkablePages;
```

```csharp
public namespace Sandbox.Shared
{
Expand Down Expand Up @@ -61,6 +65,10 @@ This package is compatible with ASP.NET Core 3.1+ applications or libraries inte

1. In the shared class library, create an implementation of the `ILinkablePageInventory` interface, which will be used to determine which Pages in the application should be protected:

```csharp
using XperienceCommunity.LinkablePages;
```

```csharp
public class LinkablePageInventory : ILinkablePageInventory
{
Expand Down Expand Up @@ -96,6 +104,10 @@ This package is compatible with ASP.NET Core 3.1+ applications or libraries inte
1. Register the library with ASP.NET Core DI:
```csharp
using XperienceCommunity.LinkablePages;
```
```csharp
public void ConfigureServices(IServiceCollection services)
{
Expand All @@ -114,6 +126,8 @@ This package is compatible with ASP.NET Core 3.1+ applications or libraries inte
1. Add the data protection custom module registration to your ASP.NET Core application (in `Startup.cs` or wherever you register your dependencies):
```csharp
using XperienceCommunity.LinkablePages;
[assembly: RegisterModule(typeof(LinkablePageProtectionModule))]
```
Expand All @@ -130,6 +144,10 @@ This package is compatible with ASP.NET Core 3.1+ applications or libraries inte
1. Create a custom module class in your CMS application to register the `LinkablePageProtectionModule` and the `ILinkablePageInventory` implementation:
```csharp
using XperienceCommunity.LinkablePages;
```
```csharp
// Registers this custom module class
[assembly: RegisterModule(typeof(DependencyRegistrationModule))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>disable</Nullable>

<Description>
Provides abstraction and data protection for pages that can be linked to for Kentico Xperience 13.0 applications to help developers easily generate links to pages in the content tree.
</Description>

<Product>XperienceCommunity.LinkablePages</Product>
<Title>$(Product)</Title>
<PackageTags>$(PackageTags)</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Kentico.Xperience.Libraries" Version="[13.0.0, 13.1.0)" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CMS.DocumentEngine;
using CMS.DocumentEngine.Routing;
Expand All @@ -12,7 +13,7 @@ namespace XperienceCommunity.PageLinkTagHelpers
/// </summary>
public interface ILinkablePageLinkRetriever
{
Task<LinkablePageLinkResult?> RetrieveAsync(Guid nodeGUID);
Task<LinkablePageLinkResult?> RetrieveAsync(Guid nodeGUID, CancellationToken token = default);
}

/// <summary>
Expand All @@ -30,7 +31,7 @@ public DefaultLinkablePageLinkRetriever(IPageRetriever pageRetriever, IPageUrlRe
this.pageUrlRetriever = pageUrlRetriever;
}

public async Task<LinkablePageLinkResult?> RetrieveAsync(Guid nodeGUID)
public async Task<LinkablePageLinkResult?> RetrieveAsync(Guid nodeGUID, CancellationToken token = default)
{
var pages = await pageRetriever
.RetrieveAsync<TreeNode>(
Expand All @@ -39,7 +40,8 @@ public DefaultLinkablePageLinkRetriever(IPageRetriever pageRetriever, IPageUrlRe
// Optimize returned columns, .WithPageUrlPaths() will add back the ones it needs
.Columns(nameof(TreeNode.DocumentName))
.WithPageUrlPaths(),
cache => cache.Key($"page-link|{nodeGUID}"));
cache => cache.Key($"page-link|{nodeGUID}"),
cancellationToken: token);

var page = pages.FirstOrDefault();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class ServiceCollectionLinkablePageExtensions
/// <returns></returns>
public static IServiceCollection AddXperienceCommunityPageLinks(this IServiceCollection services)
{
services.TryAddSingleton<ILinkablePageLinkRetriever, DefaultLinkablePageLinkRetriever>();
services.TryAddTransient<ILinkablePageLinkRetriever, DefaultLinkablePageLinkRetriever>();

return services;
}
Expand All @@ -28,7 +28,7 @@ public static IServiceCollection AddXperienceCommunityPageLinks(this IServiceCol
public static IServiceCollection AddXperienceCommunityPageLinks<TCustomLinkablePageLinkRetriever>(this IServiceCollection services)
where TCustomLinkablePageLinkRetriever : class, ILinkablePageLinkRetriever
{
services.TryAddSingleton<ILinkablePageLinkRetriever, TCustomLinkablePageLinkRetriever>();
services.TryAddTransient<ILinkablePageLinkRetriever, TCustomLinkablePageLinkRetriever>();

return services;
}
Expand All @@ -43,7 +43,7 @@ public static IServiceCollection AddXperienceCommunityPageLinks<TCustomLinkableP
public static IServiceCollection AddXperienceCommunityPageLinksProtection<TCustomLinkablePageInventory>(this IServiceCollection services)
where TCustomLinkablePageInventory : class, ILinkablePageInventory
{
services.TryAddSingleton<ILinkablePageInventory, TCustomLinkablePageInventory>();
services.TryAddTransient<ILinkablePageInventory, TCustomLinkablePageInventory>();

return services;
}
Expand Down

0 comments on commit a9a0e69

Please sign in to comment.