Skip to content

Commit 62812c2

Browse files
committed
Convert to newer httk-web
1 parent f85407e commit 62812c2

23 files changed

Lines changed: 248 additions & 150 deletions

.github/workflows/httkweb.yaml

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,49 @@
11
name: httkweb
22

33
on:
4-
# Runs on pushes targeting the default branch
54
push:
65
branches: ["main"]
7-
8-
# Allows you to run this workflow manually from the Actions tab
96
workflow_dispatch:
107

11-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
128
permissions:
139
contents: read
1410
pages: write
1511
id-token: write
1612

17-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
18-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
1913
concurrency:
2014
group: "pages"
2115
cancel-in-progress: false
2216

23-
# Default to bash
2417
defaults:
2518
run:
2619
shell: bash
2720

2821
jobs:
29-
# Build job
3022
build:
3123
runs-on: ubuntu-latest
3224
steps:
33-
- name: Install dependencies
34-
run: |
35-
sudo apt-get update
36-
sudo apt-get install python3 python3-yaml python3-jsonschema python3-markdown python3-mdx-math python3-pygments python3-docutils
3725
- name: Checkout
38-
uses: actions/checkout@v3
39-
with:
40-
submodules: recursive
41-
path: web
42-
- name: Checkout httk
43-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
27+
28+
- name: Setup Python
29+
uses: actions/setup-python@v5
4430
with:
45-
repository: httk/httk
46-
ref: devel
47-
path: httk
31+
python-version: "3.11"
32+
33+
- name: Install project
34+
run: |
35+
python -m pip install --upgrade pip
36+
python -m pip install .
37+
4838
- name: Generate website
4939
run: |
50-
export PYTHONPATH=$PWD/httk/src:$PYTHONPATH
51-
export PATH=$PWD/httk/bin:$PATH
52-
cd web
53-
python3 ./publish_static.py
54-
cd ..
40+
make generate
41+
5542
- name: Upload artifact
56-
uses: actions/upload-pages-artifact@v2
43+
uses: actions/upload-pages-artifact@v3
5744
with:
58-
path: web/public
59-
# Deployment job
45+
path: public
46+
6047
deploy:
6148
environment:
6249
name: github-pages
@@ -66,4 +53,4 @@ jobs:
6653
steps:
6754
- name: Deploy to GitHub Pages
6855
id: deployment
69-
uses: actions/deploy-pages@v2
56+
uses: actions/deploy-pages@v4

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
PYTHON ?= python3
2+
3+
.PHONY: docs docs-live docs-clean clean format format-check typecheck typecheck_pyright lint test test_fastfail audit
4+
5+
serve:
6+
python3 ./serve_dynamic.py
7+
8+
generate:
9+
python3 ./publish_static.py
10+
11+
serve_static:
12+
echo "Open:"
13+
echo "* http://localhost:8000/index.html"
14+
cd public && python3 -m http.server
15+
16+
clean:
17+
find . -name "*.pyc" -print0 | xargs -0 rm -f
18+
find . -name "*~" -print0 | xargs -0 rm -f
19+
find . -name "__pycache__" -print0 | xargs -0 rm -rf
20+
21+
format:
22+
$(PYTHON) -m ruff check src examples --select F401 --fix
23+
$(PYTHON) -m isort src
24+
$(PYTHON) -m black src
25+
26+
format-check:
27+
$(PYTHON) -m isort --check-only src
28+
$(PYTHON) -m black --check src
29+
30+
lint:
31+
$(PYTHON) -m ruff check src
32+
33+
typecheck_pyright:
34+
$(PYTHON) -m pyright
35+
36+
typecheck:
37+
$(PYTHON) -m mypy
38+
39+
test:
40+
$(PYTHON) -m pytest
41+
42+
test_fastfail:
43+
$(PYTHON) -m pytest -q -x
44+
45+
ci: format-check lint typecheck test_fastfail

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
httk example website
2-
--------------------
1+
Example Website With httk.web
2+
-----------------------------
33

4-
This repository is a simple example how to set up a website with a blog using the httkweb site generator.
4+
This repository is a simple example of how to set up a website with a blog using
5+
``httk.web`` from ``httk-web``.
56

6-
Fork this repository, edit the contents under `src/content` and if you keep it on GitHub, edit the configuration to turn on "GitHub Pages" using "GitHub Actions" and the attached workflow in `.github/actions/httkweb.yaml` should automatically generate and publish the website.
7+
Fork this repository, edit the content under ``src/content``, and if you keep it
8+
on GitHub, enable GitHub Pages using GitHub Actions. The workflow in
9+
``.github/workflows/httkweb.yaml`` generates and publishes the website.

publish_static.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

3-
import os, shutil, sys
3+
from pathlib import Path
44

5-
from httk.httkweb import publish
5+
from httk.web import publish
66

7-
if not os.path.exists("public"):
8-
os.mkdir("public")
9-
10-
for filename in os.listdir("public"):
11-
if not filename.startswith("."):
12-
f = os.path.join("public",filename)
13-
if os.path.isdir(f):
14-
shutil.rmtree(f)
15-
else:
16-
os.unlink(f)
17-
18-
publish("src","public",'http://127.0.0.1/')
19-
20-
sys.stdout.write("*****\nNow open public/index.html in your web browser.\n*****\n")
7+
ROOT = Path(__file__).parent
8+
publish(ROOT / "src", ROOT / "public", "http://127.0.0.1/")
219

10+
print("*****\nNow open public/index.html in your web browser.\n*****")

pyproject.toml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[build-system]
2+
requires = ["setuptools>=68", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "example_website_httk"
7+
version = "0.1.0"
8+
description = "Example of how to use httk as a static site generator (that can be extended with a backend)."
9+
readme = "README.md"
10+
license = "AGPL-3.0+"
11+
requires-python = ">=3.11"
12+
authors = [{ name = "Rickard Armiento", email = "gitcommits@armiento.net" }]
13+
dependencies = [
14+
"httk-web @ git+https://github.com/httk/httk-web",
15+
]
16+
classifiers = [
17+
"Operating System :: OS Independent",
18+
"Programming Language :: Python",
19+
]
20+
[project.optional-dependencies]
21+
dev = [
22+
"pytest>=8.0",
23+
"httpx>=0.27",
24+
"black",
25+
"ruff",
26+
"isort",
27+
"pyright",
28+
"mypy"
29+
]
30+
31+
[tool.setuptools]
32+
package-dir = {"" = "src"}
33+
34+
[tool.setuptools.packages.find]
35+
where = ["src"]
36+
37+
[tool.pytest.ini_options]
38+
testpaths = ["tests"]
39+
40+
[tool.isort]
41+
profile = "black"
42+
43+
[tool.ruff]
44+
target-version = "py311"
45+
src = ["src"]
46+
47+
[tool.black]
48+
target-version = ["py311"]
49+
line-length = 120
50+
skip-string-normalization = true
51+
52+
[tool.pyright]
53+
pythonVersion = "3.11"
54+
include = ["src", "serve_dynamic.py", "publish_static.py"]
55+
extraPaths = ["src"]
56+
reportMissingImports = true
57+
58+
[tool.mypy]
59+
python_version = "3.11"
60+
files = ["src", "serve_dynamic.py", "publish_static.py"]
61+
mypy_path = ["src"]
62+
namespace_packages = true
63+
explicit_package_bases = true
64+
warn_unused_ignores = true
65+
66+
[[tool.mypy.overrides]]
67+
module = ["yaml", "markdown", "docutils", "docutils.*", "httk.web", "httk.web.*"]
68+
ignore_missing_imports = true

serve_dynamic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/usr/bin/env python3
22

3-
from httk.httkweb import serve
3+
from pathlib import Path
44

5-
serve("src", port=8080, config="config_dynamic")
5+
from httk.web import serve
6+
7+
ROOT = Path(__file__).parent
8+
serve(ROOT / "src", port=8080, config_name="config_dynamic")

src/content/404.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
Title: My Website - Missing page
3-
Name: "404"
4-
Template: "404"
2+
title: My Website - Missing page
3+
name: "404"
4+
template: "404"
55
---
66
The page could not be found.

src/content/blog.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
--------
2-
Title: My Website - Blog posts
3-
Name: Blog
4-
Template: blog
5-
Base_template: base_default
6-
--------
1+
---
2+
title: My Website - Blog posts
3+
name: Blog
4+
template: blog
5+
base_template: base_default
6+
---
77

88
Blog
99
====
1010

1111
Below is a list of all blog posts available here.
12-

src/content/blogposts/another_post.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
--------
2-
Title: My Website - Another post
3-
Author: Rickard Armiento
4-
Date: 2023-10-04
5-
Name: Another post
6-
Template: blogpost
7-
Base_template: base_default
8-
--------
1+
---
2+
title: My Website - Another post
3+
author: Rickard Armiento
4+
date: 2023-10-04
5+
name: Another post
6+
template: blogpost
7+
base_template: base_default
8+
---
99

1010
Another post
1111
============

src/content/blogposts/hello-everyone.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
--------
2-
Title: My Website - Hello Everyone
3-
Author: Rickard Armiento
4-
Date: 2023-10-03
5-
Name: Hello Everyone
6-
Template: blogpost
7-
Base_template: base_default
8-
--------
1+
---
2+
title: My Website - Hello Everyone
3+
author: Rickard Armiento
4+
date: 2023-10-03
5+
name: Hello Everyone
6+
template: blogpost
7+
base_template: base_default
8+
---
99

1010
Hello everyone
1111
==============

0 commit comments

Comments
 (0)