Blogging With JBake
01 May 2016
I have an existing Octopress blog which is probably near its useful days. Octopress which is Jekyll underneath the covers, is still one of the best static site generator. It has more community support and more written plugins. If I'm a Ruby guy, I will certainly stick with Octopress or Jekyll. But I'm not, being a Java developer. One of the biggest reason why I'm switching to jbake
is being able to run it on JVM. JBake is not as mature as Jekyll, it's Github inception was 17th of July 2012.
Prerequisites
-
JDK - the oven
-
git - the stupid content tracker
-
sdkman - to easily install Software Development Kits
$ curl -s "https://get.sdkman.io" | bash
-
lazybones - template generator
$ sdk install lazybones
-
gradle - for the optional github deployment script
$ sdk install gradle
Setting up your bakery
I followed CoffeaElectronica to initially setup my bakery.
$ lazybones create jbake-groovy blog
Creating project from template jbake-groovy (latest) in 'blog'
Define value for 'JBake Plugin Version' [0.2]:
Define value for 'JBake Version' [2.3.2]: 2.4.0
Define value for 'Gradle version' [2.3]: 2.9
GitHub project: [username/projectname.git]: drmanalo/dhon.github.io.git
Then I cloned one of knes1 repositories git clone https://github.com/knes1/tehartikli-jbake-template.git
since it has the Freemarker templates that I wanted for my blog. After cloning, I placed the cloned template into src/jbake
replacing all existing folders there. I also deleted the initial contents under content/blog/2013
folder which are initial posts on HTML, Markdown and AsciiDoc format to show you how to write your posts.
I changed the build.gradle
slightly to support Freemarker.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'me.champeau.gradle:jbake-gradle-plugin:0.2'
classpath 'org.jbake:jbake-core:2.3.1'
classpath 'org.pegdown:pegdown:1.4.2'
classpath 'org.asciidoctor:asciidoctorj:1.5.2'
classpath 'org.freemarker:freemarker:2.3.19'
}
}
apply plugin: 'me.champeau.jbake'
task publish(type: GradleBuild) {
buildFile = 'publish.gradle'
tasks = ['publishGhPages']
}
Header of every recipe
title=Disclaimer
date=2015-05-01
type=page
keywords=drmanalo,disclaimer
status=published
On the above snippet type could be either ``post`` or ``page``. The difference on how it will be baked is purely based on your moulder which happen to be the files inside ``templates`` folder.
### Baking your recipe
$ gradle jbake
:jbake
BUILD SUCCESSFUL
Total time: 5.542 secs
### Previewing your posts
$ groovy serve.groovy
Starting Jetty, press Ctrl+C to stop.
2016-05-07 15:17:10.455:INFO:oejs.Server:jetty-7.6.15.v20140411
2016-05-07 15:17:10.496:INFO:oejsh.ContextHandler:started o.e.j.s.ServletContextHandler{/,file:/home/drmanalo/workspace/blog/}
2016-05-07 15:17:10.520:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080
### Publishing to github
This requires your associated ``SSH key`` for the configured github username.
$ gradle publish
:publish
:dhon.github.io:publishGhPages
BUILD SUCCESSFUL
Total time: 14.107 secs