Skip to main content

A static site generator app for django

Project description

Run Cheap Static Site Generator (SSG)

This is a barebones django "app" (i.e. plugin) that you can use to generate static sites from your django views and templates.

I wrote this as an alternative to Jekyll for folks who are more used to using Django's template system.

How to use

First, install the django app (the only dependency is django).

python3 -m pip install runcheap-ssg

Next, add runcheap_ssg to your INSTALLED_APPS list in your settings.py. This enables management commands for building the static site and some helpful template filters.

INSTALLED_APPS = [
    ...
    "runcheap_ssg",
]

Next, update the views in your urls.py to use include_in_ssg.

from django.urls import path, re_path
from django.conf.urls.i18n import i18n_patterns
from django.views.generic.base import TemplateView
from runcheap_ssg.decorators import include_in_ssg
from my_website.views import landing_view, BlogEntryView, favicon_view, robots_view

# works with translated pages
i18n_urlpatterns = i18n_patterns(
    # works with simple views and default paths
    path("", include_in_ssg(landing_view), name="landing"),
    # works with class-based views and regex paths
    re_path(r"^about/$", include_in_ssg(TemplateView.as_view(template_name="about.html")), name="about"),
    # works with url parameters
    # (set parameters for each page to generate with `ssg_reverse_iter` kwarg)
    path(
        "blog/",
        include_in_ssg(
            TemplateView.as_view(template_name="about.html", extra_context={"entries": BlogEntryView.entries})
        ),
        name="blog_list",
    ),
    path(
        "blog/<slug:slug>/",
        include_in_ssg(
            BlogEntryView.as_view(),
            # generates one page per entry (i.e. `reverse("blog_entry", kwargs={"slug": "..."})`)
            ssg_reverse_iter=[{"kwargs": {"slug": entry["slug"]}} for entry in BlogEntryView.entries],
        ),
        name="blog_entry",
    ),
)

# works other types of pages
urlpatterns = i18n_urlpatterns + [
    # works with non-internationalized pages
    path("non-i18n/", include_in_ssg(TemplateView.as_view(template_name="non-i18n.html")), name="non-i18n"),
    # works with non-html files
    path("favicon.ico", include_in_ssg(favicon_view), name="favicon_ico"),
    # works with views that use @include_in_ssg decorator (so don't have to use it in the urls.py)
    path("robots.txt", robots_view, name="robots_txt"),
    # this view isn't wrapped by include_in_ssg(), so won't be included in the static build
    path("not-included/", TemplateView.as_view(template_name="not_included.html"), name="not_included"),
]

You can also use @include_in_ssg as a decorator in your views.

# ...in your myapp/views.py
from runcheap_ssg.decorators import include_in_ssg
...
@include_in_ssg
def robots_view(request):
    return FileResponse(open(finders.find("robots.txt"), "rb"))

Finally, you can generate your site as a set of static files using the built-in command (views that don't inherit from StaticTemplateView or StaticFileView are ignored).

python3 manage.py runcheap_ssg_build --output "_build"

Your static site is now rendered in ./_build/! Hooray!

Additionally, if you want to test your static site, there's a built-in server.

python3 manage.py runcheap_ssg_serve

Examples

Check out the examples folder of this repository to see example django projects that use Run Cheap SSG.

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

runcheap_ssg-1.0.4.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

runcheap_ssg-1.0.4-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file runcheap_ssg-1.0.4.tar.gz.

File metadata

  • Download URL: runcheap_ssg-1.0.4.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for runcheap_ssg-1.0.4.tar.gz
Algorithm Hash digest
SHA256 8678eb2b47909d8ef0e3a0ed92c7d229aaba7d1ef2fd9b8ba42f2565c2b306bf
MD5 6604b64dbb860f39b91536956d09dd37
BLAKE2b-256 811241ab11be6e078b50332eb2529f52808ff6ded37e6a7519ce844dd5cf9d70

See more details on using hashes here.

File details

Details for the file runcheap_ssg-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: runcheap_ssg-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for runcheap_ssg-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5f00942f1b4497ef099e0cf8d39ece37248362c5c2abf6497e2888f58a1bf606
MD5 74612f1933d7763329ccb22ee59f1be8
BLAKE2b-256 d971a528f81035d78642e5bef540d089ae4f7e410da2be56595589f7ed632633

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