Uses Java7 file watch service to monitor a directory structure that has freemarker templates. When changes are detected it generates a html page including support for syntax highlighting for Java, SQL, XML, Javascript.
Typically you install and run this application on a server and setup a cron job that pulls website changes from git or svn. This application detects changes and updates the pages in a destination directory and you use Nginx or Apache to serve the content.
Download the runnable jar from maven central.
Run it specifying a source directory (that has the freemarker templates etc) and a destination directory (where the
resulting html is generated to). Note that the source directory can have an other files (css, js, images, fonts etc) - if the
file extension ends with
java -jar avaje-website-generator-1.0.1.jar \n
-source /home/rob/website/source \n
-dest /home/rob/website/destination
# edit the templates etc in the source directory
# the pages etc are automatically generated
# into the destination directoy
The source directory can have an other files (css, js, images, fonts etc). If the
file extension ends with
On a server typically this program is running and there is a cron job that pulls updates into the source directory via git pull or similar. Nginx or similar is configured to serve the pages from the destination directory.
<dependency>
<groupId>org.avaje</groupId>
<artifactId>avaje-website-generator</artifactId>
<version>1.0.1</version>
</dependency>
The Java7 file watch service uses OS level file watching events so it is fast and efficient. pygments.org provides the nice server side syntax highlighting and we are using Jyphon to execute this - its slow for the first syntax highlight but then is decent performance.
Uses Freemarker for templating and Jyphon / Pygments for syntax hightlighting. Has a simple template layout inheritance mechanism as described below.
<!-- In the 'child' page -->
<meta name="layout" content="_layout/parent-layout.html" />
The meta layout
tag defines a parent template to inherit.
<!-- In the parent page -->
<div id="layout-body"></div>
In the parent page a div
with an id
of layout-body
defines where in the parent the child page content goes.
<head>
<!-- In the 'child' page -->
<title>The page title</title>
...
If you have a title
tag in the head of the page then this title is used in the final generated page.
<head>
<!-- tags in the head section of the 'child' page -->
</head>
Any content you have in the head
section of the page will be incorporated into the final page layout as
long as the parent layout includes a meta
tag with an id
of layout-head
.
<!-- In the parent page -->
<meta id="layout-head" />
Pygments provides the syntax highlighting and Jython is used to execute it.
The supported languages for syntax highlighting is: java, groovy, scala, javascript, sql, sh, and properties
To use the syntax highlighting you prefix the code with 3 backticks followed by the language and terminate it with 3 backticks.
``java // only 2 backticks above ... ``
Example logs from running the application are shown below:
java -jar avaje-website-generator-1.0.1.jar -s /home/rob/website-source -d /home/rob/site
--
-- walks the source directory tree and generates html and copies files into destination directory
--
16:33:26.341 [main] DEBUG o.a.w.generator.SiteWatchRender - ... render template: websitegenerator/index.html
16:33:31.648 [main] DEBUG o.a.w.generator.SiteWatchRender - ... render template: index.html
16:33:31.663 [main] DEBUG o.a.w.generator.SiteWatchRender - ... render template: docs/transactions/begincommit.html
...
16:33:34.409 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... copy file: css/bootstrap.min.css
16:33:34.421 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... copy file: images/favicon.ico
16:33:34.422 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... copy file: README.md
16:33:34.422 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... render template: metrics/index.html
16:33:34.439 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... copy file: js/bootstrap.js
16:33:34.440 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... copy file: js/bootstrap.min.js
--
-- After the source directory walk the watcher service is registered on all the directories
--
16:33:34.443 [MainThread] INFO org.avaje.website.generator.WatchDir - Scanning /home/rob/website-source ...
16:33:34.476 [MainThread] INFO org.avaje.website.generator.WatchDir - Watching...
--
-- The watch service detects file change events and pages are regenerated
-- or files/directories copied/deleted as required
--
16:34:18.315 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... render template: websitegenerator/index.html
16:56:56.423 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... deleted file /home/rob/site/websitegenerator/hellorob.html
16:57:10.528 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... copy file: websitegenerator/docs.css
16:57:32.913 [MainThread] DEBUG o.a.w.generator.SiteWatchRender - ... deleted directory /home/rob/work-avaje/site/websitegenerator/morecss