Jekyll Strapi v4 Plugin | Ruby Help

For context, I am integrating Strapi v4 as a headless cms / api with Jekyll 4.2.2 as a SSG.

I have got the plugin to work, but the permalinks doesn’t work for me. I am very new to Ruby programming.

Here is the code that needs updated: jekyll-strapi/site.rb at master · strapi/jekyll-strapi · GitHub

I think the :category, :title, etc… must be added to placeholders to work, but I am unsure what document is defined as because when I put :id as my permalink for Strapi, it doesn’t generate the id of the post like it should.

Ultimately, I want pretty permalink styles like this: /blog/:categories/:year/:month/:day/:title/, but first I must have :id working.

      url = Jekyll::URL.new(
        :template => @config['strapi']['collections'][collection]['permalink'],
        :placeholders => {
          :id => document.id.to_s,
          :uid => document.uid,
          :slug => document.slug,
          :type => document.type
        }
      )

This is my Strapi Jekyll config in _config.yml

# Strapi dashboard integration
strapi:
    # Your API endpoint (optional, default to http://localhost:1337)
    endpoint: https://api.example.com/api
    # Collections, key is used to access in the strapi.collections
    # template variable
    collections:
        # Example for a "posts" collection
        posts:
            # Collection name (optional). Used to construct the url requested. Example: type `foo` would generate the following url `http://localhost:1337/foo`.
            type: posts
            # Permalink used to generate the output files (eg. /posts/:id).
            permalink: :id/
            layout: post.html
            output: true
        authors:
            type: authors

p.s. Strapi team in v4 does NOT maintain this repository anymore at this point in spacetime. I have spoke with them and they don’t program with Ruby.

If you are willing, maintaining this plugin would allow a larger audience to make use of Jekyll as part of the lifecycle of their workspace.

It could also be here or both locations may need updated. In Strapi v4 the schema changed slightly from v3.

The collections.rb location with :id and others. jekyll-strapi/collection.rb at master · strapi/jekyll-strapi · GitHub

        # Add necessary properties
        result.each do |document|
          document.type = collection_name
          document.collection = collection_name
          document.id ||= document._id
          document.url = @site.strapi_link_resolver(collection_name, document)
        end

Also, if it helps, here is an example of Jekyll setting up the attributes.

I feel I am close to the solution, but am unable to create the solution because I am new to Ruby programming. I still don’t know what the line: document.id does. I understand it is fetching the id from a document, but the naming conventions have to match.

My public JSON api data structure for 1 post is as follows:

  • data:
    • 0:
      • id:
        • attributes:
          • title: title goes here
          • etc…

Okay, it has been updated and now works, but still needs more testing and debugging.

You can find the updates and code here if you want to use Strapi with Jekyll