From ffbda019e4dc0a96179f69da2bc8391ba8d9d43f Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Fri, 18 Apr 2025 16:05:53 +0530 Subject: [PATCH] Add sample visual campaign template on install and upgrade. --- cmd/install.go | 14 +++++ internal/migrations/v5.0.0.go | 15 +++++ static/email-templates/default-visual.json | 66 ++++++++++++++++++++++ static/email-templates/default-visual.tpl | 37 ++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 static/email-templates/default-visual.json create mode 100644 static/email-templates/default-visual.tpl diff --git a/cmd/install.go b/cmd/install.go index 640bfb9c..46c1c05d 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -221,6 +221,20 @@ func installTemplates(q *models.Queries) (int, int) { lo.Fatalf("error creating sample transactional template: %v", err) } + // Sample visual campaign template. + visualTpl, err := fs.Get("/static/email-templates/default-visual.tpl") + if err != nil { + lo.Fatalf("error reading default visual template: %v", err) + } + visualSrc, err := fs.Get("/static/email-templates/default-visual.json") + if err != nil { + lo.Fatalf("error reading default visual template json: %v", err) + } + + if err := q.CreateTemplate.Get(&campTplID, "Sample visual template", models.TemplateTypeCampaignVisual, "", visualTpl.ReadBytes(), visualSrc.ReadBytes()); err != nil { + lo.Fatalf("error creating default campaign template: %v", err) + } + return campTplID, archiveTplID } diff --git a/internal/migrations/v5.0.0.go b/internal/migrations/v5.0.0.go index b0c8e00f..47ac89c2 100644 --- a/internal/migrations/v5.0.0.go +++ b/internal/migrations/v5.0.0.go @@ -74,5 +74,20 @@ func V5_0_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf, lo *log.Logger return err } + // Insert visual campaign template. + visualTpl, err := fs.Get("/static/email-templates/default-visual.tpl") + if err != nil { + lo.Fatalf("error reading default visual template: %v", err) + } + visualSrc, err := fs.Get("/static/email-templates/default-visual.json") + if err != nil { + lo.Fatalf("error reading default visual template json: %v", err) + } + + if _, err := db.Exec(`INSERT INTO templates (name, type, subject, body, body_source) VALUES($1, $2, $3, $4, $5)`, + "Sample visual template", "campaign_visual", "", visualTpl.ReadBytes(), visualSrc.ReadBytes()); err != nil { + return err + } + return nil } diff --git a/static/email-templates/default-visual.json b/static/email-templates/default-visual.json new file mode 100644 index 00000000..6b098888 --- /dev/null +++ b/static/email-templates/default-visual.json @@ -0,0 +1,66 @@ +{ + "root": { + "type": "EmailLayout", + "data": { + "backdropColor": "#F5F5F5", + "canvasColor": "#FFFFFF", + "textColor": "#262626", + "fontFamily": "MODERN_SANS", + "childrenIds": [ + "block-1744970939431", + "block-1744970976991", + "block-1744971036169", + "block-1744971054197" + ] + } + }, + "block-1744970939431": { + "type": "Heading", + "data": { + "props": { + "text": "Hello {{ .Subscriber.Name }}", + "level": "h3" + }, + "style": { + "padding": { "top": 16, "bottom": 16, "right": 24, "left": 24 } + } + } + }, + "block-1744970976991": { + "type": "Text", + "data": { + "style": { + "fontWeight": "normal", + "padding": { "top": 16, "bottom": 16, "right": 24, "left": 24 } + }, + "props": { + "markdown": true, + "text": "This is a test e-mail campaign. Your second name is {{ .Subscriber.LastName }} and this block of text is in Markdown.\n\nHere is a [tracked link](https://listmonk.app@TrackLink).\n\nUse the link icon in the editor toolbar or when writing raw HTML or Markdown, simply suffix @TrackLink to the end of a URL to turn it into a tracking link. Example:\n\n\n\nFor help, refer to the [documentation](https://listmonk.app/docs)." + } + } + }, + "block-1744971036169": { + "type": "Divider", + "data": { + "style": { + "padding": { "top": 16,"right": 0, "bottom": 16, "left": 0 } + }, + "props": { + "lineColor": "#CCCCCC" + } + } + }, + "block-1744971054197": { + "type": "Button", + "data": { + "style": { + "padding": { "top": 16, "bottom": 16, "right": 24, "left": 24 } + }, + "props": { + "buttonBackgroundColor": "#2563EB", + "text": "This is a button", + "url": "https://listmonk.app" + } + } + } +} diff --git a/static/email-templates/default-visual.tpl b/static/email-templates/default-visual.tpl new file mode 100644 index 00000000..a44e319a --- /dev/null +++ b/static/email-templates/default-visual.tpl @@ -0,0 +1,37 @@ + + + +
+ + + + + + +
+

Hello {{ .Subscriber.Name }}

+
+

This is a test e-mail campaign. Your second name is {{ .Subscriber.LastName }} and this block of text is in Markdown.

+

Here is a tracked link.

+

Use the link icon in the editor toolbar or when writing raw HTML or Markdown, simply suffix @TrackLink to the end of a URL to turn it into a tracking link. Example:

+

+

For help, refer to the documentation.

+
+
+
+
+ +
+
+ +