Access programmatically generated pages via site.pages?

Preface

I’m working on a small plugin that fetches JSON data from an API, then directly creates pages for each entry

Issue

This all builds perfectly but my issue:

  • On the generated page, I can access any page variables perfectly - {{ page.foobar }}
  • On other pages, I cannot loop through the custom pages to create a list - {% for page in site.pages %}

Looking at the generator section of code, this should work but I don’t know if I am missing something.

module Jekyll
    module CUSTOM_REST_API 
        def get_data
            # This function returns an array of hashes, containing my API data
            data
        end
    end

    class CustomGenerator < Generator
        include CUSTOM_REST_API

        def generate(site)
            content = get_data
            content.each do | data |
                # SEE HERE - Add each custom page into the site.pages array to be built
                site.pages << CustomPage.new(site, site.source, 'custom', data)
            end
        end
    end

    class CustomPage < Page
        def initialize(site, base, dir, datum)
          @site = site
          @base = base
          @dir  = dir
          @name = datum["slug"] + "/index.html"

          # Set generated filepath name
          self.process(@name)

          # Use custom page layout / template
          self.read_yaml(File.join(base, '_layouts'), 'custom.html')

          # Add custom page data to each page
          self.data['title'] = datum["name"]
          self.data['category'] = "custom"
          self.data['foobar'] = datum["foobar"]
        end
      end
end

I’m assuming the generate function runs after an inventory is taken?

I believe this is the class that registers everything in site.pages, however I don’t know if this should belong here.

Recap:
I created pages from an external API using a custom plugin.
The plugin itself uses a custom generator to transform and build pages based on data.

On the data pages, I could access page data {page.custom_property}
Outside of the data pages, I could not access this data from site.pages
This is because the standard site.pages is already set by the time this generator runs.

Solution:
In my plugin, I simply added my page data to site.data instead, since it is accessible at anytime.

hello Recap, could you write down the final part of your plugin that generated page from some data?