Skip to content

Instantly share code, notes, and snippets.

@samuelcolvin
Last active August 4, 2016 16:41
Show Gist options
  • Save samuelcolvin/814f6609bdacb2cd8c80d3494fc67802 to your computer and use it in GitHub Desktop.
Save samuelcolvin/814f6609bdacb2cd8c80d3494fc67802 to your computer and use it in GitHub Desktop.

Static site generator inspired by jekyll but much improved

Features:

  • jinja templating language
  • written in python: easy to install modify and extend
  • built in redirects, sitemap and html checking.
  • support for resusable templates, allow reference to templates dir. or list of dirs, thereby allowing just a single file to be overruled.
  • auto-reload with dev. server
  • dynamic static file names to work well with CDNs
  • support for markdown and/or restructured text
  • sass compiling
  • partial rebuilds for performance
  • auto deploy and check commands with scp, git and maybe more providers, including build.txt generation
  • multi-frontmatter, eg. support for more than one content section to pages
  • support variables inside pages
  • allow for easy extension
  • allow generation of nginx redirect .conf pages
  • config.local.yml support so you can run things differently locally
  • link conversion and default template link mkdocs
  • bower or grablib support

Data model

Context of a page:

. (page data in root of context): variables from frontmatter, name, path
site: full site object, including list of pages, tree of pages, pages with tags
data: data from data directory.

converting "pages" to templates:

simple page

---
layout: foo
---
this is content

becomes:

{"content": "this is content"}
{% extends 'foo.jinja (or html)' %}
{% block content %}
this is content
{% endblock %}

explicit context

---
layout: foo
whatever: 4
---
{% block foo %}
this is content
{% endbock %}

{% block bar %}
this is content
{% endbock %}

becomes:

{"whatever": 4}
{% extends 'foo.jinja' %}

{% block foo %}
this is content
{% endbock %}

{% block bar %}
this is content
{% endbock %}

content + blocks

---
layout: foo
---
this is content

{% block bar %}
this is content 1
{% endbock %}

becomes:

{"content": "this is content 1"}
{% extends 'foo.jinja' %}

{% block content %}
this is content 1
{% endbock %}

{% block bar %}
this is content
{% endbock %}

multi list

---
layout: foo
multi: list
---
this is content 1
---
---
this is content 2

becomes:

{"content": ["this is content 1", "this is content 2"]}
{% extends 'foo.jinja' %}

multi dict

---
layout: foo
multi: dict
key: first_element
---
this is content 1
---
key: foobar
something_else: 4
---
this is content 2

becomes:

{"content": {"first_element": "this is content 1", "foobar": "this is content 2"}}
{% extends 'foo.jinja' %}

multi dict with first key missing

---
layout: foo
multi: dict
---
this is content 1
---
foobar
---
this is content 2

becomes:

{"content": {"primary_content": "this is content 1", "foobar": "this is content 2"}}
{% extends 'foo.jinja' %}

{% block content %}
this is content 1
{% endblock

extensions

from jackal import extensions
from jinja2 import contextfunction,

@extensions.modify_page('foobar.html', '/path/to/bar.md')
def modify_pages(template, context):
    context['whatever'] = 'changed'
    return template, context

@extensions.modify_context
def modify_entire_context(context):
    context['change'] = 1
    return context

@contextfunction
def whatever(context, file_name):
    return 'context to render'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment