Skip to main content

A static site generator written in Python

Project description

ophinode

ophinode is a static site generator written in Python that focuses on being a simple and flexible library for creating websites.

This project is currently in the initial development stage, and the APIs may change at any time.

Example programs

You can also get these example programs by running python -m ophinode examples.

# Example program: render a page without defining a site.
#
# Running this program prints a HTML document to standard output.
#
from ophinode import *

class MainPage(HTML5Page):
    def body(self):
        return Div(
            H1("Main Page"),
            P("Welcome to ophinode!"),
        )

    def head(self):
        return [
            Meta(charset="utf-8"),
            Title("Main Page"),
        ]

print(render_page(MainPage(), HTML5Layout()))
# Example program: create a page in a directory.
#
# Running this program creates "index.html" in "./out" directory.
#
from ophinode import *

class DefaultLayout(Layout):
    def build(self, page, context):
        return [
            HTML5Doctype(),
            Html(
                Head(
                    Meta(charset="utf-8"),
                    Title(page.title()),
                    page.head(),
                ),
                Body(
                    page.body(),
                ),
            )
        ]

class MainPage(Page):
    @property
    def layout(self):
        return DefaultLayout()

    def body(self):
        return Div(
            H1("Main Page"),
            P("Welcome to ophinode!"),
        )

    def head(self):
        return []

    def title(self):
        return "Main Page"

if __name__ == "__main__":
    site = Site({
        "export_root_path"                       : "./out",
        "default_layout"                         : DefaultLayout(),
        "build_strategy"                         : "sync",
        "preserve_site_definition_across_builds" : False,
        "page_default_file_name"                 : "index.html",
        "page_default_file_name_suffix"          : ".html",
        "auto_write_exported_page_build_files"   : False,
        "auto_write_exported_site_build_files"   : True,
        "return_site_data_after_page_build"      : False,
        "return_page_data_after_page_build"      : False,
        "return_misc_data_after_page_build"      : True,
        "return_built_pages_after_page_build"    : False,
        "return_expanded_pages_after_page_build" : False,
        "return_rendered_pages_after_page_build" : False,
        "return_exported_files_after_page_build" : True,
        "gather_and_merge_page_build_results"    : True,
    }, [
        ("/", MainPage()),
    ])

    site.build_site()
# Example program: parallel build.
#
# Running this program creates "page1.html" to "page1000.html"
# in "./out" directory.
#
import os
from ophinode import *

class DefaultLayout(Layout):
    def build(self, page, context):
        return [
            HTML5Doctype(),
            Html(
                Head(
                    Meta(charset="utf-8"),
                    Title(page.title()),
                    page.head(),
                ),
                Body(
                    page.body(),
                ),
            )
        ]

class MainPage(Page):
    def __init__(self, idx):
        self.idx = idx

    @property
    def layout(self):
        return DefaultLayout()

    def body(self):
        return Div(
            H1("Main Page"),
            P("Welcome to ophinode!"),
            P(f"This is page{self.idx}.html."),
        )

    def head(self):
        return []

    def title(self):
        return "Main Page"

if __name__ == "__main__":
    cpu_count = os.cpu_count()
    site = Site({
        "export_root_path"                       : "./out",
        "default_layout"                         : DefaultLayout(),
        "build_strategy"                         : "parallel",
        "parallel_build_workers"                 : cpu_count,
        "parallel_build_chunksize"               : 1,
        "preserve_site_definition_across_builds" : False,
        "page_default_file_name"                 : "index.html",
        "page_default_file_name_suffix"          : ".html",
        "auto_write_exported_page_build_files"   : True,
        "auto_write_exported_site_build_files"   : False,
        "return_site_data_after_page_build"      : False,
        "return_page_data_after_page_build"      : False,
        "return_misc_data_after_page_build"      : True,
        "return_built_pages_after_page_build"    : False,
        "return_expanded_pages_after_page_build" : False,
        "return_rendered_pages_after_page_build" : False,
        "return_exported_files_after_page_build" : False,
        "gather_and_merge_page_build_results"    : False,
    }, [
    ])

    for i in range(1, 1001):
        page_group = i % cpu_count
        site.add_page(
            f"/page{i}.html",
            MainPage(i),
            page_group=f"{page_group}"
        )

    site.build_site()

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

ophinode-0.0.1a10.tar.gz (24.6 kB view details)

Uploaded Source

Built Distribution

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

ophinode-0.0.1a10-py3-none-any.whl (35.0 kB view details)

Uploaded Python 3

File details

Details for the file ophinode-0.0.1a10.tar.gz.

File metadata

  • Download URL: ophinode-0.0.1a10.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ophinode-0.0.1a10.tar.gz
Algorithm Hash digest
SHA256 6fc1eb3101350d439dade31f7e81dc592d47bdeac42fce673b2445d868876f33
MD5 fec3a6188dd83e54c85488ba09c07889
BLAKE2b-256 b4a61be4c59336ac74c77a0c39445b1a8876ea244bd1d7515574a3ce22f52a64

See more details on using hashes here.

File details

Details for the file ophinode-0.0.1a10-py3-none-any.whl.

File metadata

  • Download URL: ophinode-0.0.1a10-py3-none-any.whl
  • Upload date:
  • Size: 35.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for ophinode-0.0.1a10-py3-none-any.whl
Algorithm Hash digest
SHA256 51cec526fd23556114a44fcc4db13118a853831b669b24c1aaa52faf5495a26d
MD5 40b98ac45206a2c0d4718bde31e1e1ff
BLAKE2b-256 a9f4c6356386ef676e48ec77d120c56b833d7dd1ffd590b1f6524f47fc7ce5b7

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