{% extends "_templates_/base.html" %} {% block main %}
Welcome to Lightweight: a static website generator without magic.
You’re running version {{ ctx.version }}.
Since this is the core idea behind the framework,
start by checking out the site.py
file.
This module contains a few examples of using library.
It’s located right in the root of the generated project directory.
Having a project setup and a local dev server running we can play with some content:
Including a regular HTML to the site is easy:
about.html
.
site.py
right next to other includes:
site.include('about.html')
about.html
If your file is not located under the root of the project directory, then use the relative path.
For example file <project>/docs/examples/space-invasion.html
is included via:
site.include('docs/examples/space-invasion.html')
and will be accessible under /docs/examples/space-invasion.
Jinja is a powerful template engine for Python.
You can see how its used in the index.html
.
To render a Jinja template as part of the site use the lightweight.jinja
method:
from lightweight import jinja
...
site.include('index.html', jinja('index.html'))
...
This piece of code creates content from rendering the provided index.html
Jinja template
and places it under the same to the output directory.
You can also pass arguments to Jinja templates.
This is done via keyword arguments of jinja(src, **kwargs)
.
The code with the image looks like this:
{#- @formatter:off -#}
{%- raw -%}
{% if spoon is defined and spoon is none %}
<img src="{{ site / 'img/matrix/no-spoon.jpg' }}"
alt="A bent spoon"
title="There is no spoon.">
{% else %}
<img src="{{ site / 'img/matrix/spoon.jpg' }}"
alt="Matrix boy with an unbent spoon."
title="Do not try and bend the spoon. That's impossible. Instead… only try to realize the truth.">
{% endif %}
{%- endraw -%}
{#- @formatter:on -#}
We do not pass the spoon
to the template, so it is undefined.
Let’s pass None
to render the true branch of the if.
site.include('index.html', jinja('index.html', spoon=None))
{% endblock %}