Skip to main content

Simple Python-based static site generator

Project description

S-Gen

This is a simple yet powerful static site generator that is easy to migrate from html.

Environments

Python 3.11.x/3.12.x (Recommended)

Get started

Install

  1. Make virtual env: python3 -m venv env
  2. Activate virtual env: source env/bin/activate for linux/macos or .\env\Scripts\activate for windows
  3. Run (python3 -m )pip install git+https://github.com/timomono/sgen.git

Create project

(python3 -m )sgen create example_project
cd example_project

Listen

If you're using VSCode, press Cmd/Ctrl + Shift + B, otherwise

(python3 -m )sgen listen

It will be built automatically when the file changes.

Run development server

(python3 -m )sgen runserver

Please note that it won't work unless you build it.

Now that the developing server’s running, visit localhost:8282 with your web browser.

You'll see a simple Hello world! page. It worked!

Create checklist app

Let's create a simple checklist app.

Create project

Follow the steps above to create an app named "simple_checklist" and build it, and start the server.

Write template

Open simple_checklist/src/(file name) in your favorite editor and copy and paste the following:

src/base.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{title}} | S-Gen Example</title>
    <style>
        body {
            margin: 0;
        }
        .navbar {
            background-color: brown;
            display: flex;
            align-items: center;
        }
        .navbar * {
            color: white;
        }
    </style>
</head>
<body>
    <div class="navbar">
        <h1 style="margin:0;padding: 1rem;">
            {{heading}}
        </h1>
        <ul>
            <li>
                <a href="/">Color</a>
                <a href="/animal.html">Animal</a>
            </li>
        </ul>
    </div>
    <div style="padding: 1rem;">
        {{body}}
    </div>
</body>
</html>

src/index.html

{% from sgen.stdlib.pyrender.avoid_escape import AvoidEscape %}
{{ include("base.html",
        title="Favorite color",
        heading="Color",
        body=AvoidEscape(f"""
        <label for="favorite-color">What color do you like?</label>
        <select id="favorite-color">
            {
                "".join([
                    f'<option value="{color}">{{color}}</option>'
                    for color in ["red","green","blue"]
                ])
            }
        </select>
        """)
    ) }}

src/animal.html

{% from sgen.stdlib.pyrender.avoid_escape import AvoidEscape %}
{{ include("base.html", 
    ```
    title="Favorite animal",
        heading="Animal",
        body=AvoidEscape(f"""
        <label for="favorite-animal">What animal do you like?</label>
        <select id="favorite-animal">
            {
                "".join([
                    f'<option value="{animal}">{{animal}}</option>'
                    for animal in ["zebra","lion","cat"]
                ])
            }
        </select>
        """)
    ) }}
    ```

A dropdown menu will appear.

This is as short as it gets. If we were to write raw HTML, it would be much longer.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sgen_tool-1.0.0.tar.gz (12.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sgen_tool-1.0.0-py3-none-any.whl (12.7 MB view details)

Uploaded Python 3

File details

Details for the file sgen_tool-1.0.0.tar.gz.

File metadata

  • Download URL: sgen_tool-1.0.0.tar.gz
  • Upload date:
  • Size: 12.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sgen_tool-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9b7ab0ccd872909d4a25706cf80e50756878640bc0160eb3093376315785c3d6
MD5 63453fec306572af3cb1ca9724f6ca16
BLAKE2b-256 d3d0690902c33e0ce9e4fcb6f0f551450080251ef269be641bdee94ffdfa5aaa

See more details on using hashes here.

File details

Details for the file sgen_tool-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: sgen_tool-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for sgen_tool-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ed824331f91ad2b835bd799466542e46e5085a786dd0d3663047cbeb9c1beb0
MD5 9dfa78a34a924f974a2c4115c6ce4dba
BLAKE2b-256 e6daf9afa256c79d1e3b55c012f13e5903affb710edfa5d5283ea5569d9760ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page