Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Add `viewport` meta tag to visual builder default template. Closes #2751.

Kailash Nadh576309d9236f
diff --git a/frontend/email-builder/src/App/TemplatePanel/HtmlPanel.tsx b/frontend/email-builder/src/App/TemplatePanel/HtmlPanel.tsx
index a0ab3520..d375a708 100644
--- a/frontend/email-builder/src/App/TemplatePanel/HtmlPanel.tsx
+++ b/frontend/email-builder/src/App/TemplatePanel/HtmlPanel.tsx
@@ -1,13 +1,12 @@
import React, { useMemo } from 'react';
-import { renderToStaticMarkup } from '@usewaypoint/email-builder';
-
import { useDocument } from '../../documents/editor/EditorContext';
+import { renderHtmlWithMeta } from '../../utils';
import HighlightedCodePanel from './helper/HighlightedCodePanel';
export default function HtmlPanel() {
const document = useDocument();
- const code = useMemo(() => renderToStaticMarkup(document, { rootBlockId: 'root' }), [document]);
+ const code = useMemo(() => renderHtmlWithMeta(document, { rootBlockId: 'root' }), [document]);
return <HighlightedCodePanel type="html" value={code} />;
}
diff --git a/frontend/email-builder/src/App/index.tsx b/frontend/email-builder/src/App/index.tsx
index b5dbe7ed..65afae4b 100644
--- a/frontend/email-builder/src/App/index.tsx
+++ b/frontend/email-builder/src/App/index.tsx
@@ -1,9 +1,9 @@
-import React from 'react';
import { Stack, useTheme } from '@mui/material';
-import { renderToStaticMarkup } from '@usewaypoint/email-builder';
+import React from 'react';
import { TEditorConfiguration } from '../documents/editor/core';
-import { useInspectorDrawerOpen, useSamplesDrawerOpen, subscribeDocument, setDocument } from '../documents/editor/EditorContext';
+import { setDocument, subscribeDocument, useInspectorDrawerOpen, useSamplesDrawerOpen } from '../documents/editor/EditorContext';
+import { renderHtmlWithMeta } from '../utils';
import InspectorDrawer, { INSPECTOR_DRAWER_WIDTH } from './InspectorDrawer';
import TemplatePanel from './TemplatePanel';
@@ -46,7 +46,7 @@ export default function App(props: AppProps) {
if (props.onChange) {
subscribeDocument ((document) => {
- props.onChange?.(document, renderToStaticMarkup(document, { rootBlockId: 'root' }))
+ props.onChange?.(document, renderHtmlWithMeta(document, { rootBlockId: 'root' }))
})
}
diff --git a/frontend/email-builder/src/utils.tsx b/frontend/email-builder/src/utils.tsx
new file mode 100644
index 00000000..c759493a
--- /dev/null
+++ b/frontend/email-builder/src/utils.tsx
@@ -0,0 +1,11 @@
+import { renderToStaticMarkup } from '@usewaypoint/email-builder';
+import { TEditorConfiguration } from './documents/editor/core';
+
+export function renderHtmlWithMeta(document: TEditorConfiguration, options: { rootBlockId: string }): string {
+ const html = renderToStaticMarkup(document, options);
+ // Insert <head> with viewport meta after <html>
+ return html.replace(
+ '<html>',
+ '<html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"></head>'
+ );
+}
diff --git a/static/email-templates/default-visual.tpl b/static/email-templates/default-visual.tpl
index 9f923f80..f432ced8 100644
--- a/static/email-templates/default-visual.tpl
+++ b/static/email-templates/default-visual.tpl
@@ -1,5 +1,8 @@
<!doctype html>
<html>
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ </head>
<body>
<div
style='background-color:#F5F5F5;color:#262626;font-family:"Helvetica Neue", "Arial Nova", "Nimbus Sans", Arial, sans-serif;font-size:16px;font-weight:400;letter-spacing:0.15008px;line-height:1.5;margin:0;padding:32px 0;min-height:100%;width:100%'