{% extends "_templates_/base.html" %} {% block main %}

Welcome to Lightweight: a static website generator without magic.

You’re running version {{ ctx.version }}.

Code over configuration

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.

Next steps

Having a project setup and a local dev server running we can play with some content:

Include a new HTML page

Including a regular HTML to the site is easy:

  1. Create an HTML file under the project directory. We will assume it’s name to be about.html.
  2. Add a following line to site.py right next to other includes:
    site.include('about.html')
  3. Done! Check out the page at the location matching the file name, e.g. /about for 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.

Add a new page rendered by Jinja

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).

For example, try controlling the spoon. {% if spoon is defined and spoon is none %} A bent spoon {% else %} Matrix boy with an unbent spoon. {% endif %}

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))

Add some style

Create Content of your own

{% endblock %}