From 3a4f4777b33d5cf113cbd4e6513593ec055a7360 Mon Sep 17 00:00:00 2001 From: Brandon Krigbaum Date: Mon, 11 Nov 2024 10:00:11 -0600 Subject: [PATCH] Add newsletter stealth link component --- packages/marko-newsletters/components/marko.json | 3 +++ .../components/stealth-link.marko | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/marko-newsletters/components/stealth-link.marko diff --git a/packages/marko-newsletters/components/marko.json b/packages/marko-newsletters/components/marko.json index 92b73b256..e9449eabd 100644 --- a/packages/marko-newsletters/components/marko.json +++ b/packages/marko-newsletters/components/marko.json @@ -22,5 +22,8 @@ "@title": "string", "@description": "string", "@date": "object" + }, + "": { + "template": "./stealth-link.marko" } } diff --git a/packages/marko-newsletters/components/stealth-link.marko b/packages/marko-newsletters/components/stealth-link.marko new file mode 100644 index 000000000..bd0fe4b2c --- /dev/null +++ b/packages/marko-newsletters/components/stealth-link.marko @@ -0,0 +1,15 @@ +import { get } from "@parameter1/base-cms-object-path"; +import defaultValue from "@parameter1/base-cms-marko-core/utils/default-value"; +import moment from "moment"; + +$ const { newsletter, date } = input; + +$ const newsletterSiteName = get(newsletter, "site.name") || "Homepage"; +$ const linkText = defaultValue(input.linkText, newsletterSiteName); +$ const unixTimestamp = moment(date).unix(); +$ const position = defaultValue(input.position, "top"); +$ const linkUrl = `${newsletter.site.origin}/email-preview?newsletterId=${newsletter.id}×tamp=${unixTimestamp}&position=${position}`; + +
+ ${linkText} +