Giter Site home page Giter Site logo

alanta / kontent.statiq Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 3.0 180 KB

Module to retrieve content from Kentico Kontent for building static websites with Statiq

License: MIT License

C# 100.00%
static-site-generator kontent static-site c-sharp dotnet-core kentico-kontent

kontent.statiq's Introduction

 __  __                  _                          __     __    _            
|  \/  | __ _ _ __ _ __ (_)_  __ __   ____ _ _ __   \ \   / /_ _| | ___ _ __  
| |\/| |/ _` | '__| '_ \| \ \/ / \ \ / / _` | '_ \   \ \ / / _` | |/ _ \ '_ \ 
| |  | | (_| | |  | | | | |>  <   \ V / (_| | | | |   \ V / (_| | |  __/ | | |
|_|  |_|\__,_|_|  |_| |_|_/_/\_\   \_/ \__,_|_| |_|    \_/ \__,_|_|\___|_| |_|

šŸ”­ Iā€™m currently working on

  • Bolt Comments : Easy self-hosted comments for your Jamstack site. An Azure Static WebApp

āœØ Recent projects

šŸŒ± Iā€™m currently learning:

  • Public Key Infrastructure (PKI)
  • Running TCP services on Azure Container Apps

āš” Fun fact:

  • Alanta doesn't really mean anything. It's just a name my mom came up with when I wanted to start my own company (once upon a time, a long time ago...)

šŸ“« How to reach me:

kontent.statiq's People

Contributors

alanta avatar petrsvihlik avatar simply007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

kontent.statiq's Issues

Support for the taxonomy end-point

See issue #20 - the Delivery API has a taxonomy groups end-point that really should be available in Kontent.Statiq

I think this should be a separate module.

To Do

[ ] define a good use case
[ ] example code
[ ] investigate support for taxonomies in Statiq; how can we leverage as much of Statiq as possible?

Review Notes

As promised, I went through the code, and here are my findings:

Kontent.Statiq

Kentico.Kontent.Delivery

  • It seems to me that Kentico.Kontent.Delivery.Urls.QueryParameters should be part of the .Abstractions library
    • It's a common logic that creates an unnecessary dependence on the Delivery SDK and even worse, on its dependencies (such as AngleSharp). Would you agree?

KontentDownloadImages is not setting the destination for image files.

Describe the bug
KontentDownloadImages is downloading images but the files have no destination.

To Reproduce
Reproducable in the Planty theme

Expected behavior
The KontentDownloadImages modules should download images so they can be stored on disk.

Actual behavior
Nothing is stored any more,

Environment(please complete the following information):

  • OS: Any
  • .NET Core version: 3.1.x
  • Package version: 1.0.0-beta10

Additional context
This used to work just fine.

Timeout while loading many images using KontentDownloadImage module

Describe the bug
When loading many images, a timeout occurs in the KontentDownloadImage module

To Reproduce
Setup an image download pipeline for many pages with images in various sizes.

Expected behavior
All images should download, without error.

Actual behavior
The pipeline failes, reporting a timeout.

Environment(please complete the following information):

  • OS: Windows
  • .NET version : 6
  • Package version: 2.0.0-beta0015

Additional context
Seeing this happen when downloading over 300 images. Traced it back to Statiqs ReadWeb module, which spawns as many threads as it can to download the images.

KontentDownloadImages support for `Config`

Is your feature request related to a problem?
I'd like to customize paths of downloaded images based on contextual data.

Describe the solution you'd like
Similar to other modules that come OOTB with Statiq, I think the KontentImageProcessor should accept Config<string> localPath in the constructor.

Describe alternatives you've considered
public KontentImageProcessor WithLocalPath(string path)
-> this allows some level of customization, however, it doesn't allow me to load things from the IDocument and IExecutionContext.

Cannot use Statiq.Feeds with Kontent

Describe the bug
Statiq.Feeds depends on AngleSharp >= 0.9.10 but that version is incompatible with the current version 0.14.0.
The Delivery SDK requires AngleSharep >= 0.14.0.

To Reproduce
Add a pipeline that uses the GenerateFeeds module to a project using Kontent.Statiq.

Expected behavior
The feed generates without issues.

Actual behavior
An exception occurs:

Error while executing module GenerateFeeds in Feeds/Process: Could not load type 'AngleSharp.Parser.Html.HtmlParser' from assembly 'AngleSharp, Version=0.14.0.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea'.

Environment(please complete the following information):

  • OS: Windows
  • .NET Core version: 3.1
  • Package version or git commit hash: 3495dfb

Additional context
This popped up in pre-release testing.

Incompatibility with Statiq.Web beta 18

Describe the bug
The latest Statiq.Web depends on Statiq.Common v32 whereas Kontent.Statiq depends on v31. There are obviously some breaking changes which cause the combination of the latest versions not to work.

To Reproduce
Add <PackageReference Include="Statiq.Web" Version="1.0.0-beta.18" /> to your project and you'll start getting errors.

I tried to upgrade this site for instance: https://github.com/Kentico/statiq-starter-kontent-lumen

Expected behavior

  • build passes

Actual behavior

[CRIT] Method not found: 'System.Threading.Tasks.Task1<Statiq.Common.IDocument> Statiq.Common.IExecutionContextCreateDocumentFromStringExtensions.CreateDocumentAsync(Statiq.Common.IExecutionContext, System.Collections.Generic.IEnumerable1<System.Collections.Generic.KeyValuePair`2<System.String,System.Object>>, System.String, System.String)'.

Environment(please complete the following information):

  • OS: Win
  • .NET 5
  • beta 9

Solution
Upgrade the following references

<PackageReference Include="Statiq.Common" Version="1.0.0-beta.31" />
<PackageReference Include="Statiq.Core" Version="1.0.0-beta.31" />

to beta 32.

Support for other delivery endpoints

Is there a reason why there is support only for the /items endpoint? Was it a deliberate choice or was it just because of the lack of time and it's still the plan to support them at some point?

I can see that for larger projects it could be handy to implement the /items-feed as well. The same goes for the taxonomies... (not to mention other endpoints)

.NET 6 support

The Kontent Delivery SDK will add .NET 6 support so it's time to add support for .NET 6 as requested by @Simply007.
For now multi-targeting .NET Core 3.1 and .NET 6. Statiq is at .NET Core 3.1 so it makes sense to stick to that as the minumum requirement.

Allow to create IDocuments from Linked items

Is your feature request related to a problem? Please describe.
If you want to load Linked Items of the particular item, it is required to transform them into IDocument to be able to pass them through the pipeline and i.e. use them to create a view model for the Razor view. It would be great to have this feature out of the box.

I will describe the situation in the example:
You have a "Root" item that is the root of your website, this contains the Linked Items element (Subpages) model menu structure. Every item (Page type) then contains another Subpages element to allow having a multilevel navigation menu. Plus the Page model contains "Content" Linked items element containing typically one item holding the channel-agnostic content.
This is basically a Webspotlight setup.

Example model structure:

public partial class Root
{
        public IEnumerable<object> Subpages { get; set; } // Strongly types items of type i.e. Page
}

public partial class Page
{
        public IEnumerable<object> Subpages { get; set; } // Strongly types items of type i.e. Page
        public IEnumerable<object> Content { get; set; } // Contains only one "Content" item e.g. LandingPage
}

public partial class LandingPage
{
        public string Headline { get; set; }
        public IRichTextContent MainText { get; set; }
        public IRichTextContent Summary { get; set; }
}

Now if you want to load the data from Root and render data from the linked items in razor views, you would do something like:

InputModules = new ModuleList {
                new Kontent<Root>(client)
                    .WithQuery(
                        new EqualsFilter("system.codename", "root"),
                        new LimitParameter(1),
                        new DepthParameter(3)
                    ),
                new ReplaceDocuments(
                    new ExecuteConfig(
                        Config.FromDocument((doc, context) => 
                             // *********** THIS PART COULD BE PART OF THE  Kontent.Statiq MODULE ************ 
                            doc.AsKontent<Root>().Subpages.ToList().Select(subpage =>
                            {
                                var pageContent = (subpage as Page)?.Content.FirstOrDefault();
                                if(pageContent == null)
                                {
                                        throw new InvalidDataException("Root page (codename: root, type: root) does not contain any pages, or any page does not contain exactly content block!");
                                }

                                return context.CreateDocument(
                                    CreateKontentDocument(context, pageContent)); 
                            })
                        )
                    )
                )
            };

// ...

ProcessModules = new ModuleList {
                new MergeContent(new ReadFiles("LandingPage.cshtml")),
                new RenderRazor()
                    .WithModel(Config.FromDocument((document, context) =>
                    {
                        var typeCodename = document
                            .FilterMetadata(KontentKeys.System.Type)
                            .Values
                            ?.FirstOrDefault()
                            ?.ToString();
                        Type type = typeProvider.GetType(typeCodename);

                        var landingPageType = typeof(LandingPage);
                        if(landingPageType == type)
                        {
                                return document.AsKontent<LandingPage>();
                        }
                        else
                        {
                                throw new InvalidDataException("Unsuported content type of the Page's Content element");
                        }
                    })),
    // ****
    };


// basically copy&paste of the https://github.com/alanta/Kontent.Statiq/blob/main/Kontent.Statiq/Kontent.cs#L49
private IDocument CreateKontentDocument(IExecutionContext context, object item)
        {
            var props = item.GetType().GetProperties(BindingFlags.Instance | BindingFlags.FlattenHierarchy |
                                                            BindingFlags.GetProperty | BindingFlags.Public);
            var metadata = new List<KeyValuePair<string, object>>
            {
                new KeyValuePair<string, object>(TypedContentExtensions.KontentItemKey, item),
            };

            if (props.FirstOrDefault(prop => typeof(IContentItemSystemAttributes).IsAssignableFrom(prop.PropertyType))
                ?.GetValue(item) is IContentItemSystemAttributes systemProp)
            {
                metadata.AddRange(new[]
                {
                    new KeyValuePair<string, object>(KontentKeys.System.Name, systemProp.Name),
                    new KeyValuePair<string, object>(KontentKeys.System.CodeName, systemProp.Codename),
                    new KeyValuePair<string, object>(KontentKeys.System.Language, systemProp.Language),
                    new KeyValuePair<string, object>(KontentKeys.System.Id, systemProp.Id),
                    new KeyValuePair<string, object>(KontentKeys.System.Type, systemProp.Type),
                    new KeyValuePair<string, object>(KontentKeys.System.LastModified, systemProp.LastModified)
                });
            }

            return context.CreateDocument(metadata, null, "text/html");
        }

In the CreateKontentDocument I have only removed the part of GetContent delegate for simplicity and using item.GetType().GetProperties instead of typeof<TContentModel>.GetProperties

Describe the solution you'd like

It would be great to have the functionality to transfer Linked Items to IEnumerable<IDocument> right in the SDK.

doc.LinkedItemsAsKontentDocuments<Root>(root => root.Subpages);

Describe alternatives you've considered
I was thinking about a separate module, but I think it is overengineering.

Additional context
I have the solution in the https://github.com/Kentico/jamstackon.net/blob/linked-items-idocument-transformation/Pipelines/RootPipeline.cs

  • I have invited you to the project @alanta

Workflows are referencing vulnerable actions

Hello, there!

As part of the university research we are currently doing regarding the security of Github Actions, we noticed that one or many of the workflows that are part of this repository are referencing vulnerable versions of the third-party actions. As part of a disclosure process, we decided to open issues to notify GitHub Community.

Please note that there are could be some false positives in our methodology, thus not all of the open issues could be valid. If that is the case, please let us know, so that we can improve on our approach. You can contact me directly using an email: ikoishy [at] ncsu.edu

Thanks in advance

  1. The workflow ci.yml is referencing action gittools/actions/gitversion/setup using references v0.9.6. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.
  2. The workflow ci.yml is referencing action gittools/actions/gitversion/execute using references v0.9.6. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.
  3. The workflow release.yml is referencing action gittools/actions/gitversion/setup using references v0.9.6. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.
  4. The workflow release.yml is referencing action gittools/actions/gitversion/execute using references v0.9.6. However this reference is missing the commit 90150b4 which may contain fix to the vulnerability.

The vulnerability fix that is missing by actions' versions could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider updating the reference to the action.

If you end up updating the reference, please let us know. We need the stats for the paper :-)

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.