How to generate a static sites with rails?

Hi at the rails, that topic seems to come up sometimes.

I tried middleman with some good initial success. But the deeper I dig, it’s not rails.

I know, that rails is about dynamic websites. But sometimes, I need to spit out some static generated pages. Why I should change my well known tools?

I’m asking to build a static site generatoir, build on rails.

What I learned so far, you need to have a list of all the pages to generate.

It could be easy to generate that from the routes. but we need to generate each and every pages for all of the resources.

So what a generator does need to do, is to trickle down through all the routes, and grab all the data for every resource, and call the template upon that.

I know that this can get out of hands quite quickly. But let us assume, a directed graph of resources. That makes it a limited number of pages to generate.

In my current case, I back the data with a yaml file. I use the anchors and links think of it like an object database. but I only need it to go one level deep.

I now have tried middleman to good success. (but it got harder, the deeper I dig in that old code)

I’m looking forward for someone to join on into this project. ~eike

1 Like

I would build the dynamic site in Rails then have a crawler/scraper run separately (as a Git action?) and serve the scraped pages (NokoGiri @docs?) statically. Perhaps you could provide a sitemap for the scraper to follow.

I wanted to do that sometime ago but not anymore. fwiw I think jekyll is a good tool for making dry static sites, rsync the _site folder and done.

However, if you find a good way to do it with rails I would like to try it out.

https://sitepress.cc might be what you’re looking for.

2 Likes

I’ve done this before and written about it here. IIRC, it’s as barebones as you can get — just Rails and a scraper. It’s reliably deployed my site for a good couple of years now.

2 Likes

I’ve been considering this as well (for hosting websites built with Rails, whose content change very rarely). I made a selection of useful tools here: Spone's list / Rails as a static site generator · GitHub

And I finally found the best tool for the job: GitHub - benpickles/parklife: Render a Rack app (Rails/Sinatra/etc) to a static build so it can be served by Netlify, Now, GitHub Pages, S3, or any other web server.

PS: hi @boardfish nice to see you here :wink:

1 Like

An approach is to leverage actionpack-page_caching and let the site be generated on demand, or scrape.

When you deploy, mv + rm the directory with the cache (moving is atomic in Unix, rm -rf is not).

This is how Rails Contributors basically works. This is its configuration file for NGINX.

Parklife looks neat, particularly for warning on 404s and getting pages that aren’t otherwise linked to! :wave: