I wrote a generator plugin for my Jekyll site. It makes an API request to gather some necessary data to help with the build.
I'm using --livereload
when running jekyll serve
to develop locally. The generator seems to be called every time I save a file and regenerate the site. This uses up a lot of API requests made in my generator.
I only need to make that API request once. Is there a way for the generator to know how many times it gets called so that I can run it once and not on subsequent generations?
Here's the general impression of my generator plugin:
class CloudinaryContent < Jekyll::Generator
safe true
def fetch(uri, env)
# Make requests
end
# Fetch data before generating site
def generate(site)
require 'uri'
require 'net/https'
require 'json'
# fetch data and store in global
# variable for other plugins to use
$site_data = fetch()
end
end
This is similar to Avoid repeated calls to an API in Jekyll Ruby plugin except I'm making API requests in a generator, and I only want to call the generator the first time jekyll serve
is called, and not during subsequent reloads when files change during local development.