My website EmmanuelRosa.com is written using the Grain framework. While writing articles for my site I discovered that the process of writing one article often leads to the need to write other related articles. Ideally, these articles would be linked together, making it easy to navigate from one to the other. This is especially important in articles which are part of a series. This got me thinking about ways I can code something now and have it take effect in the future. And so it was decided: I wanted a way to create a link into the future.
The future article
The idea was simple. Upon determining that I would likely create a related article in the future, I'd add a special kind of link pointing to it. When generating the website, Grain would check if the linked-to article exists. If so, it would render some content. Otherwise it would render alternative content.
This special type of link is implemented with a taglib I named
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
id taglib expects an identifier and an optional
Closure. When invoked, it searches for a page with the specified id in the page's YAML header. If a matching page is not found, the taglib returns
null. Otherwise it will either return the URL to the page, or call the provided
Closure with the URL.
An example where I've used this taglib is in my recent article The State of Things. In it I have this closing paragraph:
1 2 3 4
Note that the actual content is all on one line, unlike the rendering shown above.
The last sentence changes depending on whether an article with the
id state-machine-builder exists. Lets take a closer look at just the Groovy code:
When the state machine builder page is found the
Closure is called, which then returns Markdown content with a link to the page. Otherwise it returns a simple: Tune in next week. In practice this means that upon publishing the follow-up article, the original article gets rendered with a link to the new article. I don't have to remember to go back and add the link!
Don't forget to publish
It's common for me to draft multiple articles simultaneously. Not literally simultaneously; you know what I mean. Obviously this makes it quite possible to accidentally forget to publish an article. Grain blog posts contain a published YAML attribute. Usually this attribute is treated as a Boolean; the article is published when set to true. And so it was, until I got my hands on it:
1 2 3 4 5 6 7 8 9 10 11 12 13
I modified the
ResourceMapper to accept a
String-formatted date so that articles are published once the publication date has arrived.
1 2 3 4 5 6 7 8 9 10
As I began publishing articles on my newsletter, I learned that among other rendering anomalies, my Graphviz and PlantUML diagrams do not render properly. I'm using a taglib to process the diagram's source code and render it as SVG content. Apparently email clients don't know what to do with SVG images. So I added a temporary message to the page new subscribers see:
1 2 3 4 5 6 7 8
I'm assuming that I'll have the issues resolved within a few months so I set it and forgot it.
That's all folks
When planning out my site, I knew from the start that I wanted something programmable. I wanted to write content as if I were coding. And I'm glad to say Grain has delivered. I look forward to coding more and remembering less.