emails: Inline CSS in emails in build_email.

Previously, we had an architecture where CSS inlining for emails was
done at provision time in inline_email_css.py. This was necessary
because the library we were using for this, Premailer, was extremely
slow, and doing the inlining for every outgoing email would have been
prohibitively expensive.

Now that we've migrated to a more modern library that inlines the
small amount of CSS we have into emails nearly instantly, we are able
to remove the complex architecture built to work around Premailer
being slow and just do the CSS inlining as the final step in sending
each individual email.

This has several significant benefits:

* Removes a fiddly provisioning step that made the edit/refresh cycle
  for modifying email templates confusing; there's no longer a CSS
  inlining step that, if you forget to do it, results in your testing a
  stale variant of the email templates.
* Fixes internationalization problems related to translators working
  with pre-CSS-inlined emails, and then Django trying to apply the
  translators to the post-CSS-inlined version.
* Makes the send_custom_email pipeline simpler and easier to improve.

Signed-off-by: Daniil Fadeev <fadeevd@zulip.com>
This commit is contained in:
Daniil Fadeev
2023-04-05 13:19:58 +04:00
committed by Tim Abbott
parent 7202a98438
commit 2f203f4de1
33 changed files with 91 additions and 214 deletions

View File

@@ -109,7 +109,7 @@ echo "$version" >version
cd "$OUTPUT_DIR"
tar --append -f "$TARBALL" "$prefix/prod-static" "$prefix/build_id" "$prefix/version" "$prefix/zulip-git-version" "$prefix/locale" "$prefix/staticfiles.json" "$prefix/templates/zerver/emails/compiled" "$prefix/webpack-stats-production.json"
tar --append -f "$TARBALL" "$prefix/prod-static" "$prefix/build_id" "$prefix/version" "$prefix/zulip-git-version" "$prefix/locale" "$prefix/staticfiles.json" "$prefix/webpack-stats-production.json"
rm -rf "$prefix"

View File

@@ -23,7 +23,7 @@ EXCLUDED_FILES = [
## Test data Files for testing modules in tests
"tools/tests/test_template_data",
# Our parser doesn't handle the way its conditionals are layered
"templates/zerver/emails/missed_message.source.html",
"templates/zerver/emails/missed_message.html",
# Previously unchecked and our parser doesn't like its indentation
"web/images/icons/template.hbs",
# Template checker recommends very hard to read indentation.

View File

@@ -72,15 +72,6 @@ def compilemessages_paths() -> List[str]:
return paths
def inline_email_css_paths() -> List[str]:
paths = [
"scripts/setup/inline_email_css.py",
"templates/zerver/emails/email.css",
]
paths += glob.glob("templates/zerver/emails/*.source.html")
return paths
def configure_rabbitmq_paths() -> List[str]:
paths = [
"scripts/setup/configure-rabbitmq",
@@ -180,16 +171,6 @@ def need_to_run_compilemessages() -> bool:
)
def need_to_run_inline_email_css() -> bool:
if not os.path.exists("templates/zerver/emails/compiled/"):
return True
return is_digest_obsolete(
"last_email_source_files_hash",
inline_email_css_paths(),
)
def need_to_run_configure_rabbitmq(settings_list: List[str]) -> bool:
obsolete = is_digest_obsolete(
"last_configure_rabbitmq_hash",
@@ -246,15 +227,6 @@ def main(options: argparse.Namespace) -> int:
else:
print("No need to run `tools/setup/build_timezone_values`.")
if options.is_force or need_to_run_inline_email_css():
run(["scripts/setup/inline_email_css.py"])
write_new_digest(
"last_email_source_files_hash",
inline_email_css_paths(),
)
else:
print("No need to run `scripts/setup/inline_email_css.py`.")
if not options.is_build_release_tarball_only:
# The following block is skipped when we just need the development
# environment to build a release tarball.

View File

@@ -33,9 +33,6 @@ setup_node_modules(production=True)
# Build emoji
run(["./tools/setup/emoji/build_emoji"])
# Inline CSS in emails
run(["./scripts/setup/inline_email_css.py"])
# Copy over static files from the zulip_bots package
run(["./tools/setup/generate_zulip_bots_static_files.py"])