Jekyll Ruby reference and Generators tutorial

Hi! I’m Mattia. Until now I always developed with Jekyll with its basic functionalities and the documentation on the Jekyll website has always been enough. Now I need to create a Generator plugin and I see from the examples on the Jekyll website that I have to use Ruby. Is there a documentation where I can find Jekyll ruby reference or some tutorial about Jekyll Ruby programming other than the example on the Jekyll website?
Thank you,
Mattia

I do not know Ruby so this won’t be the place for me to give you advice, but can you share what the generator does?

Did you look at the Generators section of the Jekyll docs? Also good to include links in your question to show what you have already looked at and are aware of

The examples there cover explanations of the generate method, reading in a data file, handling some parameters.

I have this page in my cheatsheets which won’t give new info but does give a much smaller script as an outline starting point


I’d say think of what you want to do (e.g. generate html files from API data or a file in _data or from a config file or whatever) and search for what you want to do.

You’ll find existing forum answers, tutorials and also existing plugins which do something similar to what you want and you can learn from those.

If you’re still stuck, then open a new topic or reuse this thread, showing what you have coded so far and what you want to do next but are stuck on the understanding or syntax of.

I fleshed out my generator section to cover some more use cases and I think it is more useful than the examples in the Jekyll docs.

Remember to search Jekyll forums here for similar questions around plugins and show links in your question to show that you’ve done your own research.

Here is one where someone got stuck making a generator because they picked the wrong class and I provided the right class and a code snippet to get them on their merry way to conquering the Jekyll site.

Hi! Thank you for your answers. These are very useful! Your website is a very good reference too! Thank you! Sorry for the missing links I checked. For my future posts I’ll remember. I’ll try from the points you suggested me and when I’ll manage to do something working I’ll share in the forum if it’s not already present.
Thank you again.

1 Like

Would you mind sharing what you generator does?

1 Like

I’d like to generate a document in a collection (can be event a post) to make rss subscribers updated that a new pdf file has been uploaded. This website is managed by a customer of mine directly from GitHub (GitHub pages) and he wants just drag and drop a pdf file in a folder. I’d like to generate a post that said: “Hey a PDF has been uploaded! Check it out!” and the jekyl-rss will generate this new RSS.
By the way, I thought that Generators could be the most useful tool for this task, but if you have another idea I’m open to suggestion :slight_smile:

I have an idea for you. Do you use Forestry.io (or some other headless CRM)? Basically, it allows you to create blog posts via a website. It creates the markdown file in Jekyll for you.

What this means is you can set up a template for a post that accepts a file attachment. Once the post is saved in Forestry, it adds the post to your Jekyll site on GitHub. GitHub Pages will re-build and the new post is up, as well as your PDF file and an update to the RSS feed.

Forestry is free for a single account, so maybe you set it up for your client, then give them the login information?

Here is a video that shows you how to set it up and what the client needs to do. It will take your client about 30 seconds to perform their steps. Once they press save, GitHub Pages, will auto re-build and the RSS feed is up to date.

FYI… no audio in this video…

Let me know what you think and if you have any questions.

1 Like

I’d second that. Forestry gives nice UI for uploading assets like images and maybe PDF support.

Oh I see.

Yes you could use the generator to add to the site.posts array to make new post at build time which contains a download link.

1 Like

Maybe you can sidestep the generator aspect altogether

Look at the Jekyll feed plugin and see if you can override the behavior of the plugin. Even better if you can make your own XML file based on that or based in this approach that also doesn’t need a plugin.

I’m assuming the standard feed only shows blog posts. (In my experience, doesn’t show other pages so I don’t bother to use a feed on my sites without posts)

So then add onto the logic of the file to add a link to the PDF.

You will have to make sure your feed is compliant with a feed standard in terms of adding metadata for showing it is an PDF, if that even is a thing at all that is allowed.

Instead of a link to a post, the link goes to the pdf.

Be sure to use a feed reading tool to test how users would see data they subscribe to, so you don’t garble things for them.

1 Like

Hi! Thank you!! Forestry is the right way!! I really love it! Thank you even for the video! With this solution I don’t even need to create a generator. I’ll let you know if my customer agree to use Forestry’s interface.

@MichaelCurrin I think I’ll try your solution since the xml the jekyll-feed plugin generates links in his own way: the title linked to the post for example. Maybe I need to generate a feed which link not to the post, but always at the same page… Having more control over the generation of the feed could make me more flexible. I’ll let you know.

In the meanwhile, thank you again

1 Like

Great! Glad to hear it will be useful!

1 Like