Stapy is a real-time static page generator made with Python https://stapy.magentix.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
magentix 568b180ed9 Themes section added 1 week ago
build Themes section added 1 week ago
web Necessary resources copied from build/web to web 3 weeks ago
LICENCE Copyright updated 3 weeks ago
README.md Themes section added 1 week ago
crawler.sh Exclude default configuration file 2 weeks ago
server.py default config file optional 1 week ago

README.md

StaPy

StaPy is a real-time static page generator made with Python 3. The code is a file of about 200 lines to modify freely.

Requirements

Requires Python 3.4 or newer on any operating system.

Themes

Simple and minimal themes made with StaPy:

Installation

Create a project directory anywhere and download the last release from the StaPy repository.

mkdir stapy
cd stapy
wget https://codeberg.org/magentix/stapy/archive/last.tar.gz
tar zxvf last.tar.gz --strip 1
rm last.tar.gz

Website

Static files are generated in the web directory. It contains all pages and files you need to deploy (html, css, js, images...).

HTTP server

Run standalone HTTP server:

python3 server.py

Access to http://localhost:1985

Route

When a page is open in the browser, the server search a json file in build/json directory. The name of the json file is the same as the URL path. Examples:

URL Path Json file
/ index.html.json
/hello.html hello.html.json
/hello/world.html hello/world.html.json
/hello/world/ hello/world/index.html.json

If the json file does not exist, a 404 error is sent.

Configuration

The json file contains all the data required for generate the page:

{
  "title": "Page title",
  "description": "Page description",
  "template": "build/template/default.html",
  "content": "build/page/index.html"
}

template and content keys are required.

A file named default.json in the build/json directory is used for the default configuration. It will be merged with the page's json file. This is useful for a global configuration.

default.json

{
  "title": "Default title",
  "template": "build/template/default.html"
}

index.html.json

{
  "title": "Home title",
  "content": "build/page/index.html"
}

default.json + index.html.json

{
  "title": "Home title",
  "template": "build/template/default.html",
  "content": "build/page/index.html"
}

Note: the default.json file is optional.

Template

The template file is the skeleton of the page:

<!DOCTYPE html>
<html lang="fr">
    <head>
        <meta charset="utf-8">
        <title>{{ title }}</title>
        <meta name="description" content="{{ description }}" />
        <link rel="stylesheet" href="/css/style.css" />
    </head>
    <body>
        {% content %}
    </body>
</html>
  • All variables in double curly braces {{ }} will be replaced with the text declared in the json file for the var.
  • All variables in curly brace percent {% %} will be replaced with the content of the file declared in the json file for the var.

Tip: set false for the variable in the json file to replace it with empty text.

Resources

All necessary resources like js, css or images are copied from the build/web directory to the web directory.

Static files

The final static HTML files and resources are added or refreshed when the pages are opened in the browser. When /hello.html is open, the hello.html file is automatically generated in the web directory.

Crawler

The website can be regenerated with a crawler (for example when the template is updated). StaPy gives a simple cURL crawler. All declared routes (json) will be reached.

sh crawler.sh

200 http://localhost:1985/
200 http://localhost:1985/hello.html
...

Feel free to delete the web directory and launch the crawler.

Netlify

Setup Netlify to deploy the web directory of the git repository.