Repos / pytaku / ff20e51f8c
commit ff20e51f8c178bf981d80aa3737bf31a1059a506
Author: Bùi Thành Nhân <hi@imnhan.com>
Date: Sat Oct 2 18:07:53 2021 +0700
implement pytaku-collect-static command
diff --git a/.builds/debian.yml b/.builds/debian.yml
index 1ef3eaa..6cf7d0b 100644
--- a/.builds/debian.yml
+++ b/.builds/debian.yml
@@ -69,7 +69,8 @@ tasks:
cd ~/pytaku &&
~/.local/bin/pytaku-migrate &&
rm -r static &&
- cp -r ~/.local/lib/python3.9/site-packages/pytaku/static ./ &&
+ ~/.local/bin/pytaku-collect-static . &&
+ tree ./static &&
sudo systemctl restart pytaku pytaku-scheduler &&
echo 'All done.'
"
diff --git a/README.md b/README.md
index bef92b9..a9e50ee 100644
--- a/README.md
+++ b/README.md
@@ -127,6 +127,21 @@ # then restart `pytaku` & `pytaku-scheduler` processes
network and let them worry about access control and end-to-end encryption for
you.
+## Optional optimization
+
+With the setup above, you're serving static assets using gunicorn, which is not
+ideal performance-wise. For private usage this doesn't really matter. However,
+if you want to properly serve static assets using nginx and the like, you can
+copy all static assets into a designated directory with:
+
+```sh
+pytaku-collect-static target_dir
+```
+
+This will copy all assets into `target_dir/static`. You can now instruct
+nginx/caddy/etc. to serve this dir on `/static/*` paths. There's an example
+caddyfile to do this in the ./contrib/ dir.
+
# LICENSE
Copyright (C) 2021 Bùi Thành Nhân
diff --git a/pyproject.toml b/pyproject.toml
index 1687773..64257ac 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pytaku"
-version = "0.5.2"
+version = "0.6.0"
description = "Self-hostable web-based manga reader"
authors = ["Bùi Thành Nhân <hi@imnhan.com>"]
license = "AGPL-3.0-only"
@@ -18,6 +18,7 @@ pytaku-dev = "pytaku:dev"
pytaku-migrate = "pytaku:migrate"
pytaku-generate-config = "pytaku:generate_config"
pytaku-scheduler = "pytaku:scheduler"
+pytaku-collect-static = "pytaku:collect_static"
[tool.poetry.dependencies]
python = "^3.7"
diff --git a/src/pytaku/__init__.py b/src/pytaku/__init__.py
index c3c9882..c35f53b 100644
--- a/src/pytaku/__init__.py
+++ b/src/pytaku/__init__.py
@@ -60,3 +60,22 @@ def scheduler():
from .scheduler import main_loop
main_loop()
+
+
+def collect_static():
+ from sys import argv
+
+ if len(argv) != 2:
+ print("Usage: pytaku-collect-static path/to/static/dir")
+ print("A 'static' dir will be created inside the provided path.")
+ exit(1)
+
+ import importlib.resources
+ from pathlib import Path
+ from shutil import copytree
+
+ destination = Path(argv[1]) / "static"
+
+ with importlib.resources.path("pytaku", "__init__.py") as pytaku_path:
+ copytree(pytaku_path.parent / "static", destination)
+ print(f"Static files copied to {destination}")