Table of Contents
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.
- Clone the repository
git clone https://github.com/Mikuel210/Statify.git
- Install the requirements
cd Statify # CD to the installation folder pip install -r requirements.txt
- Add the
bin
folder to yourPATH
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.
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 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 templateoutput_path
: The path of the final pagevenv_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.
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 pagestatify.render_partial
: Compiles a template and writes it to the current page instead of to a file
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 withstatify 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.
- 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.
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.