Cryogen Static Site Generator

repository·master·Indexed 22 days ago

https://github.com/cryogen-project/cryogen

A static site generator for blogs and pages supporting Markdown and AsciiDoc. Cryogen features automatic content recompilation, theme customization via Selmer templates, and built-in support for RSS, sitemaps, and syntax highlighting using Highlight.js. It can be initialized and managed using Leiningen, clj-new, or deps-new.

Tokens
3.1K
Snippets
10
Records
12
Agent score
77%

What's inside Cryogen

  1. Customize layouts with Selmer

    master

    Cryogen uses the Selmer templating engine. Layout files are located in themes/{theme}/html/.

    Layout Structure

    • Base Layout: base.html is the primary layout. Use this to define global assets (CSS/JS), headers, and footers.
    • Page Layouts: Specific layouts (e.g., tag.html) should extend the base layout using {% extends "/html/base.html" %} and wrap their unique content in a {% block content %} block.
    • Metadata Mapping: Each page's metadata :layout key must match the filename of the layout (e.g., :layout "tag" maps to tag.html).

    Example tag.html layout:

    {% extends "/html/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 %}
  2. Create a new Cryogen site

    master

    You can initialize a new Cryogen website using Leiningen, clj-new, or deps-new.

    Using Leiningen

    Requires Leiningen 2.5.0 or above.

    lein new cryogen my-blog

    Using clj-new

    clojure -Ttools install com.github.seancorfield/clj-new '{:git/tag "v1.2.362"}' :as clj-new
    clojure -TClj-new create :template cryogen :name myname/myblog :force true
    cd myname/myblog/

    Using deps-new

    clojure -Ttools install io.github.seancorfield/deps-new '{:git/tag "v0.4.0"}' :as new
    clojure -Sdeps '{:deps {io.github.cryogen-project/cryogen {:git/tag "0.6.6" :git/sha "fcb2833"}}}' -Tnew create :template org.cryogenweb/new :name myname/myblog
    cd myname/myblog/
  3. Customize layouts using Selmer

    master

    Cryogen uses the Selmer templating engine.

    Layout Structure:

    • Base layouts are located in themes/{theme}/html/base.html. This is where you define global assets (CSS/JS), headers, and footers.
    • Specific page layouts should be placed in themes/{theme}/html/ and must match the :layout key in the page's metadata.
    • Page layouts should use {% extends "/html/base.html" %} and wrap their unique content in a {% block content %} block.

    Example tag.html layout:

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

    master

    To change your site's theme, update the :theme key in content/config.edn to match a folder name in the themes/ directory.

    The default template includes three themes. Note that the Nucleus theme is an external asset that may have specific usage requirements (e.g., keeping the footer).

  5. Deploy your Cryogen site

    master

    The generated static site is located in the public folder. You can host this folder using any static web server like Nginx or Apache.

    Nginx Example

    To serve your site at yoursite.com, configure an Nginx server block as follows:

    server {
      listen 80 default_server;
      listen [::]:80 default_server ipv6only=on;
      server_name localhost <yoursite.com> <www.yoursite.com>;
    
      access_log  /var/log/blog_access.log;
      error_log   /var/log/blog_error.log;
    
      location / {
        alias       /var/blog/;
        error_page  404 = /404.html;
      }
    }

    Deployment Steps:

    1. Copy the contents of your public folder to the server directory (e.g., /var/blog/).
    2. Update the server_name in your Nginx config.
    3. Place a custom error page at /var/blog/404.html.
  6. Run the Cryogen development server

    master

    Start a web server that watches the content and themes folders for changes and automatically recompiles.

    Using Leiningen

    lein serve # or lein serve:fast

    Using tools-deps

    clojure -X:serve # or clojure -X:serve:fast

    Note: The *:fast variants perform partial compilation of only the changed page/post to speed up the process.

    Static Generation Only

    If you only want to generate the static files without starting a server:

    lein run
    # or
    clojure -M:build
    lein serve
  7. Configure Code Syntax Highlighting

    master

    Cryogen uses Highlight.js for syntax highlighting.

    To add support for more languages, replace the existing themes/{theme}/js/highlight.pack.js with a customized package downloaded from the Highlight.js website. The initialization function hljs.initHighlightingOnLoad() is automatically called within themes/{theme}/html/base.html.

    <script>hljs.initHighlightingOnLoad();</script>
  8. Install the Lotus theme

    master

    To use the Lotus theme in your Cryogen site, follow these steps:

    1. Install Sass: Ensure sass is installed on your system.
    2. Configure Sass Path: In your content/config.edn file, set the :sass-path key to the location of your Sass installation. If Sass is installed globally, use the string "sass".
    3. Enable the Theme: In content/config.edn, change the :theme key to "lotus".
    4. Customize Branding:
      • Open base.html and replace the existing GitHub and LinkedIn links with your own profile links.
      • Replace the white lotus logo in base.html with your preferred logo.
      • For additional social media icons, refer to icons.svg.
    ;; content/config.edn
    {:sass-path "sass"
     :theme "lotus"}
  9. Switch between Markdown and AsciiDoc

    master

    By default, Cryogen uses Markdown. To switch to AsciiDoc:

    1. Open project.clj in your site directory.
    2. In the :dependencies section, replace cryogen-flexmark with cryogen-asciidoc (ensuring version compatibility).

    Once switched, the compiler will look for .asc files in the content/asc directory instead of .md files in content/md.

  10. Configure the site via config.edn

    master

    Site-wide settings are managed in content/config.edn. Key configuration options include:

    • :site-title: The title of your site.
    • :author: The author's name.
    • :site-url: The base URL of the site.
    • :post-root / :page-root: Directories for posts and pages.
    • :public-dest: Where the static site is generated.
    • :theme: The selected theme name (e.g., "blue").
    • :disqus?: Boolean to enable/disable Disqus.
    • :clean-urls: URL formatting (e.g., :trailing-slash).
    • :hide-future-posts?: Boolean to hide posts with future dates.
    {:site-title                   "My Awesome Blog"
     :author                       "Bob Bobbert"
     :description                  "This blog is awesome"
     :site-url                     "http://blogawesome.com/"
     :post-root                    "posts"
     :page-root                    "pages"
     :post-root-uri                "posts-output"
     :page-root-uri                "pages-output"
     :tag-root-uri                 "tags-output"
     :author-root-uri              "authors-output"
     :public-dest                  "public"
     :blog-prefix                  "/blog"
     :rss-name                     "feed.xml"
     :rss-filters                  ["cryogen"]
     :recent-posts                 3
     :post-date-format             "yyyy-MM-dd"
     :archive-group-format         "yyyy MMMM"
     :sass-src                     []
     :sass-path                    "sass"
     :theme                        "blue"
     :resources                    ["img"]
     :keep-files                   [".git"]
     :disqus?                      false
     :disqus-shortname             ""
     :ignored-files                [#"\.#.*" #".*\.swp$"]
     :previews?                    false
     :posts-per-page               5
     :blocks-per-preview           2
     :clean-urls                   :trailing-slash
     :collapse-subdirs?            false
     :hide-future-posts?           true
     :klipse                       {}
     :description-include-elements #{:p :h1 :h2 :h3 :h4 :h5 :h6}
     :debug?                       false}
  11. Configure your Cryogen site

    master

    Site configuration is managed in content/config.edn. This file controls site metadata, routing, themes, and plugin settings.

    Example configuration structure:

    {:site-title                   "My Awesome Blog"
     :author                       "Bob Bobbert"
     :description                  "This blog is awesome"
     :site-url                     "http://blogawesome.com/"
     :post-root                    "posts"
     :page-root                    "pages"
     :post-root-uri                "posts-output"
     :page-root-uri                "pages-output"
     :tag-root-uri                 "tags-output"
     :author-root-uri              "authors-output"
     :public-dest                  "public"
     :blog-prefix                  "/blog"
     :rss-name                     "feed.xml"
     :rss-filters                  ["cryogen"]
     :recent-posts                 3
     :post-date-format             "yyyy-MM-dd"
     :archive-group-format         "yyyy MMMM"
     :sass-src                     []
     :sass-path                    "sass"
     :theme                        "blue"
     :resources                    ["img"]
     :keep-files                   [".git"]
     :disqus?                      false
     :disqus-shortname             ""
     :ignored-files                [#"\.#.*" #".*\.swp$"]
     :previews?                    false
     :posts-per-page               5
     :blocks-per-preview           2
     :clean-urls                   :trailing-slash
     :collapse-subdirs?            false
     :hide-future-posts?           true
     :klipse                       {}
     :description-include-elements #{:p :h1 :h2 :h3 :h4 :h5 :h6}
     :debug?                       false}

    For a full list of keys, refer to the official Cryogen documentation site.

    {:site-title "My Awesome Blog"
     :theme "blue"}