Skip to content

Commit 23ee908

Browse files
committed
www: introduce www_folder config item
fix #529
1 parent bedfc09 commit 23ee908

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## untagged
44

5+
- Make www upload path configurable
6+
([#618](https://github.com/chatmail/relay/pull/618))
7+
58
- Allow custom nginx config files
69
([#617](https://github.com/chatmail/relay/pull/617))
710

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,16 @@ This starts a local live development cycle for chatmail web pages:
257257

258258
#### Custom web pages
259259

260-
If you want to include other pages,
260+
You can skip uploading a web page
261+
by setting `www_folder=disabled` in `chatmail.ini`.
262+
263+
If you want to manage your web pages outside this git repository,
264+
you can set `www_folder` in `chatmail.ini` to a custom directory.
265+
`cmdeploy run` will upload it as the server's home page,
266+
and if it contains a `src/index.md` file,
267+
will build it with hugo.
268+
269+
If you want to include existing web pages,
261270
they need their separate nginx config
262271
under `/etc/nginx/sites-enabled/`.
263272
Note that they need to listen on port 8443 instead of 443.

chatmaild/src/chatmaild/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, inipath, params):
3333
self.password_min_length = int(params["password_min_length"])
3434
self.passthrough_senders = params["passthrough_senders"].split()
3535
self.passthrough_recipients = params["passthrough_recipients"].split()
36+
self.www_folder = params.get("www_folder")
3637
self.filtermail_smtp_port = int(params["filtermail_smtp_port"])
3738
self.filtermail_smtp_port_incoming = int(
3839
params["filtermail_smtp_port_incoming"]

cmdeploy/src/cmdeploy/__init__.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pathlib import Path
1212

1313
from chatmaild.config import Config, read_config
14-
from pyinfra import facts, host
14+
from pyinfra import facts, host, logger
1515
from pyinfra.api import FactBase
1616
from pyinfra.facts.files import File
1717
from pyinfra.facts.server import Sysctl
@@ -737,12 +737,24 @@ def deploy_chatmail(config_path: Path, disable_mail: bool) -> None:
737737
packages=["fcgiwrap"],
738738
)
739739

740-
www_path = importlib.resources.files(__package__).joinpath("../../../www").resolve()
741-
742-
build_dir = www_path.joinpath("build")
743-
src_dir = www_path.joinpath("src")
744-
build_webpages(src_dir, build_dir, config)
745-
files.rsync(f"{build_dir}/", "/var/www/html", flags=["-avz"])
740+
reporoot = importlib.resources.files(__package__).joinpath("../../../").resolve()
741+
www_path = Path(config.www_folder)
742+
# if www_folder was not set, use default directory
743+
if not config.www_folder:
744+
www_path = reporoot.joinpath("www")
745+
# if www_folder was set to a non-existing folder, skip upload
746+
if not www_path.is_dir():
747+
logger.warning("Building web pages is disabled in chatmail.ini, skipping")
748+
else:
749+
build_dir = www_path.joinpath("build")
750+
src_dir = www_path.joinpath("src")
751+
# if www_folder is a hugo page, build it
752+
if src_dir.joinpath("index.md").is_file():
753+
build_webpages(src_dir, build_dir, config)
754+
# if it is not a hugo page, upload it as is
755+
else:
756+
build_dir = www_path
757+
files.rsync(f"{build_dir}/", "/var/www/html", flags=["-avz"])
746758

747759
_install_remote_venv_with_chatmaild(config)
748760
debug = False

cmdeploy/src/cmdeploy/www.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import time
44
import traceback
55
import webbrowser
6+
from pathlib import Path
67

78
import markdown
89
from chatmaild.config import read_config
@@ -106,7 +107,9 @@ def main():
106107
config = read_config(inipath)
107108
config.webdev = True
108109
assert config.mail_domain
109-
www_path = reporoot.joinpath("www")
110+
www_path = Path(config.www_folder)
111+
if not config.www_folder:
112+
www_path = reporoot.joinpath("www")
110113
src_path = www_path.joinpath("src")
111114
stats = None
112115
build_dir = www_path.joinpath("build")

0 commit comments

Comments
 (0)