Access programmatically generated pages via site.pages?


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


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

    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 <<, site.source, 'custom', data)

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

          # Set generated filepath name

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

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

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.

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.

In my plugin, I simply added my page data to 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?