BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph 1.0.1-alpha.440ac6a

This is a prerelease version of BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph.
There is a newer version of this package available.
See the version list below for details.
dotnet add package BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph --version 1.0.1-alpha.440ac6a                
NuGet\Install-Package BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph -Version 1.0.1-alpha.440ac6a                
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="BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph" Version="1.0.1-alpha.440ac6a" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph --version 1.0.1-alpha.440ac6a                
#r "nuget: BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph, 1.0.1-alpha.440ac6a"                
#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 BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph as a Cake Addin
#addin nuget:?package=BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph&version=1.0.1-alpha.440ac6a&prerelease

// Install BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph as a Cake Tool
#tool nuget:?package=BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph&version=1.0.1-alpha.440ac6a&prerelease                

Xperience Open Graph Component NuGet Version

This package provides a Mvc ViewComponent implementation for rendering common OpenGraph meta elements from content within Xperience.

Usage

  • Install the package into your Xperience Mvc project:
dotnet add package BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph

OR

<PackageReference Include="BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph" Version="x.x.x" />
  • Configure services in Startup.cs:
using BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph;
using Kentico.Web.Mvc;
using Microsoft.Extensions.DependencyInjection;

// ...

public void ConfigureServices( IServiceCollection services )
{
    services.AddMvc();
    services.AddKentico();

    // ...

    services.AddXperienceOpenGraphComponent();
}
  • Invoke the component within the <head/> of a Razor View:
<head>
    @* ... *@

    @await Component.InvokeAsync( nameof( XperienceOpenGraph ) )

    @* OR *@

    @( await Component.InvokeAsync<XperienceOpenGraph>( )

    @* ... *@
</head>

Extensibility

Customize Source TreeNode Field Names

The default IOpenGraphDataRetriever implementation, OpenGraphDataRetriever, uses the configured OpenGraphDataRetrievalOptions.FieldNames instance to determine the source fields of a TreeNode when retrieving an OpenGraphData instance.

The default source field names are represented by the OpenGraphPageFields type, and can be configured using the Options Pattern:

using BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph;
using Kentico.Web.Mvc;
using Microsoft.Extensions.DependencyInjection;

// ...

public void ConfigureServices( IServiceCollection services )
{
    services.AddMvc();
    services.AddKentico();

    // ...

    services.AddXperienceOpenGraphComponent();
    services.PostConfigure<OpenGraphDataRetrievalOptions>(
        options =>
        {
            // Use the `DocumentPageTitle` and `DocumentPageDescription` fields provided by Xperience.
            options.UseMetadataFields();

            options.FieldsNames.Image = "CustomOpenGraphImage";
            options.FieldsNames.Video = "CustomOpenGraphVideo";
        }
    )
}
Customize OpenGraphData Retrieval

The default IOpenGraphDataRetriever implementation, OpenGraphDataRetriever provides various virtual methods that allow customization of OpenGraphData retrieval and mapping. This can be done by inheriting from OpenGraphDataRetriever, and overriding the registration in the IServiceCollection:

CustomOpenGraphDataRetriever.cs

using BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph.Abstractions;
using BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph.Infrastructure;
using CMS.Base;
using CMS.DocumentEngine;
using Kentico.Content.Web.Mvc;
using Microsoft.Extensions.Options;

public class CustomOpenGraphDataRetriever : OpenGraphDataRetriever
{

    public CustomOpenGraphDataRetriever(
        IOptions<OpenGraphDataRetrievalOptions> defaultOptions,
        ISiteService siteService
    ) : base( defaultOptions, siteService )
    {
    }

    protected override async Task<OpenGraphData> RetrieveAsync( TreeNode page, Action<OpenGraphDataRetrievalOptions> configure = null, CancellationToken cancellation = default )
    {
        var data = await base.RetrieveAsync( page, configure, cancellation );

        // Do something with it...

        return data;
    }

}

Startup.cs

using BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph;
using Kentico.Web.Mvc;
using Microsoft.Extensions.DependencyInjection;

// ...

public void ConfigureServices( IServiceCollection services )
{
    services.AddMvc();
    services.AddKentico();

    // ...

    services.AddXperienceOpenGraphComponent();

    // replace ServiceDescriptor
    services.Replace(
        new ServiceDescriptor( typeof( IOpenGraphDataRetriever ), typeof( CustomOpenGraphDataRetriever ), ServiceLifetime.Transient )
    );
}

FAQ

  • Will this ViewComponent work if I'm not using Page Routing?

no.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BizStream.Kentico.Xperience.AspNetCore.Components.OpenGraph:

Package Downloads
BizStream.Kentico.Xperience.AspNetCore.Components

A collection of ASP.NET Core Mvc ViewComponents that integrate with Xperience CMS.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 2,608 10/4/2021
1.1.0-beta.4aa17f0 181 9/29/2021
1.0.2 1,686 9/13/2021
1.0.2-beta.ff8773b 209 9/13/2021
1.0.1 2,970 7/14/2021
1.0.1-beta.ec965f2 174 7/20/2021
1.0.1-beta.b1e536c 175 7/16/2021
1.0.1-beta.8c6c3a1 277 7/16/2021
1.0.1-beta.8bfe389 234 7/16/2021
1.0.1-beta.45e07f5 220 7/16/2021
1.0.1-beta.41625fb 196 7/19/2021
1.0.1-beta.181bf86 267 7/16/2021
1.0.1-alpha.440ac6a 184 9/13/2021
1.0.1-alpha.3a07ded 204 7/15/2021