mirror of
https://github.com/chatmail/relay.git
synced 2026-05-15 19:14:44 +00:00
create a wwwdev.sh entry point for helping live web design/development (#92)
* create a wwwdev.sh entry point for developing the web part * rename script * fix README * add a note * don't depend on deltachat python package * avoid bailing out on jinja2 errors, and provide file-url for instant clickability * in webdev mode make page auto-refresh every 3 seconds
This commit is contained in:
@@ -3,7 +3,6 @@ Chat Mail pyinfra deploy.
|
||||
"""
|
||||
import importlib.resources
|
||||
import configparser
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
|
||||
from pyinfra import host
|
||||
@@ -11,11 +10,6 @@ from pyinfra.operations import apt, files, server, systemd
|
||||
from pyinfra.facts.files import File
|
||||
from pyinfra.facts.systemd import SystemdEnabled
|
||||
from .acmetool import deploy_acmetool
|
||||
import markdown
|
||||
from jinja2 import Template
|
||||
|
||||
|
||||
from .genqr import gen_qr_png_data
|
||||
|
||||
|
||||
def _install_chatmaild() -> None:
|
||||
@@ -325,67 +319,6 @@ def get_ini_settings(mail_domain, inipath):
|
||||
return settings
|
||||
|
||||
|
||||
def build_htmlj2_from_markdown(source):
|
||||
assert source.exists(), source
|
||||
template_content = open(source).read()
|
||||
if source.stem == "privacy":
|
||||
title = "privacy {{ config.mail_domain }}"
|
||||
elif source.stem == "index":
|
||||
title = "home {{ config.mail_domain }}"
|
||||
elif source.stem == "info":
|
||||
title = "info {{ config.mail_domain }}"
|
||||
|
||||
html = markdown.markdown(template_content)
|
||||
html = (
|
||||
textwrap.dedent(
|
||||
f"""\
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>{title}</title>
|
||||
<link rel="stylesheet" href="./water.css">
|
||||
</head>
|
||||
<body>
|
||||
"""
|
||||
)
|
||||
+ html
|
||||
+ "\n"
|
||||
+ textwrap.dedent(
|
||||
"""\
|
||||
<footer>
|
||||
<a href="index.html">home</a> |
|
||||
<a href="info.html">more info</a> |
|
||||
<a href="privacy.html">privacy</a> |
|
||||
<a href="https://github.com/deltachat/chatmail">-> public development </a>
|
||||
</footer>
|
||||
</body>"""
|
||||
)
|
||||
)
|
||||
|
||||
target_path = source.with_name(source.stem + ".html.j2")
|
||||
with open(target_path, "w") as f:
|
||||
f.write(html)
|
||||
print(f"wrote {target_path}")
|
||||
return target_path
|
||||
|
||||
|
||||
def build_webpages(www_path, config):
|
||||
mail_domain = config["mail_domain"]
|
||||
qr_data = gen_qr_png_data(mail_domain).read()
|
||||
www_path.joinpath(f"qr-chatmail-invite-{mail_domain}.png").write_bytes(qr_data)
|
||||
|
||||
for path in www_path.iterdir():
|
||||
if path.suffix == ".md":
|
||||
path = build_htmlj2_from_markdown(path)
|
||||
|
||||
if path.suffix == ".j2":
|
||||
target = path.with_name(path.name[:-3])
|
||||
template = Template(path.read_text())
|
||||
with target.open("w") as f:
|
||||
f.write(template.render(config=config))
|
||||
|
||||
|
||||
def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> None:
|
||||
"""Deploy a chat-mail instance.
|
||||
|
||||
@@ -393,6 +326,7 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N
|
||||
:param mail_server: the DNS name under which your mail server is reachable
|
||||
:param dkim_selector:
|
||||
"""
|
||||
from .www import build_webpages
|
||||
|
||||
apt.update(name="apt update", cache_time=24 * 3600)
|
||||
server.group(name="Create vmail group", group="vmail", system=True)
|
||||
@@ -442,8 +376,10 @@ def deploy_chatmail(mail_domain: str, mail_server: str, dkim_selector: str) -> N
|
||||
config = get_ini_settings(mail_domain, chatmail_ini)
|
||||
www_path = pkg_root.joinpath("../../../www").resolve()
|
||||
|
||||
build_webpages(www_path, config)
|
||||
files.rsync(f"{www_path}/", "/var/www/html", flags=["-avz"])
|
||||
build_dir = www_path.joinpath("build")
|
||||
src_dir = www_path.joinpath("src")
|
||||
build_webpages(src_dir, build_dir, config)
|
||||
files.rsync(f"{build_dir}/", "/var/www/html", flags=["-avz"])
|
||||
|
||||
_install_chatmaild()
|
||||
debug = False
|
||||
|
||||
Reference in New Issue
Block a user