Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Publishes the landing page to GitHub Pages whenever it changes on main.
# The site is the same template `/` serves locally, rendered without Django
# by scripts/build_landing_site.py.

name: Pages

on:
push:
branches: [main]
paths:
- src/templates/landing/**
- src/static/vendor/**
- scripts/build_landing_site.py
- .github/workflows/pages.yml
workflow_dispatch:

concurrency:
group: pages
cancel-in-progress: false

permissions: {}

jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
- uses: actions/configure-pages@v5
- run: python3 scripts/build_landing_site.py _site
- uses: actions/upload-pages-artifact@v4
with:
path: _site

deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ staticfiles/

# The example project, rebuilt on demand by examples/build.py.
examples/.build/

# Static landing page built for GitHub Pages
_site/
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project
follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.2.1] - 2026-11-30

### Added

- **A landing page.** In this repository, `/` now serves a page with a Three.js network globe, the opt-in
apps, the login methods, the four transports, a quick start and an FAQ. Three.js
0.170.0 is vendored under `src/static/vendor/three` rather than loaded from a CDN,
and `STATICFILES_DIRS` now includes `src/static`.
- **The landing page on GitHub Pages.** `scripts/build_landing_site.py` renders the
same template without Django, and `.github/workflows/pages.yml` deploys it from
`main` to <https://ctrlaltdevelop.github.io/django-ninja-starter/>.

## [2.2.0] - 2026-11-26

### Added
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ installed, and an environment badge so nobody edits production by mistake.
**[Read the documentation](docs/README.md)** — one page per app, covering its routes,
models, admin, setup and usage.

**[See the landing page](https://ctrlaltdevelop.github.io/django-ninja-starter/)** — a
one-page tour with a Three.js globe, published on GitHub Pages. This repository serves
the same page at `/`; its source is
[`src/templates/landing/index.html`](src/templates/landing/index.html). Generated
projects do not include it.

## Requirements

- Python 3.12 or newer
Expand Down
68 changes: 68 additions & 0 deletions scripts/build_landing_site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""Build the landing page as a static site for GitHub Pages.

The page is a Django template only so that `/` can serve it locally. This renders
the same file without Django: it resolves the one `{% static %}` tag, copies the
vendored Three.js beside it, and points the links that need a running project
(the API docs, the admin, GraphQL) at the documentation instead, since a static
host has none of those routes.

python scripts/build_landing_site.py [output-dir] # default: _site
"""

from __future__ import annotations

import re
import shutil
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
TEMPLATE = ROOT / "src" / "templates" / "landing" / "index.html"
VENDOR = ROOT / "src" / "static" / "vendor"
REPO = "https://github.com/CtrlAltDevelop/django-ninja-starter"
DOCS = f"{REPO}/tree/main/docs"

# Routes that exist only in a running project, and where the static site sends them.
LINK_REWRITES = {
"/": "./",
"/api/docs": f"{DOCS}/README.md",
"/api/redoc": f"{DOCS}/README.md",
"/graphql": f"{DOCS}/README.md",
"/admin/": f"{DOCS}/admin.md",
}

LOAD_STATIC = re.compile(r"\{%\s*load static\s*%\}")
STATIC_TAG = re.compile(r"\{%\s*static\s+'([^']+)'\s*%\}")
HREF = re.compile(r'href="([^"]*)"')


def render(source: str) -> str:
html = LOAD_STATIC.sub("", source)
html = STATIC_TAG.sub(lambda match: f"./{match.group(1)}", html)
html = HREF.sub(
lambda match: f'href="{LINK_REWRITES.get(match.group(1), match.group(1))}"', html
)
leftover = re.search(r"\{[%{#]", html)
if leftover:
raise SystemExit(
f"Unrendered template syntax near: {html[leftover.start() : leftover.start() + 60]!r}"
)
return html


def build(output: Path) -> None:
if output.exists():
shutil.rmtree(output)
output.mkdir(parents=True)
(output / "index.html").write_text(
render(TEMPLATE.read_text(encoding="utf-8")), encoding="utf-8"
)
shutil.copytree(VENDOR, output / "vendor")
# Pages would otherwise run Jekyll over the output, which has no use here.
(output / ".nojekyll").touch()


if __name__ == "__main__":
target = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / "_site"
build(target)
print(f"Built {target}")
3 changes: 3 additions & 0 deletions src/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,9 @@ def app_transports(app: str, published: tuple[str, ...]) -> tuple[str, ...]:

STATIC_URL = "static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
# Files that ship with the project itself, such as the landing page's vendored
# Three.js. Apps keep finding their own `static/` directories as before.
STATICFILES_DIRS = [BASE_DIR / "src" / "static"]
# Uploaded files, as opposed to files that ship with the code. Settings rather
# than constants because the two differ per deployment more than almost anything
# else here: a container mounts a volume, a platform points MEDIA_URL at a CDN,
Expand Down
2 changes: 2 additions & 0 deletions src/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.http import Http404, HttpRequest, HttpResponse
from django.urls import path
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView
from ninja.openapi.docs import Redoc
from strawberry.django.views import AsyncGraphQLView

Expand Down Expand Up @@ -34,6 +35,7 @@ def api_redoc(request: HttpRequest, version: str = "") -> HttpResponse:


urlpatterns = [
path("", TemplateView.as_view(template_name="landing/index.html"), name="landing"),
path("admin/", admin.site.urls),
path("api/docs", api_docs, name="api-docs"),
path("api/redoc", api_redoc, name="api-redoc"),
Expand Down
2 changes: 1 addition & 1 deletion src/django_ninja_starter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Django Ninja Starter project generator."""

__version__ = "2.2.0"
__version__ = "2.2.1"
21 changes: 21 additions & 0 deletions src/static/vendor/three/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright © 2010-2024 three.js authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
6 changes: 6 additions & 0 deletions src/static/vendor/three/three.module.min.js

Large diffs are not rendered by default.

Loading