A simple static site generator.
PyBlue allows the reuse of visuals (header/footer) and data across many pages and it can generate static sites from dynamic templates.
This page was created with PyBlue from the file located in docs/index.html
There is no shortage of static html generators. PyBlue is a personal project that aims to address my personal annoyances with other options. I have evaluated quite a few alternatives even used some over longer periods of time. None of the choices did what I needed for my work. Hence came the motivation to write my own.
The following are some of the reasons why PyBlue exists:
And then of course it has many advanced features:
pip install pyblue --upgrade
Or download it from the PyBlue at PyPI. Alternatively to install the latest version:
git clone git@github.com:ialbert/pyblue.git
cd pyblue
python setup.py develop
The documentation that you read now has been created from the files in the docs folder.
pyblue -r docs
http:://localhost:8080
.pyblue -r docs -o html
To see extra help on options run: pyblue -h
The pages are rendered through the Django Template language. To make use of the templating you need to understand how this templating language works.
By default there is extra data associated with each page.
For example the
{{ page }}
variable is available:
{{ page.name }}
will produce: Index{{ page.last_modified }}
will produce: Monday, July 18, 2016{{ page.size|filesizeformat }}
will produce: 7.9 KBNote how in this last case we also made use of the filesizeformat
builtin filter of Django.
Users may add more information even load a python module into the page.
More details on the Context page.
Users can also make use of pyblue specific template tags that are
automatically available. For example the link
tag generates
relative paths to any other file.
{% link "context.html" %}
will
produce the following: Context
.
{% link "context.html" text="Click me now!" %}
will
produce the following: Click me now!
.
Important: Note how in this case the file is located in info/context.html
Yet we did not have
to put the full path the linking tag. PyBlue
found the file and linked it properly.
Why did that work? The {% link "context.html" %}
command performs a regular expression search on all files in the directory and
once it finds a match it produces a link to it with the proper relative path.
This keeps links correct even if the files were to be moved later.
Note that the search string is a regular expression and it is sufficient
to specify the shortest unambiguous part of the filename. PyBlue
will find it and link it.
As a matter of fact this is one reason PyBlue was written. I got very tired of fixing broken links after a site reorganization. PlyBlue now does it automatically.
The {% img "fractal.png" %}
tag works similarly to the link tag.
but generates image links. It also takes the css
parameter where css classes may be passed
to the image. The CSS itself will have to be defined in the page header or the site asssets.
To include markdown content into an HTML document place it between
{% markdown %}
and {% endmarkdown %}
template tags.
When using markdown fenced codeblocks may be used. Include code between ``` symbols that can also take language hints:
import sys
for line in open("data.txt"):
print line.strip()[:10]
To include syntax highlighted code from a file write {% code "context.py" lang="python" %}
#
# The data file named context.py in the root folder
# will be loaded automatically into the page.
#
NUMBERS = range(5)
# It may contain any valid python construct.
def say_hello(name):
return "Hello %s" % name
greeting = say_hello("World!")
This file is also special because of its name: context.py
. The contents of
this python module is available inside every page under the name of context
.
For example writing {{ context.greeting }}
produces: Hello World!.
This is where the full power of pyblue
shows. You see, you can go wild and add any and all
data that you might need. Call out to any program, read any file etc. It is Python
all the way down.
Alternatively one can instruct PyBlue to include the rendered content of markdown files.
To include the file example.md
in its original content one would use
{% code "example.md" %}
this would produce:
---
**Note**: This text comes from a **markdown** file.
print "Hello World!"
---
This same file could be included as html with {% markdown_file "example.md" %}
In that case it will produce the following:
Note: This text comes from a markdown file.
print "Hello World!"
Note how in both cases an automatic search takes place PyBlue will find the location
of the file example.md
wherever it might be on the root
directory. That's super convenient.
The django templating system allows extending or including other templates or sections.
{% extend "sometemplate.html" %}
{% include "sometemplate.html" %}
These features support template inheritance and composition.
Read on from more Advanced Features and Markdown test page