kontent-ai / delivery-sdk-net

Kontent.ai Delivery .NET SDK
https://www.nuget.org/packages/Kontent.Ai.Delivery
MIT License
32 stars 43 forks source link

Proposal: New way of rendering rich-text #259

Open petrsvihlik opened 3 years ago

petrsvihlik commented 3 years ago

Theme:

Goals:

All related issues: https://github.com/Kentico/kontent-delivery-sdk-net/labels/rich-text

Supported scenarios:

Current solution:

Proposed solution:

Detailed proposition:

Example code:

var articleResponse = await deliveryClient.GetItemAsync<Article>("on-roasts");
Article article = articleResponse.Item;
IRichTextContent richText = article.Body;
// Contains links, assets, strongly typed inline content items...already processed by `T Resolve(T model)`
// Ready to be passed to ASP.NET MVC Display Templates
IEnumerable<IRichTextBlock> blocks = richText.Blocks; 

HtmlResolver resolver = new HtmlResolver(new XYZLinkResolver(), new ABCAssetResolver()...); // Or build via DI
string flattenedHtml = resolver.ToString(blocks, articleResponse.LinkedItems);
jrkd commented 2 years ago

It looks like this new approach might resolve this as the IContentLinkUrlResolver moves from ModelProvider to HtmlResolver,

But currently, because the IContentLinkUrlResolver is instantiated via DI in the ModelProvider, which is in turn used by the DeliveryClient, Its currently impossible to have a IDeliveryClient instance injected within a custom IContentLinkUrlResolver implementation (it creates a circular dependency), eg;

    public class CustomContentLinkUrlResolver : IContentLinkUrlResolver
    {
        public CustomContentLinkUrlResolver(IDeliveryClient client)
        {
        }
    }

which in our case we want, (and I would think is a pretty general requirement?) to query Kontent's subpages hierarchy and build the url for a particular content item passed to the Url Resolver.

MiroKentico commented 2 years ago

Thanks for pointing this out, we will take this into consideration.