Skip to content

A modern, highly customizable static site generator for Python

License

Notifications You must be signed in to change notification settings

Mikuel210/Statify

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Statify

A modern, highly customizable static site generator for Python
Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License

About The Project

Statify is a highly customizable static site generator for Python. Statify allows you to make anything into a web. You decide where you get your data from and how is it compiled into the final page.

Python

(back to top)

Getting Started

Prerequisites

Installation

  1. Clone the repository
    git clone https://github.com/Mikuel210/Statify.git
  2. Install the requirements
    cd Statify # CD to the installation folder
    pip install -r requirements.txt
  3. Add the bin folder to your PATH

(back to top)

Usage

To create a new Statify project, create a new directory and type in the terminal:

statify init

You can also choose a template to start from. You can list all of the available templates by using statify templates. You can create your own templates by placing them into the bin/init directory in the Statify installation.

Type statify init [template] to start a new project from a template.

Virual environments

Virtual environments are a key part of understanding how Statify works. Virtual environments are Python scripts located in the project's temporary directory and executed from the project's root directory. All virtual environments automatically import the statify module, and are able to import other modules from Statify, such as constants or compiler.

You can execute a Python script as a virtual environment by calling statify.execute_venv.

The compile file

The compile file is executed when you run statify compile. Its purpose is to get the required data and turn it into the final pages.

This is how a basic compile file might look:

from pathlib import Path

pages = Path("pages")

for page in pages.iterdir():
    statify.compile({
        "input_path": page,
        "output_path": f"public/{page.name}"
    })

This compile file takes all templates from a directory and calls statify.compile to turn them into the final pages. The compile file is executed in a virtual environment, so it automatically imports the statify module.

statify.compile takes a context dictionary. A context might include:

  • input_path: The path of the template
  • output_path: The path of the final page
  • venv_template: The Python code to be executed before the code in the template. Both are executed in the same virtual environment, so the code in the page template is able to access the code in the virtual environment template.

The context can also include other custom keys, which are accessible through the statify.context dictionary. It is recommended to use statify.get_context_value, statify.get_context_value_safe and statify.set_context_value instead of directly working with the variable.

The templates

Templates are HTML files that can have embedded Python code. Embedded Python code is written inside of a <python> tag.

Templates get converted into virtual environments when they are compiled. All HTML code is turned into a statify.write call in the virtual environment, and embedded Python code remains the same. Embedded Python code is written into the virtual environment with its indentation relative to the <python> tag. HTML code is turned into a statify.write call with no indentation.

Useful functions for using in templates:

  • statify.write: Writes content to the final page
  • statify.render_partial: Compiles a template and writes it to the current page instead of to a file

Project configuration

Statify projects can have a .statifyconfig file either in the root directory or in a config directory. This file can override default configuration values for this project only.

A .statifyconfig file is written in JSON. It can override the following settings:

  • compile_file: The path to the compile file to be executed with statify compile
  • temp_directory: The directory to execute virtual environments in. All of its contents are deleted on compile.
  • public_directory: The directory for compiled pages. All of its contents are deleted on compile.
  • resources_directory: The directory, relative to the public directory, that will be kept on compile. Useful for storing CSS or JavaScript files that final pages might need to access.
  • debug: If set to true, virtual environments won't be deleted until compiling again.

(back to top)

Roadmap

  • More templates
  • Installation wizard
  • More default functions
  • Better IDE integration
  • Compile differences only
  • Auto compile on events (such as a database update)

See the open issues for a full list of proposed features and known issues.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repository and create a pull request. You can also simply open an issue with the tag "enhancement." Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Top contributors:

contrib.rocks image

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

About

A modern, highly customizable static site generator for Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages