GithubHelp home page GithubHelp logo

storyblok's Introduction

Adliance.Storyblok

Adliance.Storyblok is a client to the Storyblok API written in C# that enables easy and strongly typed access to stories and components stored in the Storyblok headless CMS.

It also provides an ASP.NET Core middleware to directly render render stories into views based on their Storyblok slug.

Build Status NuGet Badge

storyblok's People

Contributors

saxx avatar pburndorfer avatar myquay avatar dakshalraijada avatar fgiuliani avatar lwlook avatar

Stargazers

Drew Heyworth avatar Adebayo Olumide avatar Simon Årstam avatar

Watchers

James Cloos avatar  avatar Toke Noer avatar  avatar

storyblok's Issues

Error code 422 when call by StoryblokStoryClient _storyClient.load()

Hi everyone,

The function LoadStories() in StoryblokStoryClient class aggregrates URL's parameters that are different with parameters which we are using to call Content Delivery APIs of StoryBlok.

For example:
StoryblokStoryClient fixed URL with a param "&cb={DateTime.UtcNow:yyyyMMddHHmmss}", while our URL doesn't contain this param. So in our project, if use _storyClient.Story().WithSlug("home").Load(), then result is return 422 code Error.

This is my URL as https://api.storyblok.com/v2/cdn/stories/home?cv=1680237492&token=1hfg5CmnrelP8fJT5llmWatt&version=published

Map tag_list to StoryBlokStory

There is no way to retreive the tag_list form the Client. Can we map the tag_list that is returned from the API to StoryBlokStory?

Trying to get started

I've followed the boilerplate instructions and get a 401 error when running. Also, I'd like to build in .net 8, do you foresee any issues if I download the code and just upgrad to .net 8? Any help would be greatly appreciated.

HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
Adliance.Storyblok.Clients.StoryblokStoryClient.LoadStoryFromStoryblok(CultureInfo culture, string slug, ResolveLinksType resolveLinks, bool resolveAssets, string resolveRelations)
Adliance.Storyblok.Clients.StoryblokStoryClient.LoadStory(CultureInfo culture, string slug, ResolveLinksType resolveLinks, bool resolveAssets, string resolveRelations)
Adliance.Storyblok.StoryblokStoryQuery.Load()
Adliance.Storyblok.Middleware.StoryblokMiddleware.Invoke(HttpContext context, StoryblokStoryClient storyblokClient, IOptions options, ILogger logger)
Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

Considerations behind .net 7 update?

Hi,
We needed to make a PR/extension to include parent_id on the Story object, but in the process we can see that the package has been updated to .net 7.0 and right now we haven't moved to .net 7.

While we haven't decided our long term plan for using this SDK (as we do not use the middleware, prefering to use a dynamic route resolver etc.), I just want highlight it might be problematic for some users to update to .net 7 as it's not LTS. Depending on the organization people might not be able to use non LTS versions (we weren't allowed at my previous job) and for now it doesn't seem like it's actually required, so I'd just highlight this consideration for the SDK.

The main reason to update to .net 7, as far as I can tell, would be to discard the homegrown polymorphic serialization and base it on the new support in .net 7 - but again, that will break people who need to stay on .net 6.

(Just my 2 cent - so not really an action/bug/feature....)

Integration with existing localised application

I ran into an issue with how this package interacts with a solution that's already localised.

During registration of the Storyblok middleware this section was interfering with our localisation configuration causing existing sections of the application to not behave as intended.

I've made a few changes to the library so that it is able to integrate with a solution that's already been localised - here's the commit: myquay@2ab0f64

Let me know if this is something you think could help other users of your library and I'm happy to submit a PR otherwise feel free to close the issue.

The changes I made where around the three touch points below:

  1. In ApplicationBuilderExtensions.cs remove the code that alters the localisation configuration. Add a custom RequestCultureProvider to support the Storyblok style of localization by prefixing the slug so it works nicely with the editor. Placed it at high priority so it overrides other settings but does not modify existing settings so outside of Storyblok the application behaves as before.
 requestLocalizationOptions.Value.RequestCultureProviders.Insert(0, new CustomRequestCultureProvider(async context =>
 {
     // special handling of Storyblok preview URLs that contain the language, like ~/de/home vs. ~/home
     // if we have such a URL, we also change the current culture accordingly
     var slug = context.Request.Path.ToString().Trim('/');
     var supportedCultures = requestLocalizationOptions?.Value?.SupportedCultures?.Select(s => s.Name).ToArray() ?? Array.Empty<string>();

     foreach (var supportedCulture in supportedCultures)
     {
         if (slug.StartsWith($"{supportedCulture}/", StringComparison.OrdinalIgnoreCase) || slug.Equals(supportedCulture, StringComparison.OrdinalIgnoreCase))
             return await Task.FromResult(new ProviderCultureResult(supportedCulture));
     }

     return await Task.FromResult<ProviderCultureResult?>(null);
 }));
  1. Updated the settings validation so that Storybloks configured supported cultures must be a subset of the cultures configured in the application so that we are not adding cultures unsupported in the wider application to the Storyblok integration.
var configuredCultures = requestLocalizationOptions?.SupportedCultures?.Select(s => s.Name) ?? new string[] { };
if(Settings.SupportedCultures.Any(x => !configuredCultures.Any(y => y.Equals(x, StringComparison.OrdinalIgnoreCase))))
{
    throw new Exception("All supported cultures in Storyblok must be configured in ASP.NET.");
}
  1. Update the Storyblok middleware to not interfere with the Culture Cookie, or the CurrentUI Culture

Support for RichText Resolver

As of now there is no implementation for a RichText resolver, it would be a nice feature to add.

What I think is most important is:

  • Paragraphs
  • Headlines (all levels)
  • Bold, italic, strike, underscore
  • Links
  • Ordered lists, unordered lists
  • Pictures
  • Quotes

What is think is less important:

  • Inline code
  • Code block
  • Horizontal rule
  • Rendering of blocks (although a nice feature)

The JavaScript client got a similar feature:
https://github.com/storyblok/storyblok-js-client/blob/main/src/richTextResolver.ts

Support for Management APIs

Hello,
Im currently exploring the capabilities of the API for Asset management. I would like to know whether the library supports programmatically creating assets using Management APIs, specifically in JavaScript.
Thank you!

[Request, Issue] Update SDK to add Blazor support

Hi,

I'm currently trying to implement the C# SDK. However, because the SDK is not built to be used with Blazor, this is currently not possible.
For instance, when you follow the tutorial on the Storyblok website, you need to add a Teaser class. With Blazor, this works like this:

[StoryblokComponent("teaser")]
public partial class Teaser : StoryblokComponent
{
    [JsonPropertyName("headline")]
    public string Headline { get; set; }
}

The problem this throws is the fact that every component in Blazor needs to have some overrides (which can found in ComponentBase). Since C# doesn't allow for multiple inheritance, it's not possible to use the SDK with Blazor. Are you planning on adding Blazor support anytime soon?

Thanks!

Rendering single option story within page

Hi,

I've been trying to figure out how to render a single option story in a page. So far; I've been unsuccessful and I hope that someone can point me in the right direction. At this point, I'm even wondering if this SDK supports this?

My steps so far:

  1. In Storyblok, add single option to page, make sure it's filled
  2. In Program.cs, add options.ResolveRelations = "navigation"; when calling the Middleware, so that it resolves the relations properly
  3. In the pagemodel (HomeTemplate.cs in this case), instead of adding a component, add a StoryblokStory so that the model looks like this:
[StoryblokComponent("homepage_template", "HomepageTemplate")]
public class HomepageTemplate : StoryblokComponent
{
    [JsonPropertyName("navigation")]
    public StoryblokStory Navigation { get; set; }

    [JsonPropertyName("fixed")]
    public StoryblokComponent[] Fixed { get; set; }

    [JsonPropertyName("body")]
    public StoryblokComponent[] Body { get; set; }

}
  1. Create a Navigation.cs and Navigation.cshtml file in the correct place, with Navigation.cs looking like this:
[StoryblokComponent("navigation")]
public class Navigation : StoryblokComponent
{
    [JsonPropertyName("items")]
    public StoryblokComponent[] Items { get; set; }
}

Now, the problems begin. In my HomeTemplate.cshtml, I try to render the view correctly. Problem is: I have absolutely no idea how. When I try to do it like this: @Html.DisplayFor(x => x.Content.Navigation.Content), nothing happens. I'm guessing that's because DisplayFor expects a array, while .Navigation.Content only is a single StoryblokComponent.

Is there someone that can point me in the right direction? I've been pulling my hairs out of my head for days now, and I just can't seem to fix this.

[Question] Partial Views requiring StoryBlokStory when not a component

Hi,

I'm trying to implement this SDK using the tutorial on the website. So far, so good.

I create my Partials like this:

_NavMenu.cshtml

@model NavMenuModel

<div class="container mx-auto">
</div>

And call them like this

_Layout.cshtml:

<html>
<body class="min-h-inherit w-inherit text-black">
    <header class="w-full pb-3">
        <partial name="_NavMenu"/>
    </header>

    <main class="lg:mt-6 xs:-mt-3.5" style="min-height:500px"> <!-- @@TODO REMOVE THIS -->
        <section>
            @RenderBody()
        </section>
    </main>

    <footer>
        <partial name="_Footer"/>
    </footer>

    @Html.StoryblokEditorScript()

    @await RenderSectionAsync("Scripts", required: false)
</body>
</html>

I have a Page.cshtml like this:

@model Adliance.Storyblok.StoryblokStory<Rig.Channels.Website.Components.Page>

@Html.DisplayFor(x => Model.Content.Body)

This greets me with the following error on running the application:

System.InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Adliance.Storyblok.StoryblokStory`1[Rig.Channels.Website.Components.Page]', but this ViewDataDictionary instance requires a model item of type 'Rig.Channels.Website.Pages.Shared.NavMenuModel'.

I don't quite understand how and why this isn't working. Is there something that the SDK is doing with the pages you create so that the rendering runs in a different way? Is there any way around this? Thanks!

Library use with Razor Pages

It appears that the library is for use MVC. Is anyone aware of getting it to work with Razor Views, or have any advice for forking the library for use with Razor Views?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.