Static website generation in Groovy

#grain ul { list-style: square; list-style-position:inside; text-indent: 20px;}
#grain code { font-family: Lucidatypewriter, monospace}

A static site generator is software that translates content from a text format into HTML and creates consistant look and feel across all the pages. These HTML pages can be copied to any basic webserver. Usually the base format is Markdown or AsciiDoc which is then converted into an HTML snippet, and then put into a larger HTML page. After generation, those files are copied to a basic webserver that serves the plain HTML.

Static site generators are popular with the technical crowd. It takes the complexity off of the server (no database! no caching!) and puts it on our local machine. Most have some sort of command-line system that runs rsync to copy the updated files to the web server. Having just plain HTML makes the site more secure than traditional blogging platforms. It’s hard to do a Bobby Tables if there is no database, and you don’t have to worry about the latest PHP security updates — it’s all just plain o’ HTML, CSS, and JavaScript.

Going With The Grain

There are lots of different static site generators, usually multiple ones for each programming language. Groovy’s relatively new entry in to this world is Grain. The developers of Grain decided not to reinvent the wheel, but instead implement other technolgies in their software. For example, Grain will automatically generate CSS from SASS or SCSS sources. But instead of implementing their own SASS parser in Groovy, it attempts to use Ruby on your system and, failing that, it installs JRuby into it’s sandbox and runs the SASS gem from there. This is automatic — no user configuration is necessary for this to occur. Of course you can set a default if you want.

Other great things about Grain:

Best yet — it’s distributed under the Apache license.

To get started with Grain, you can grab one of the pre-built themes as a starting point. Then you can read the docs yourself. But after the initial setup, my workflow for a blog post is usually:

  • grain create-post <post name> — creates a Markdown file under content/blog
  • grain preview — starts the preview server
  • edit the the file and write away!
  • grain generate — generates the HTML files
  • grain deploy — run rsync on my generate files to the server

About the Author

Object Partners profile.

One thought on “Static website generation in Groovy

  1. Anders D. Johnson says:

    Mike, thanks for this nice article introducing us to SSGs and especially Grain. FYI, I noticed a typo in the page – it says “genration” rather than “generation” – as of 2015/11/19 11:45pm.

Leave a Reply

Your email address will not be published.

Related Blog Posts
A security model for developers
Software security is more important than ever, but developing secure applications is more confusing than ever. TLS, mTLS, RBAC, SAML, OAUTH, OWASP, GDPR, SASL, RSA, JWT, cookie, attack vector, DDoS, firewall, VPN, security groups, exploit, […]
Building Better Data Visualization Experiences: Part 1 of 2
Through direct experience with data scientists, business analysts, lab technicians, as well as other UX professionals, I have found that we need a better understanding of the people who will be using our data visualization products in order to build them. Creating a product utilizing data with the goal of providing insight is fundamentally different from a typical user-centric web experience, although traditional UX process methods can help.
Kafka Schema Evolution With Java Spring Boot and Protobuf
In this blog I will be demonstrating Kafka schema evolution with Java, Spring Boot and Protobuf.  This app is for tutorial purposes, so there will be instances where a refactor could happen. I tried to […]
Redis Bitmaps: Storing state in small places
Redis is a popular open source in-memory data store that supports all kinds of abstract data structures. In this post and in an accompanying example Java project, I am going to explore two great use […]