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.1.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.1-py3-none-any.whl (12.7 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sgen_tool-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 f070a9001057e386687a302be0e8d4d490d53bd9f71b9d3a13da66d40b67ddd1
MD5 6b2dc3ecd6fdf3ba11281fb0014aa7c9
BLAKE2b-256 95d97071e03286ed3f1dd8ab5074ee1065b0d189c32eb5d2ff37c91d78136921

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sgen_tool-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4fd40cdacddee6684952a7a5f7055ead4e7f75a60b452167739c6b1a39fe8fb
MD5 b1f5a9c5d769148fba4d1a7c7dd4c2ba
BLAKE2b-256 0310b4f3858622de633f4df2e1bfa386ab84c5c6a53963422a56bda79953ceb9

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