Skip to content

A simple static site generator written in Clojure

License

Notifications You must be signed in to change notification settings

rspacjer/cryogen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<img src="https://raw.githubusercontent.com/lacarmen/cryogen/master/cryogen.png" hspace="20" align="left"height="200"/>

Features

  • blog posts and pages with Markdown
  • table of contents generation
  • Theming support with Twitter Bootstrap
  • plain HTML page templates
  • code syntax highlighting
  • tags
  • sitemap
  • sass/scss compilation
  • RSS

Prerequisites

You will need Leiningen 2.5.0 or above installed.

Usage

Creating a New Site

A new site can be created using the Cryogen template as follows:

lein new cryogen my-blog

Running the Server

The web server can be started using the lein-ring plugin:

lein ring server

The server will watch for changes in the resources/templates folder and recompile the content automatically.

Site Configuration

The site configuration file is found at templates/config.edn, this file looks as follows:

{:site-title "My Awesome Blog"
 :author "Bob Bobbert"
 :description "This blog is awesome"
 :site-url "http://blogawesome.com/"
 :post-root "posts"
 :tag-root "tags"
 :page-root "pages"
 :blog-prefix "/blog"
 :rss-name "feed.xml"
 :sass-src "css"
 :sass-dest "css"
 :resources ["css" "js" "img"]}
  • post-root - value prepended to all post uri's
  • tag-root - value prepended to all tag uri's
  • page-root - value prepended to all page uri's
  • blog-prefix - prepended to all uri's (must start with slash), nil by default
  • rss-name - name of the rss file generated, nil defaults to rss.xml
  • sass-src - directory containing sources of sass files to be compiled - defaults to "css" - be sure to include this directory in your resources section
  • sass-dest - directory where the compiled output CSS would be put into. defaults to "css" - be sure to include this directory in your resources section
  • resources - list of folders to be copied over from templates to public

Creating Posts

The posts are located in the resources/templates/md/posts. Posts are written using Markdown and each post file should start with the date in the format of dd-MM-yyyy. The compiler will link the posts in order for you using the dates. A valid post file might look as follows:

19-12-2014-post1.md

The post content must start with a map containing the post metadata:

{:title "First Post!"
 :layout :post
 :tags  ["tag1" "tag3"]}

The metadata contains the following keys:

  • :title - the title of the post
  • :layout - the layout template to use for the post
  • :tags - the tags associated with this post
  • :toc - boolean indicating whether table of contents should be generated, defaults to false

The rest of the post should consist of valid Markdown content, eg:

## Hello World

This is my first post!

check out this sweet code

    (defn foo [bar]
      (bar))

Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nunc sodales pharetra massa, eget fringilla ex ornare et.
Nunc mattis diam ac urna finibus sodales. Etiam sed ipsum
et purus commodo bibendum. Cras libero magna, fringilla
tristique quam sagittis, volutpat auctor mi. Aliquam luctus,
nulla et vestibulum finibus, nibh justo semper tortor, nec
vestibulum tortor est nec nisi.

Creating Pages

Pages work similarly to posts, but aren't grouped by date. An example page might be an about page.

The pages contain the following metadata:

  • :title - the title of the page
  • :layout - the layout template for the page
  • :page-index - a number representing the order of the page in the navbar/sidebar
  • :navbar? - determines whether the page should be shown in the navbar, false by default
  • :toc - boolean indicating whether table of contents should be generated, defaults to false

Customizing Layouts

The layouts are contained in the resources/templates/html/layouts folder of the project. By default, the base.html layout is used to provide the general layout for the site. This is where you would add static resources such as CSS and Js assets as well as define headers and footers for your site.

Each page layout should have a name that matches the :layout key in the page metadata and end with .html. Page layouts extend the base layout and should only contain the content relaveant to the page inside the content block. For example, the tag layout is located in tag.html and looks as follows:

{% extends "templates/html/layouts/base.html" %}
{% block content %}
<div id="posts-by-tag">
    <h2>Posts tagged {{name}}</h2>
    <ul>
    {% for post in posts %}
        <li>
            <a href="{{post.uri}}">{{post.title}}</a>
        </li>
    {% endfor %}
    </ul>
</div>
{% endblock %}

Code Syntax Highlighting

Cryogen uses Highlight.js for code syntax highlighting. You can add more languages by replacing templates/js/highlight.pack.js with a customized package from here.

The initHighlightingOnLoad function is called in templates/html/layouts/base.html.

<script>hljs.initHighlightingOnLoad();</script>

Deploying Your Site

The generated static content will be found under the resources/public folder. Simply copy the content to a static folder for a server sugh as Nginx or Apache and your site is now ready for service.

Sites Made With Cryogen

License

Copyright © 2014 Carmen La

Distributed under the Eclipse Public License, the same as Clojure.

About

A simple static site generator written in Clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Clojure 95.6%
  • CSS 4.4%