JBake Workshop
Mario Garcia
Me
● Mario Garcia
● Working at Kaleidos.net
● Mostly Backend Developer (Java, Groovy)
● Some Frontend lately (React, Vue, CSS still not my thing)
Schedule
● What is JBake and use cases
● Installation
● Basic commands
● Blog
○ Create content
○ Templates
○ Custom content
○ Asciidoctor extensions
○ Push it to Github
Schedule
● Break (15 min)
● Project OSS
○ Some code in Gradle project
○ Configure bake
○ Include javadoc
○ Include asciidoctor doc
What is JBake
“JBake is a Java based, open source, static site/blog
generator for developers & designers”
Some features
● Self contained
● Integrated with other build tools (Gradle, Maven, SBT…)
● Content formats (asciidoctor, markdown, html)
● Multiple template support
● Draft support
● ….
Installation
Who hasn’t installed JBaked yet ?
Installation
Who hasn’t installed JBaked yet ?
● Prerequisites
○ JDK 8
● Three scenarios
○ Download BINARY directly
○ Install via SDKMAN command line (sdkman.io)
○ Integrate with your favourite BUILDING TOOL
Installation
SDKMAN
● Install sdkman (https://sdkman.io/install)
● Then “sdk install jbake”
Download binary
● Go to https://jbake.org/download.html
● Click on the latest distribution
● Decompress the zip wherever you want
● Make sure the jbake command is available in your console path
○ If you’re in linux e.g. modify .bashrc to add jbake command to the $PATH
Integrate with your build tool
We’ll see an example in the second part of this workshop
with Gradle
Use your favourite IDE
● Use any IDE with syntax highlight for
○ Asciidoctor
○ Markdown
○ HTML
○ Groovy
Get used with the basics
Basic commands
● We’re still playing so create a temporary folder
○ Check JBake help
■ jbake --help
○ Create folder nameofproject
■ jbake -i <nameofproject>
○ Browse the structure with your favourite editor
Basic commands
● Bake content to get html
○ Get into the <nameoftheproject> folder then execute
■ jbake -b
○ That will produce the final output of the blog, to browse it as if it were published online, do:
■ jbake -s
Create a new blog
Create greachblog
● Create the new project using Groovy MTE as template engine
○ jbake -i -t groovy-mte greachblog
● Lets comment on the structure and templates a little bit
Structure
● Directories
○ assets: css, js, images…
○ content: asciidoctor, markdown or html files
○ templates: Templates to interpret content files and produce the final ouput result
● jbake.properties
○ JBake configuration
About Groovy templates
About Groovy templates
● No need for enclosing tag. Braces mark the scope
About Groovy templates
● Plain strings can be inserted using yield or yieldUnscaped
Lets create a new entry
Open the project in your favourite editor
● Mines are (the ones I can help you with)
○ Emacs
○ IntelliJ
● But any editor should work.
● Look for plugins/extensions that could help you rendering/highlighting Markdown or Asciidoctor
syntax
Asciidoctor
● “A fast text processor & publishing toolchain for converting AsciiDoc to HTML5, DocBook &
more”.
○ Asciidoctor: https://asciidoctor.org/
○ Syntax Reference: https://asciidoctor.org/docs/asciidoc-syntax-quick-reference
Create an entry for today
● Create an asciidoctor file
○ greachblog/content/2019/03/28/greach_jbake_workshop.adoc
● Copy the following content:
https://asciidoctor.org/docs/asciidoc-syntax-quick-reference
Then bake it and serve it locally
● Execute with -s (it does bake and serve altogether)
○ jbake -s
Modifying templates
I don’t see my name in the entry
● We would like all blog entries to show the name of the author
● What do we need ?
○ Know about the JBAKE DATA MODEL
○ Modify the template to add the property author
○ Bake it again
JBake Data Model
● Global variables: These data variables are available to all templates regardless of the type.
● Page / Post / Custom: Variables for predefined templates as well as any custom templates you
created yourself
● Index: The index template has extra data variables available to it related to paging
● Tags: Data related to published tagged documents
https://jbake.org/docs/2.6.4/#data_model
Add the author
● Task 1
○ Go to post-brick.tpl and add the author somewhere
○ Check JBake post related variables https://jbake.org/docs/2.6.4/#data_model
● Task 2
○ I would like to write code in its own source file and then show it partially in the blog entry. I also want to be
able to download the sample code
■ You can add a :metaproperty: in the asciidoc document header called attached with the name of the
script
■ Add the script at the same place as the asciidoc document
■ Add an href in the header to “download” the attached document getting the name from the post
headers
Attach code to entry
Custom content
Pages, Posts, Tags… Videos ?
● Create a new template named videos.tpl
● The new content of type video should set it in the content file header :type:
● We will pass the youtube video id to the template via content header :video:
● If you want to add a new type of content you should associate the new type of templates in
jbake.properties
○ template.<newtype>.tpl=<nameofthetemplate>
Videos
Asciidoctor Extensions
Asciidoctor extensions
● Add extra features to your entries adding extension such as:
○ Comments
○ Render mathematical formulas
○ Diagrams
○ QR Code
○ ...
Asciidoctor Diagram
● Already added to JBake
● We have to enable it in the jbake.properties
Create a diagram
● In your asciidoctor content files write a ditaa diagram:
Add Disqus
● Puravida extensions
○ https://puravida-software.gitlab.io/asciidoctor-extensions/
● Add the following inline directive to your content file
Replace asciidoctor-extensions with the id you registered in Disqus.com
More extensions
● Asciidoctor site extension list
○ https://asciidoctor.org/docs/extensions/
● Puravida extensions
○ https://gitlab.com/puravida-software/asciidoctor-extensions
Add a site to our OSS project
JBake integrates with build tools
● I’ve got an OSS project and I would like to create the project’s site
○ The project is already using a build tool
○ The project already generates different types of docs you’d like to link from the site
■ Javadocs, using guides...etc
● In this case I’ll be using Gradle
○ www.gradle.org
OSS Project
● Simple Gradle Java Project
○ Site
○ Javadoc
● I would like it to have its own site and integrate the javadoc in it
● Show some source code in the web site
Clone project
git clone https://github.com/mariogarcia/jbake_greach.git
Add JBake plugin
● In your build.gradle.kts
Add source code in site
Make asciidoctor content files aware...
● You need to pass where the source files are to being able to include them in the web page
○ Set configuration.asciidoctor.attributes
Include source code in documentation
● Use asciidoctor include directive
Access javadoc from site
Include javadoc
● Generate javadoc
● Copy javadoc to jbake output dir
● Add link to javadoc index.html page
Include javadoc (cont.)
Include javadoc
● Link it from documentation.adoc
● It’s just a relative link to javadoc/index.html
Include javadoc
Add Disqus
Add Disqus
● Add Puravida Extensions
Add Disqus
● Add disqus directive to documentation.adoc
○ Check https://puravida-software.gitlab.io/asciidoctor-extensions
Integrate asciidoc
Asciidoctor user guide
● Add asciidoctor plugin
Asciidoctor
● Generate content (modify src/main/index.adoc) and then
○ ./gradlew ascii
● Copy generated output to jbake output
○ from build/asciidoc/html5
○ into build/jbake/guide
● Include relative link to user guide in documentation.adoc
Asciidoctor
Asciidoctor
Summary
Summary
● Jbake great for create blog content or micro sites
● Good integration with existing build tools
● Good integration with asciidoctor
● I hope you liked it

Jbake workshop (Greach 2019)

  • 1.
  • 2.
    Me ● Mario Garcia ●Working at Kaleidos.net ● Mostly Backend Developer (Java, Groovy) ● Some Frontend lately (React, Vue, CSS still not my thing)
  • 3.
    Schedule ● What isJBake and use cases ● Installation ● Basic commands ● Blog ○ Create content ○ Templates ○ Custom content ○ Asciidoctor extensions ○ Push it to Github
  • 4.
    Schedule ● Break (15min) ● Project OSS ○ Some code in Gradle project ○ Configure bake ○ Include javadoc ○ Include asciidoctor doc
  • 5.
    What is JBake “JBakeis a Java based, open source, static site/blog generator for developers & designers”
  • 6.
    Some features ● Selfcontained ● Integrated with other build tools (Gradle, Maven, SBT…) ● Content formats (asciidoctor, markdown, html) ● Multiple template support ● Draft support ● ….
  • 7.
  • 8.
  • 9.
    ● Prerequisites ○ JDK8 ● Three scenarios ○ Download BINARY directly ○ Install via SDKMAN command line (sdkman.io) ○ Integrate with your favourite BUILDING TOOL Installation
  • 10.
    SDKMAN ● Install sdkman(https://sdkman.io/install) ● Then “sdk install jbake”
  • 11.
    Download binary ● Goto https://jbake.org/download.html ● Click on the latest distribution ● Decompress the zip wherever you want ● Make sure the jbake command is available in your console path ○ If you’re in linux e.g. modify .bashrc to add jbake command to the $PATH
  • 12.
    Integrate with yourbuild tool We’ll see an example in the second part of this workshop with Gradle
  • 13.
    Use your favouriteIDE ● Use any IDE with syntax highlight for ○ Asciidoctor ○ Markdown ○ HTML ○ Groovy
  • 14.
    Get used withthe basics
  • 15.
    Basic commands ● We’restill playing so create a temporary folder ○ Check JBake help ■ jbake --help ○ Create folder nameofproject ■ jbake -i <nameofproject> ○ Browse the structure with your favourite editor
  • 16.
    Basic commands ● Bakecontent to get html ○ Get into the <nameoftheproject> folder then execute ■ jbake -b ○ That will produce the final output of the blog, to browse it as if it were published online, do: ■ jbake -s
  • 17.
  • 18.
    Create greachblog ● Createthe new project using Groovy MTE as template engine ○ jbake -i -t groovy-mte greachblog ● Lets comment on the structure and templates a little bit
  • 19.
    Structure ● Directories ○ assets:css, js, images… ○ content: asciidoctor, markdown or html files ○ templates: Templates to interpret content files and produce the final ouput result ● jbake.properties ○ JBake configuration
  • 20.
  • 21.
    About Groovy templates ●No need for enclosing tag. Braces mark the scope
  • 22.
    About Groovy templates ●Plain strings can be inserted using yield or yieldUnscaped
  • 23.
    Lets create anew entry
  • 24.
    Open the projectin your favourite editor ● Mines are (the ones I can help you with) ○ Emacs ○ IntelliJ ● But any editor should work. ● Look for plugins/extensions that could help you rendering/highlighting Markdown or Asciidoctor syntax
  • 25.
    Asciidoctor ● “A fasttext processor & publishing toolchain for converting AsciiDoc to HTML5, DocBook & more”. ○ Asciidoctor: https://asciidoctor.org/ ○ Syntax Reference: https://asciidoctor.org/docs/asciidoc-syntax-quick-reference
  • 26.
    Create an entryfor today ● Create an asciidoctor file ○ greachblog/content/2019/03/28/greach_jbake_workshop.adoc ● Copy the following content:
  • 27.
  • 28.
    Then bake itand serve it locally ● Execute with -s (it does bake and serve altogether) ○ jbake -s
  • 29.
  • 30.
    I don’t seemy name in the entry ● We would like all blog entries to show the name of the author ● What do we need ? ○ Know about the JBAKE DATA MODEL ○ Modify the template to add the property author ○ Bake it again
  • 31.
    JBake Data Model ●Global variables: These data variables are available to all templates regardless of the type. ● Page / Post / Custom: Variables for predefined templates as well as any custom templates you created yourself ● Index: The index template has extra data variables available to it related to paging ● Tags: Data related to published tagged documents https://jbake.org/docs/2.6.4/#data_model
  • 32.
    Add the author ●Task 1 ○ Go to post-brick.tpl and add the author somewhere ○ Check JBake post related variables https://jbake.org/docs/2.6.4/#data_model
  • 33.
    ● Task 2 ○I would like to write code in its own source file and then show it partially in the blog entry. I also want to be able to download the sample code ■ You can add a :metaproperty: in the asciidoc document header called attached with the name of the script ■ Add the script at the same place as the asciidoc document ■ Add an href in the header to “download” the attached document getting the name from the post headers Attach code to entry
  • 34.
  • 35.
    Pages, Posts, Tags…Videos ? ● Create a new template named videos.tpl ● The new content of type video should set it in the content file header :type: ● We will pass the youtube video id to the template via content header :video: ● If you want to add a new type of content you should associate the new type of templates in jbake.properties ○ template.<newtype>.tpl=<nameofthetemplate>
  • 36.
  • 37.
  • 38.
    Asciidoctor extensions ● Addextra features to your entries adding extension such as: ○ Comments ○ Render mathematical formulas ○ Diagrams ○ QR Code ○ ...
  • 39.
    Asciidoctor Diagram ● Alreadyadded to JBake ● We have to enable it in the jbake.properties
  • 40.
    Create a diagram ●In your asciidoctor content files write a ditaa diagram:
  • 41.
    Add Disqus ● Puravidaextensions ○ https://puravida-software.gitlab.io/asciidoctor-extensions/ ● Add the following inline directive to your content file Replace asciidoctor-extensions with the id you registered in Disqus.com
  • 42.
    More extensions ● Asciidoctorsite extension list ○ https://asciidoctor.org/docs/extensions/ ● Puravida extensions ○ https://gitlab.com/puravida-software/asciidoctor-extensions
  • 43.
    Add a siteto our OSS project
  • 44.
    JBake integrates withbuild tools ● I’ve got an OSS project and I would like to create the project’s site ○ The project is already using a build tool ○ The project already generates different types of docs you’d like to link from the site ■ Javadocs, using guides...etc ● In this case I’ll be using Gradle ○ www.gradle.org
  • 45.
    OSS Project ● SimpleGradle Java Project ○ Site ○ Javadoc ● I would like it to have its own site and integrate the javadoc in it ● Show some source code in the web site
  • 46.
    Clone project git clonehttps://github.com/mariogarcia/jbake_greach.git
  • 47.
    Add JBake plugin ●In your build.gradle.kts
  • 48.
  • 49.
    Make asciidoctor contentfiles aware... ● You need to pass where the source files are to being able to include them in the web page ○ Set configuration.asciidoctor.attributes
  • 50.
    Include source codein documentation ● Use asciidoctor include directive
  • 51.
  • 52.
    Include javadoc ● Generatejavadoc ● Copy javadoc to jbake output dir ● Add link to javadoc index.html page
  • 53.
  • 54.
    Include javadoc ● Linkit from documentation.adoc ● It’s just a relative link to javadoc/index.html
  • 55.
  • 56.
  • 57.
    Add Disqus ● AddPuravida Extensions
  • 58.
    Add Disqus ● Adddisqus directive to documentation.adoc ○ Check https://puravida-software.gitlab.io/asciidoctor-extensions
  • 59.
  • 60.
    Asciidoctor user guide ●Add asciidoctor plugin
  • 61.
    Asciidoctor ● Generate content(modify src/main/index.adoc) and then ○ ./gradlew ascii ● Copy generated output to jbake output ○ from build/asciidoc/html5 ○ into build/jbake/guide ● Include relative link to user guide in documentation.adoc
  • 62.
  • 63.
  • 64.
  • 65.
    Summary ● Jbake greatfor create blog content or micro sites ● Good integration with existing build tools ● Good integration with asciidoctor ● I hope you liked it