From 00170ca91292dd90b5cafd61bd0923d5156add8c Mon Sep 17 00:00:00 2001 From: Zaldimmar Date: Fri, 2 Oct 2026 00:43:28 -0500 Subject: [PATCH] Newsletter: social bar and event countdown parts, full-width builder - Social bar: a colored band of the site's platform icons, linked; no links added shows the footer's (src/data/socialLinks.ts, shared) - Icons are white and ink PNGs in public/email/, made from PlatformIcon.tsx by scripts/email-icons.mjs (no SVG in Gmail/Outlook) - Event countdown: a picture drawn by /api/countdown/.png when the email is opened (days, hours, minutes to local midnight in America/Chicago; then happening now; then over), with a fixed line under it as of copying - The builder takes the whole window (useWideAdminPage('full')) Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 1 + docs/updating-data-in-code.md | 2 +- public/email/discord-ink.png | Bin 0 -> 997 bytes public/email/discord-white.png | Bin 0 -> 838 bytes public/email/facebook-ink.png | Bin 0 -> 921 bytes public/email/facebook-white.png | Bin 0 -> 806 bytes public/email/instagram-ink.png | Bin 0 -> 1335 bytes public/email/instagram-white.png | Bin 0 -> 1173 bytes public/email/linkedin-ink.png | Bin 0 -> 608 bytes public/email/linkedin-white.png | Bin 0 -> 531 bytes public/email/spotify-ink.png | Bin 0 -> 1294 bytes public/email/spotify-white.png | Bin 0 -> 1091 bytes public/email/substack-ink.png | Bin 0 -> 445 bytes public/email/substack-white.png | Bin 0 -> 401 bytes public/email/tiktok-ink.png | Bin 0 -> 864 bytes public/email/tiktok-white.png | Bin 0 -> 746 bytes public/email/x-ink.png | Bin 0 -> 1159 bytes public/email/x-white.png | Bin 0 -> 1017 bytes public/email/youtube-ink.png | Bin 0 -> 622 bytes public/email/youtube-white.png | Bin 0 -> 522 bytes scripts/email-icons.mjs | 30 +++++++ server/src/index.js | 14 ++++ server/src/routes/countdown.js | 119 ++++++++++++++++++++++++++++ src/components/Footer.tsx | 9 +-- src/data/socialLinks.ts | 15 ++++ src/lib/adminWidth.tsx | 19 +++-- src/lib/newsletter.ts | 80 +++++++++++++++++++ src/pages/admin/AdminLayout.tsx | 13 +-- src/pages/admin/AdminNewsletter.tsx | 47 +++++++++-- 29 files changed, 322 insertions(+), 27 deletions(-) create mode 100644 public/email/discord-ink.png create mode 100644 public/email/discord-white.png create mode 100644 public/email/facebook-ink.png create mode 100644 public/email/facebook-white.png create mode 100644 public/email/instagram-ink.png create mode 100644 public/email/instagram-white.png create mode 100644 public/email/linkedin-ink.png create mode 100644 public/email/linkedin-white.png create mode 100644 public/email/spotify-ink.png create mode 100644 public/email/spotify-white.png create mode 100644 public/email/substack-ink.png create mode 100644 public/email/substack-white.png create mode 100644 public/email/tiktok-ink.png create mode 100644 public/email/tiktok-white.png create mode 100644 public/email/x-ink.png create mode 100644 public/email/x-white.png create mode 100644 public/email/youtube-ink.png create mode 100644 public/email/youtube-white.png create mode 100644 scripts/email-icons.mjs create mode 100644 server/src/routes/countdown.js create mode 100644 src/data/socialLinks.ts diff --git a/CLAUDE.md b/CLAUDE.md index 24281e0..3e95d37 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -34,6 +34,7 @@ In dev, Vite proxies `/api` to the target set in `vite.config.ts`, so the API mu - Uploaded media: `UPLOADS_DIR=/var/lib/ngu/uploads`, served by nginx at `/uploads/`. Setup and the nginx block are in `docs/media-uploads.md`. - Page HTML goes through the API, which fills in each page's title, description, preview image and structured data (`server/src/pageMeta.js`), and serves `/sitemap.xml`. It reads `SITE_CONFIG` (site.json) and `SITE_INDEX` (the built index.html), with Panel → Site settings (the `site_settings` table) laid over site.json, and serves `/robots.txt` from the same merge. nginx setup: `docs/seo.md`. - Video clips (Tools, admins and up): yt-dlp downloads our YouTube/Facebook videos into `CLIPS_DIR`, ffmpeg cuts them; one job at a time, files swept after a day (`server/src/clips.js`). Needs yt-dlp and ffmpeg on the VPS: `docs/video-clips.md`. +- Newsletter countdown pictures: `/api/countdown/:id.png` (`server/src/routes/countdown.js`), drawn with sharp when an email is opened; it uses the VPS's fonts, so install Poppins there (eg. into `/usr/local/share/fonts`, then `fc-cache`) or it falls back to a plain sans. The social bar's icons are static files in `public/email/`. - Word import: Blog posts → Import from Word turns a .docx into an unpublished post (headings, paragraphs, lists, tables, links); nginx needs a block for `/api/admin/import/docx` with an 11m body limit: `docs/importing.md`. - Speed: nginx must gzip JS/CSS/JSON/SVG and speak HTTP/2; page HTML is `no-cache`; uploads get a `-640.webp` small copy made at upload and at boot: `docs/performance.md`. - Security headers: the API sends them (Hono `secureHeaders()`, plus a CSRF check on `/api` writes); nginx sends HSTS on everything and must pass `Host` and `X-Forwarded-For` to the API: `docs/security-headers.md`. diff --git a/docs/updating-data-in-code.md b/docs/updating-data-in-code.md index e7e3e1d..2866be8 100644 --- a/docs/updating-data-in-code.md +++ b/docs/updating-data-in-code.md @@ -285,7 +285,7 @@ The numbers band's "Number Source" dropdown works the same way: | Organization kind labels ("Region", "Group") | the Kind options in `src/lib/adminSchema/organizations.ts` (admin); `orgListHref` in `src/lib/hrefs.ts` (the public back link, "All regions") | | | Admin account roles | `src/lib/roles.ts` (labels, notes) and `ROLES` in `server/src/auth.js` | Adding a role is also a CHECK change on `admin_users.role`. | | Admin navigation | `src/pages/admin/adminNav.ts` | | -| Newsletter parts and their defaults (Tools → Newsletter) | `PARTS_SPEC`, `PART_TYPES` and `STARTER` in `src/pages/admin/AdminNewsletter.tsx`; `PICK_DEFAULTS`, `DEFAULT_TITLE` and `COLOR` in `src/lib/newsletter.ts` | A draft is one JSON list of parts (`newsletters.layout`, 060), so adding a part or a setting needs no migration: a field in `PARTS_SPEC` and its drawing in `newsletter.ts`. The color choices are `PALETTE`; `COLOR` holds the defaults as hex, since an inbox has no theme tokens. `STARTER` is what a new draft starts with. | +| Newsletter parts and their defaults (Tools → Newsletter) | `PARTS_SPEC`, `PART_TYPES` and `STARTER` in `src/pages/admin/AdminNewsletter.tsx`; `PICK_DEFAULTS`, `DEFAULT_TITLE` and `COLOR` in `src/lib/newsletter.ts` | A draft is one JSON list of parts (`newsletters.layout`, 060), so adding a part or a setting needs no migration: a field in `PARTS_SPEC` and its drawing in `newsletter.ts`. The color choices are `PALETTE`; `COLOR` holds the defaults as hex, since an inbox has no theme tokens. `STARTER` is what a new draft starts with. The social bar's icons are PNGs in `public/email/` (Gmail and Outlook don't show SVG), made from `PlatformIcon.tsx` by `node scripts/email-icons.mjs`: run it again after adding a platform. A social bar with no links shows the footer's, `SOCIAL_LINKS` in `src/data/socialLinks.ts`. The countdown picture is `server/src/routes/countdown.js`, counting to local midnight in its `TIME_ZONE` (America/Chicago). | | The live site's address (used by QR codes) | `SITE_ORIGIN` in `src/lib/site.ts` | | | Version shown on the admin home page | `src/lib/version.ts` | | | Image directories (where logos and photos are looked up) | `src/lib/media.ts` | | diff --git a/public/email/discord-ink.png b/public/email/discord-ink.png new file mode 100644 index 0000000000000000000000000000000000000000..c9de1eb41d656d21db189634cff91f425ce43f89 GIT binary patch literal 997 zcmVG3t|d2lm)4%nx`t2bKYz7^u2rEIUT$w-k1DI)86kt z-#?tOKoLb0@n54G!f+T8iE?jdX=#P!8XtcVB@h`0)s3KDg75>V%@E!1?Md`tl52fj zgy;r{jJ0EQI#fr1+y-i`9W>K^AP9!GeqUamfQUk5NXpdyt_9{>YEy)-rx4wms!oT6 zPY3mK#6WGW2Ew}#zK{II{LOqrK6LQ+%T`%+TKmL@;c!qJ9mRL0{Qx=ISAK~{=Kq56 zn%`t67w2EJwrM|I<|e+fvJ_-p-UTzG3UyXnPKd6{zgUe5Vv|Gm^;Q0bYLqoVgmKwl zTL2=PW6g9(%*ylV9|+(XfbLncA5O}hEVbnqAw&bKGbs;b_$Cq-|2Wbi)7**1%&`XX~dKJW`btJ9ay zXCCAlBoh5H=8y@7dc$Gh+fbFvMMN}tQuRopMQKH)SL8uBIcgn-$e7eIIGP`Z<0JX1 z6TGz8n_%+H?^^noId4qytyF_tpgwgEg0oHkZ}#ZBE4c;mSPcJ^1OJ>y0Gmw4syztT za|#fij`49RH(#%M=-Fo?zTnY9Ur|=pH)i-ApuUc&z&ijvBiU6|y&?SM5x{wqvHM;V z$Fy8@_Le*FSH6sbXlJ9d|?YfCuM}S-uw84aO~it*sBW5-x%8ti4>c zU-Xxxk8p|g83ZB79gh6BP+i!v1`qT&gS-W~9jb$p^k$vtF<74Do!o3N1v!dKyNuSt#$^83Cbw>6Ftd0(1CVW>xbx@Zir-&koK*8cSf`x?g TlXI8u00000NkvXXu0mjf`Ci@3 literal 0 HcmV?d00001 diff --git a/public/email/discord-white.png b/public/email/discord-white.png new file mode 100644 index 0000000000000000000000000000000000000000..834dc30ce2a88622810b629d593f4c209561db05 GIT binary patch literal 838 zcmV-M1G)T(P)-|Uj7}~buK=!NqXl>fbUEJX z(s!O1?ETPDUXrczQ-MDIJ^jGUZ05SP=l=$`ycRpKp7^oR>ij66gZR-QzF7jOCce~I zdjB=?r4tzI3SbBEr`omiJSG0L0Yjq#SU_@E78Ss0lEc}k#ruWi&<%_X2e5+Vu__$E zVNY=@uv)XuLYb4meGmO(pi+8KM}H;I?CC>&H~?AMcx0X9Bi4`vbH|{UK*vPri#1cV z(wY)Z#E*rJb7YpL!7k=H^z%G@DM{u0R$gVgF=d!aEiSE~7aA*-BB=Ec+z2uNG&uAZ z4EoC+{?v$|-a~NP;J`(PzR94!>EX{&5nS~U^a7(DjSmCfIP@QY;SPNv@Y%zkD}iol zKGZrK*ksUeb?CQy`qC_-x1OS}e;gve8=nt+GU$7N#S!`neda@ZU~F_CvQ?e~HUk@g zQ^0pm{TaC?>Zmmsw%;f^1MShI(i=DmOi7?G@LctAqf-KCC%Lpq0FOKba_Aii6?Jn- z7jOtT?xA@g0j$#l#zI}HPzzK6je5DrmL9cHr8dU_`;FT7z}nOvTByd;HmT+CQPk+0oTkalUk!aOMnL2Lm$VA56-KP`%}vb3A^vS!!r>YSN&$Ik3;X3m`X&F)iA zP5tJa^ZoqJbKaiw1N>Meg7^xM2OxSD!VZv6A$(~)`MbkDGye&K<+eNrI2 zluS4?{5FCh=0|)GTM6NZ2*r=2!s@-97>Y8HW(fNt7thg<`e`Q$CsW-D>Ok4VbJP=s zL#Q@E_-hh~9~te5SZq~(;;ZWFA^cnd5g$Rl1<`XLTR~m~c@yL#2wy<>J4g90R8`gG zl3!sf^e226nP0afPXG%s!8#$Lpmuu#_?y}y zz(0U~fvRLyKpyoMIy_mB_`(28{YUVh)z?>n`pr}5^rNO`4oV83U#;e}!h1cw{fBu< zo}QfXq|thy`wMI*Z7fiqcmy~cD%->_^^%?2SyVfZ(+BU6HvrXL;i01UJWdo+Xzbq^H8KBK{>HWw6L^k+sOYfQ2OT|dPLucr zsDSW?gN{!3ZG=w%)p_pQ3GzbO0YsYJ2C<%Z---GJAX^-JU^fs13(F25dfKfAWPYjw zlL9Zau${enGF)}dghI`;Y-Okkhwyn`n&V_-3mManmGSsoZ&|o#01|dQZgaTKkNC01 znOY}?N(e9v(JS^|x@2ZP)CfC(y8#SCv>hVL5Sghif#?~Vt9J+JhUh88VvC~_o@wT* vmDP4jZZgkdx9j%SU)$|}lZ(={VjKSl*I+$gXiPA300000NkvXXu0mjfHs7n8 literal 0 HcmV?d00001 diff --git a/public/email/facebook-white.png b/public/email/facebook-white.png new file mode 100644 index 0000000000000000000000000000000000000000..4c33c97dbb5c8c3f3ba0661a0dabed77b51025d9 GIT binary patch literal 806 zcmV+>1KIqEP)bf8(QK@gt(BO30wYvy-=bg+R!3HD=cef?R@m)-JGU5Gw*rNbKW`ot#dOo z&+~k~XXbs*d!92vpderhum)%cdV%{uKk(cf{pPh^^O+`z2^uK_y&bp;d?mgl<_fUQ zs~KP#upfAZp56e5f$3?(?=;2I(t9~MX@JiKZsAWifjL_6Yk_z8*IQ`}N#R?8?=()s z(kNWvcK{_CuVQQyzT3_I4G?*q0A>RPCHOzGMX-gBY2Xu(3n~R1 zLr*EDmIE-+~1y!w$^}Opj>O0Bt5R2w584#MN{39^qxlpo0V(b zmZUEyuz?qWV*hW1fr2FcJ%J63NYYWq;4PtxQ22FJ#j7iiC@b5n4hXcbvl5K>hfyIsteG+^w0|r_h8O|oziE0{Xb7a^j!OJpW;FKf7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%aYA31g^gm%IR=asnCszOf002ovPDHLkV1jO+el7q2 literal 0 HcmV?d00001 diff --git a/public/email/instagram-white.png b/public/email/instagram-white.png new file mode 100644 index 0000000000000000000000000000000000000000..9460dbb34a0fa14aa59d295a71a85dac6addb5d8 GIT binary patch literal 1173 zcmV;G1Zw+Kpz<6?gkNN%L&FvQk zE@x)Wd}n@V=A1KglcWHE6~GSQ3~(8!1J8pp4!jP^8)oB;X(N3?9d*@xM#oxFgj*Kr z7GS$7o~H4b1|9-ig-a~?uYqBj2akZRqU84ilQbXR0egy&&%$Hi9B>*qre#3;g=L$5 z`mk(s+6@GHMCW?*9znMPG6+2DEe~sL*0$>5~k7FjMf;R0={SS${?hsFsiU1Y^oxmn7@_TVc z`-Q-Jhu~S$Zp74|PBi`qalQiS!@xaY${{1NyV|Da^uOx#`OdVtVCpZ5@Q<|5R*-lr za7cr*q8L{v)*9$p3H+vC;%}L#GuA1ir!K;0MtCf8)x}qo#SQy4#GEq5J8Jqr6X6RZ zJRCuOi0T;fOe$r}pH1HvB7A9t0|m_{ZRN$I9|SspFSK;1OrlB;*NZq!HMp+2Ve=>buC60&NSHN_}9rEAg5eRgA>r7%S&y<{Kc`VWN zE<|sR5;+Df_7^1|=sDo%Ih50<*R+2v!U-eXoufp~d2930L7$q_u+eoVr_V0aenNzA zjc{j<`B*1)FqVAAsWO#iMo!rCHgRmRCquznW@Al-33NL8Iy2h$n6{IN25%v@WGIlh z#$r*03A8!-x-;5KY8qlXb^_hbfNd2sE{lz^6KFOQ>WDR=|NSPOh&)CmBo6T?j4C6K z(Z@#D?J~z`tRu6lRw(=^5ZB~>%``_A8%oriP(t?6`UvtHoD6IKQk+QfJ;|SAI%6i45zC~@{yNFH0sM>Q& z>Rqe+VuT}Qlsl8@(AcS4f49wn-lwyyMIY2G8hW)@1i)&CXOC1YcP@8NBuxh3q+^oH zW-9GQ9-GgH4GXYfDF``%8;WKNWc{=TNo>*r}uW8$7o>?zAZve!E`!iXO z&C;3y?^550ok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9ayMeMcs$_Cw>P+e_DDW^n;=gvI9{)kfUqIJw{KA z+Bk?#HD+f?;v;CWDco!t`w<2jVldW}T9mtn+wQwB4 zn-yP3EHz-O(FF2*tD;0-wUiM4QfDO(8B&P8YlO_DQ{1^wuAJoQNhSyGnVUd_4Hxw3 zb-!&=XY@kp0QHA-#&Z;^vT(RUcxwLb#di4Ef zP_T4@yrZcICGLKKgQ@H2T;dCkrwZjx!cn6Ki6?9`#1TN(c=DGOd0HZq*1mVFauG3W zwYXZr-N3jK&o_g=k5X;s-))BNng8ustE3iOP~?~Y0WH>)(xQ|V9smFU07*qoM6N<$ Eg20w)BLDyZ literal 0 HcmV?d00001 diff --git a/public/email/spotify-white.png b/public/email/spotify-white.png new file mode 100644 index 0000000000000000000000000000000000000000..45b17a4b9e1169f5f189a40cb8bb64baacc8d1a3 GIT binary patch literal 1091 zcmV-J1ibr+P)sq@ zXJ9u_Lv;A8C(|vRf;R%z0o9}rUx2MZ)2M|n(BqB^kAVJB2|pF6B7S@XW`-4hG4PGd z;RmoPsPIceM3<58yr7hZh)bed8ZCk2Eaq;jN(z!BL6U=}bO$OBrsY)WgO6EG5(t>X>@Wk78RCH6WI zGdFH?0hk1|u_6S}1Q-RZ2d?{!dY^y}_Q`}*I^j0ZAWFeK6v~sN1(X=(pEdTu_gr4u z7KiZ30EPi)Qz&xJUW~ZCcnio$nmh;S2TYb-5PJlU0jGhBzzyJ>ewXLF^u1}oU@;xb z5Wo;Ekenbg=UZAydEqiptPUuGy(1jNdGBcTHb)#ig%S;bQkS{rSvpZB@l`iwA<)7_ zi7hT;_gfxElnK1ilWvuyz$usaugH&2eJ+wvTi>P8YYH#|=&OZKFZGd8`r9&Kr<&q( z!!_ROn3W#F3!YkrHZ2owRHq6RR;BI*mIEgvAdPP=ZF{7`f-pjRDAQDfh(xaX01DKa zDlpnZhWZjP^qa<-(AUjTP-~#Qgk=q# zKSKy#|EDHUa+M0M9b|R74jQTY0KK(H`iIFnjOzm&4cNjdwNE64L@FFsnlMJIsN-r9 zuRM10o8AkYS3*|klox;jN>BV?g?)nD2nu>rRH~B>NK!%~&oje0q(j~|c^AaV;)I-< zB)0-xzd7*QaO`#`d+e0v-oG2_fHS~jAE7$W&8ft;vmI+vwHDn9{A@s3N^+>p-LQ3U zI*^bk=qbESiOCth*l_Zb2}Z)(lqk-U3yyjz_>+On8gjL74!y1I@QvFd!nZH``>NkZ+Rxa?a|K0-wTQm_ywDrN3%hhgU|o~002ov JPDHLkV1mW@?zjK| literal 0 HcmV?d00001 diff --git a/public/email/substack-ink.png b/public/email/substack-ink.png new file mode 100644 index 0000000000000000000000000000000000000000..865e5417c65b09ff166d7efd31e3900a4dbb4286 GIT binary patch literal 445 zcmV;u0Yd(XP)f$ z3839TW+UWDk}AlPASy|!Urif^(M<^=t3eb{LJwvo)VvVP%rRs;ou(Ct?gde4TIm&F z82_F|8KOHu6dL8;>oO~$W+h-&f(5V%v}8{6|HHIwR0Fir&f@jVZh$sIn*V~bC`&AS z0=e(Ye}^NW+0OABowJi<0pu~L??o4I4w02#--dC#4B=S;1@IaYZw>sYm3RZ9S49x; z0CM-|w74(RAh$u@cB)#p5CW{<1-Ui0H#b>(}DN7 z7rC0tBv_z=&2P`;M-PR%4+wsca9+S0!?1d>*}KScRtx5PP8>Ba8ShGMFFgNCy6S@U zWuXiP_Q`pBWYi sE!gk1bH*^=4&3#J{qDUj$K@OI=XaSmuY1(11q@>bPgg&ebxsLQ00dQ+cK`qY literal 0 HcmV?d00001 diff --git a/public/email/tiktok-ink.png b/public/email/tiktok-ink.png new file mode 100644 index 0000000000000000000000000000000000000000..240e2ffbe2e94601e07d40f52f1d0c7a6932eba5 GIT binary patch literal 864 zcmV-m1E2hfP)hC1r>b8_$Z7Pf(R;#f{(%}+C~p9L z0iXh@mGHX(APd#aC~E-fOEff8Bb5^NS^#80y_n9eWDk&q=m`LoC|dx=5H}EpGf=hw zj3C$x(W6kEnFfG9X8`^ggP`6Axew$9h|DTJ0QJW>0J0+vy`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>qX8vBM$y zaP?Xr0&+!A05d6feZ^WI{3Yn6u(!aSh~tymRwDP){%xoejmG%Q-BHkA9qy`?+X0{) Z{{UVkUuX00ha&(0002ovPDHLkV1ip^Czb#J literal 0 HcmV?d00001 diff --git a/public/email/x-white.png b/public/email/x-white.png new file mode 100644 index 0000000000000000000000000000000000000000..2be00acfe8a387e729f295a668a685b66bf9145f GIT binary patch literal 1017 zcmVv^ptOt@)uNz*qD5p-L4(oY zCZZOBi$K$cO^Z-yQB-IY(V`a70GW*tG(i*E00l)>WYL@rHvQt_1D}`kru)73y%rvL zoA3L-bN=Uk_x-$UO%7*f428y?{F$AWo$V`9^!Zpb02)b%N95K&lNl0C*|jN_@mv z>Y{wg=MW?EwgCNrr-Jhh8g3f!%WKOeto0@aOa@v7J)WZB$^;^hl)4B$^NqFM#MFvA zNNax^CKWg#;Erg%26<@xDkG9Ul2A2>Zs+YaiOZH-Ykl7fxQ(+_Mnc{S-V=Bz1l{ao z%c;FS2{;*=)|(hm2z=E7|Izm>P%04Ald@aAI?Rkn86;6G5O@dVY0twk{8=N=H!0+8 z1ZxB$*X$>zA_YA0AfLF_8z#^VxFry((r^=#qV*=`&;%(NT%h6BJ0!3$C2j-e38lbi zy+c#Ak&wVCdr1XI=Zznepc;%xB zTH{cXWXH$ey+f0lpo0!2N!tIAK&y`?s0VOgz?H>Geyqn_NpFG*97>W|agfgin(#Kg z30fv#npL@-O!8i%5WP|9pg6#O0e7jx*f2u!8P>z+WOszmn(T_B&I;Pj4BfUyOL$$P#YZ=t;gC1g)Z|SuO=wdp+w)F46Xm^rQyIn;lAry6Ewo1M4um})~f(3 zd^SNheKbKuLW%w!7#5Y*mk02bXKfvQ0TyYvokE-&frq@-*!!#t`3@y>SWOUZan%E? zTXpDKA2b2W_YNOT&`{v5SIcUu^$o^jZ}%psR>RE|el0aq9iE8RtGQ;5DS1s8UJL$J zV&`m^dJC$X5`)Z8wLZiq$gk}RUF!{#sKDHohpP1nya_sOn1I?|W9%#8^lE=y6y$A5 nWLvW%lfOD_ijrHWrTDOaQDpE1W&XL500000NkvXXu0mjf+4asv literal 0 HcmV?d00001 diff --git a/public/email/youtube-ink.png b/public/email/youtube-ink.png new file mode 100644 index 0000000000000000000000000000000000000000..2b9a18bba635463fcc2114a6938195f1dbe30244 GIT binary patch literal 622 zcmV-!0+IcRP)TOrHDB{<8u!o^ zyf5d|`OacY)niV04&+d)q=!Iz2w4@fT9;WBvCB34`qt+h!&hJk^jpiP3>C_aVs8HLtAc>?|;O;1941lgYgMSOKT z@S`IFwu{F8i=bW?v;&)N2Yz={K!!tLdKI!y2aLJZ0|FRy3T^bnOS~5FXLPj(eq_>e zu%!gG=u&7l;9~AYFO<_3_<=^cUOEvS=tvp*p&p^PRl;p-J;64Ts= z=>6^k4!@>(z%idy1Af5as?}*9%figP)BUMoY!)$dk&;lT52byS4?`F48eLs2Z2?f zMC(xkR)9dQ@Do6h)~5(W+~J3S2lQ|c3^)b0&`0VsydQW*A5SK`5eT7|VIwe$UZ#ye z9K9?Vfs}^@t2CEQBe3UT!4dgE-e?XxM&QiDg55H+jR8kAo)gpT!fOGM=mh40JdGn~ z8WkEL;1KBo7JxF|bM5nZ{qsY>A<_e^0k0nRyETO?%@A;ii~@%q^?Ni0UudF$NOS;G zz|}wdRogzg5qg3-xe>jQ^iY(W7BL`@nUYfEtb=9ly7KeP`;%Mp?p*C zSADFa_+V?}BfJO<%5j|*N!T16TJ{tUwD^-~a#s M07*qoM6N<$f(C%vivR!s literal 0 HcmV?d00001 diff --git a/scripts/email-icons.mjs b/scripts/email-icons.mjs new file mode 100644 index 0000000..20950b0 --- /dev/null +++ b/scripts/email-icons.mjs @@ -0,0 +1,30 @@ +/* ═══════════════════════════════════════════════════════════════ + EMAIL ICONS: node scripts/email-icons.mjs (from the repo root) + + Gmail and Outlook don't show SVG, so a newsletter's social bar + (src/lib/newsletter.ts) uses PNG copies of the platform icons in + PlatformIcon.tsx: white and ink, 48px square (shown at 24), into + public/email/, which the build copies as they are, so the files + keep their addresses in emails already sent. Run it again after + adding a platform or changing an icon. Uses the server's sharp. + ═══════════════════════════════════════════════════════════════ */ + +import { readFileSync, writeFileSync } from "node:fs"; +import { createRequire } from "node:module"; + +const sharp = createRequire(new URL("../server/package.json", import.meta.url))("sharp"); +const source = readFileSync(new URL("../src/components/PlatformIcon.tsx", import.meta.url), "utf8"); + +const paths = {}; +for (const [, id, d] of source.matchAll(/^\s*(\w+):\s*'([^']+)'/gm)) paths[id] = d; +for (const [, id, d] of source.matchAll(/^\s*(\w+):\s*\n\s*'([^']+)'/gm)) paths[id] = d; +paths.instagram = /INSTAGRAM_PATH =\s*'([^']+)'/.exec(source)[1]; + +const TONES = { white: "#ffffff", ink: "#001011" }; +for (const [id, d] of Object.entries(paths)) { + for (const [tone, fill] of Object.entries(TONES)) { + const svg = ``; + writeFileSync(new URL(`../public/email/${id}-${tone}.png`, import.meta.url), await sharp(Buffer.from(svg)).png().toBuffer()); + } +} +console.log(`${Object.keys(paths).length} icons: ${Object.keys(paths).join(", ")}`); diff --git a/server/src/index.js b/server/src/index.js index 7cd715b..1014a53 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -39,6 +39,7 @@ import media from "./routes/media.js"; import clips from "./routes/clips.js"; import imports from "./routes/import.js"; import files from "./routes/files.js"; +import countdown from "./routes/countdown.js"; import { CLIPS_DIR, startClipWorker } from "./clips.js"; import { UPLOADS_DIR, writeMissingThumbs } from "./media.js"; import { logSafe, startSessionSweeper } from "./auth.js"; @@ -74,6 +75,14 @@ const app = new Hono(); // loop a synchronous write each. app.use("/api/admin/*", logger()); +/* A newsletter's countdown picture is shown inside other sites' + webmail, which the same-origin resource policy set below would + refuse. Registered first so it runs last, after secureHeaders. */ +app.use("/api/countdown/*", async (c, next) => { + await next(); + c.res.headers.set("Cross-Origin-Resource-Policy", "cross-origin"); +}); + /* Headers for every response. Referrer kept to the origin (YouTube embeds refuse to play without one). No HSTS here: nginx sends it on everything, including the files it serves from disk @@ -178,6 +187,11 @@ app.route("/api", home); app.route("/api", directory); app.route("/api", blog); app.route("/api", sitePages); +// Opened by everyone a newsletter goes to, often through one mail +// proxy's address, so looser than the rest; each picture is kept for +// its minute (routes/countdown.js). +app.use("/api/countdown/*", rateLimit({ windowMs: 60_000, max: 600 })); +app.route("/api", countdown); // Tighter limit on the write path than anything else gets. app.use("/api/feedback", rateLimit({ windowMs: 60_000, max: 5 })); diff --git a/server/src/routes/countdown.js b/server/src/routes/countdown.js new file mode 100644 index 0000000..abd0601 --- /dev/null +++ b/server/src/routes/countdown.js @@ -0,0 +1,119 @@ +/* ═══════════════════════════════════════════════════════════════ + COUNTDOWN IMAGE: GET /api/countdown/:id.png + + A newsletter's countdown block (src/lib/newsletter.ts) is this + picture: the time left until a published one-off event starts, + drawn when the email is opened, since an email can't run code. + Gmail fetches images once through its proxy and keeps them, so + there it shows the time of the first open; the block's fixed line + under the image covers that and clients that block images. + + ?bg=003a45 the band's color (hex, no #) + ?fg=ffffff the text's color + ?t=... the line above the numbers (default: the event's title) + + An event starts at local midnight on starts_on in TIME_ZONE (events + carry a date, not a time) and is over when ends_on (or starts_on) + is; the picture says which. A series has no one start to count + to, so it isn't offered. + + Each picture is kept for the minute it shows, a few hundred at most, + so a newsletter opened by everyone at once draws it once a minute. + ═══════════════════════════════════════════════════════════════ */ + +import { Hono } from "hono"; +import sharp from "sharp"; + +// The organization's home time zone (Unity Village, Missouri). +export const TIME_ZONE = "America/Chicago"; +const MAX_KEPT = 300; + +const countdown = new Hono(); +const kept = new Map(); // key → png Buffer + +const hex = (value, fallback) => (/^[0-9a-f]{6}$/i.test(value ?? "") ? `#${value}` : fallback); +const xml = (value) => + String(value).replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); + +/* The instant a date's local midnight is in a time zone, as ms. */ +export function zonedMidnight(date, timeZone = TIME_ZONE) { + const [y, m, d] = date.split("-").map(Number); + const guess = Date.UTC(y, m - 1, d); + // How far the zone's clock is from UTC at that instant, twice so a + // clock change between the guess and the answer is caught. + const offset = (at) => { + const parts = Object.fromEntries( + new Intl.DateTimeFormat("en-US", { timeZone, hourCycle: "h23", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric" }) + .formatToParts(at) + .map((p) => [p.type, Number(p.value)]), + ); + return Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute, parts.second) - at; + }; + const first = guess - offset(guess); + return guess - offset(first); +} + +/* Days, hours and minutes left, or null once it's started. */ +export function remaining(target, now = Date.now()) { + const left = target - now; + if (left <= 0) return null; + const minutes = Math.floor(left / 60_000); + return { days: Math.floor(minutes / 1440), hours: Math.floor(minutes / 60) % 24, minutes: minutes % 60 }; +} + +const W = 1104; // twice the email's 552px, for sharp screens +const H = 280; +const FONT = "Poppins, Montserrat, Helvetica, Arial, sans-serif"; + +function svg({ label, left, over, bg, fg }) { + const top = `${xml(label)}`; + if (!left) { + return `${top} +${over ? "Thanks for joining us" : "Happening now"}`; + } + const cells = [ + [left.days, left.days === 1 ? "DAY" : "DAYS"], + [left.hours, left.hours === 1 ? "HOUR" : "HOURS"], + [left.minutes, left.minutes === 1 ? "MINUTE" : "MINUTES"], + ] + .map(([n, unit], i) => { + const x = (W / 3) * i + W / 6; + return `${String(n).padStart(2, "0")} +${unit}`; + }) + .join(""); + return `${top}${cells}`; +} + +countdown.get("/countdown/:file", async (c) => { + const id = /^(.+)\.png$/.exec(c.req.param("file"))?.[1]; + const event = id + ? c + .get("db") + .prepare(`SELECT title, starts_on, ends_on FROM events WHERE id = ? AND is_published = 1 AND is_series = 0 AND starts_on IS NOT NULL`) + .get(id) + : null; + if (!event) return c.json({ error: "No such event" }, 404); + + const bg = hex(c.req.query("bg"), "#003a45"); + const fg = hex(c.req.query("fg"), "#ffffff"); + const label = (c.req.query("t") ?? "").trim().slice(0, 60) || event.title.slice(0, 60); + const left = remaining(zonedMidnight(event.starts_on)); + // Over once the last day's midnight has passed. + const over = !left && Date.now() >= zonedMidnight(event.ends_on ?? event.starts_on) + 86_400_000; + const key = JSON.stringify([id, bg, fg, label, left, over]); + + let png = kept.get(key); + if (!png) { + png = await sharp(Buffer.from(svg({ label, left, over, bg, fg }))).png().toBuffer(); + if (kept.size >= MAX_KEPT) kept.delete(kept.keys().next().value); + kept.set(key, png); + } + return c.body(png, 200, { + "Content-Type": "image/png", + // Asked for again at every open, where the client allows it. + "Cache-Control": "no-cache, max-age=0, must-revalidate", + }); +}); + +export default countdown; diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index 6f25a42..a291b87 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -4,12 +4,7 @@ import { useNavSections } from "../lib/navSections.ts"; import siteLogo from "../assets/logos/NGU_Logo.svg"; import PlatformIcon from "./PlatformIcon.tsx"; import { ORGANIZATION_DETAILS as Organization_Details } from "../data/organizationDetails.ts"; - -const Social_Links = [ - { label: "Instagram", href: "https://www.instagram.com/nextgenerationunity/", platform: "instagram" }, - { label: "Facebook", href: "https://www.facebook.com/NextGenerationofUnity", platform: "facebook" }, - { label: "Discord", href: "https://discord.com/invite/AtngzpqaX5", platform: "discord" }, -]; +import { SOCIAL_LINKS } from "../data/socialLinks.ts"; // Give's destination lives in navConfig so the footer and the nav can't drift. // Only the label differs down here. @@ -88,7 +83,7 @@ export default function Footer() { {/* Socials + get in touch */}
- {Social_Links.map(({ label, href, platform }) => ( + {SOCIAL_LINKS.map(({ label, href, platform }) => ( = [ + { label: 'Instagram', href: 'https://www.instagram.com/nextgenerationunity/', platform: 'instagram' }, + { label: 'Facebook', href: 'https://www.facebook.com/NextGenerationofUnity', platform: 'facebook' }, + { label: 'Discord', href: 'https://discord.com/invite/AtngzpqaX5', platform: 'discord' }, +] diff --git a/src/lib/adminWidth.tsx b/src/lib/adminWidth.tsx index 5bd3a1e..02cdb0e 100644 --- a/src/lib/adminWidth.tsx +++ b/src/lib/adminWidth.tsx @@ -3,7 +3,8 @@ The admin column is max-w-5xl. The record editor wants more (its section nav sits to the left of a form that keeps that width), and - so does the admin home (three cards across). + so does the admin home (three cards across): "wide". The newsletter + builder takes the whole window, its editor beside a preview: "full". Like the title (adminTitle.tsx), the page asks and the layout decides, so AdminLayout stays the one place that sets
's width. @@ -14,14 +15,16 @@ import { createContext, useContext, useEffect } from "react"; -export const AdminWidthContext = createContext<((wide: boolean) => void) | null>(null); +export type AdminWidth = "normal" | "wide" | "full"; -export function useWideAdminPage() { - const setWide = useContext(AdminWidthContext); +export const AdminWidthContext = createContext<((width: AdminWidth) => void) | null>(null); + +export function useWideAdminPage(width: Exclude = "wide") { + const setWidth = useContext(AdminWidthContext); useEffect(() => { - if (!setWide) return undefined; - setWide(true); - return () => setWide(false); - }, [setWide]); + if (!setWidth) return undefined; + setWidth(width); + return () => setWidth("normal"); + }, [setWidth, width]); } diff --git a/src/lib/newsletter.ts b/src/lib/newsletter.ts index 3d07759..cd9d349 100644 --- a/src/lib/newsletter.ts +++ b/src/lib/newsletter.ts @@ -14,6 +14,12 @@ bar, and the button label footer the closing lines (blank: the site's name and address) and the rule above them + social a band of the site's platform icons, each linked + (PNGs in public/email/: scripts/email-icons.mjs) + countdown a picture of the time left until a picked event, + drawn by the API when the email is opened + (server/src/routes/countdown.js), with a fixed line + under it, as of copying, for when images don't load any block drawn as its email-safe equivalent: headings, paragraphs (with **bold**, *italic* and [links](url)), callouts, quotes, lists, link and button rows, images, @@ -31,6 +37,7 @@ ═══════════════════════════════════════════════════════════════ */ import { readableOn } from './color.ts' +import { PLATFORMS } from './platforms.ts' export type NewsletterItem = { title: string @@ -70,12 +77,25 @@ export type NewsletterPart = { rule?: string | null /** The bar down the left of a picks section's cards. */ bar?: string | null + /** A social bar's links, in order. */ + socials?: Array<{ platform?: string | null; url?: string | null }> + /** A countdown's event. */ + event?: string | null } +/* What a countdown needs of its event. */ +export type CountdownEvent = { title: string; starts_on?: string | null; href: string } + export type Newsletter = { parts: NewsletterPart[] /** A picks part's items, ready to draw (picked, published, in order). */ itemsFor: (part: NewsletterPart) => NewsletterItem[] + /** A countdown's event, if it's one that can be counted to. */ + eventFor: (id: string) => CountdownEvent | null + /** Now, for the countdown's fixed line. */ + now: number + /** A social bar with no links of its own shows these (the footer's). */ + defaultSocials: Array<{ platform: string; url: string }> /** The site's address, for the header link and footer. */ origin: string siteName: string @@ -296,6 +316,53 @@ function footerHtml(part: NewsletterPart, n: Newsletter): string {
` } +/* The site's platform icons as PNGs, white or ink to read on the band. */ +const platformLabel = (id: string) => PLATFORMS.find((p) => p.id === id)?.label ?? id +const socialsOf = (part: NewsletterPart, n: Newsletter) => + (part.socials?.length ? part.socials : n.defaultSocials).filter((link) => link.platform && link.url) + +const iconUrl = (n: Newsletter, platform: string, band: string | null) => + `${n.origin}/email/${encodeURIComponent(platform)}-${band && readableOn(band) === '#ffffff' ? 'white' : 'ink'}.png` + +function socialHtml(part: NewsletterPart, n: Newsletter): string { + const band = colorOf(part.color, COLOR.body) + const links = socialsOf(part, n) + .map((link) => ({ platform: link.platform!, url: safeHref(link.url!, n) })) + .filter((link) => link.url) + if (links.length === 0) return '' + const icons = links + .map( + (link) => + `${escape(platformLabel(link.platform))}`, + ) + .join('') + return `
${icons}
` +} + +/* "12 days to go", as of `now`: an event starts at its date's + midnight. Null once it has, or with no date. */ +export function countdownLine(event: CountdownEvent, now: number): string | null { + if (!event.starts_on) return null + const [y, m, d] = event.starts_on.split('-').map(Number) + const days = Math.ceil((new Date(y, m - 1, d).getTime() - now) / 86_400_000) + if (days <= 0) return null + return days === 1 ? '1 day to go' : `${days} days to go` +} + +function countdownHtml(part: NewsletterPart, n: Newsletter): string { + const event = part.event ? n.eventFor(part.event) : null + if (!event || !part.event) return '' + const band = colorOf(part.color, COLOR.body) ?? COLOR.page + const label = part.text?.trim() || event.title + const query = new URLSearchParams({ bg: band.slice(1), fg: readableOn(band).slice(1), t: label }) + const src = `${n.origin}/api/countdown/${encodeURIComponent(part.event)}.png?${query}` + const line = countdownLine(event, n.now) ?? 'Happening now' + return ` + ${imageTag(src, `${label}: ${line}`)} +

${escape(line)}: ${escape(event.title)}

+` +} + function partHtml(part: NewsletterPart, n: Newsletter): string { switch (part.type) { case 'header': @@ -306,6 +373,10 @@ function partHtml(part: NewsletterPart, n: Newsletter): string { return picksHtml(part, n) case 'footer': return footerHtml(part, n) + case 'social': + return socialHtml(part, n) + case 'countdown': + return countdownHtml(part, n) default: { const html = blockHtml(part, n) return html ? `${html}` : '' @@ -395,6 +466,15 @@ function partText(part: NewsletterPart, n: Newsletter): string[] { } case 'footer': return ['--', ...(part.text?.trim() ? [part.text.trim()] : [n.siteName, n.origin]), ''] + case 'social': { + const lines = socialsOf(part, n).map((link) => `${platformLabel(link.platform!)}: ${link.url}`) + return lines.length ? [...lines, ''] : [] + } + case 'countdown': { + const event = part.event ? n.eventFor(part.event) : null + if (!event) return [] + return [`${countdownLine(event, n.now) ?? 'Happening now'}: ${event.title}`, event.href, ''] + } default: return blockText(part, n) } diff --git a/src/pages/admin/AdminLayout.tsx b/src/pages/admin/AdminLayout.tsx index 16e95b9..8cd77a5 100644 --- a/src/pages/admin/AdminLayout.tsx +++ b/src/pages/admin/AdminLayout.tsx @@ -25,7 +25,7 @@ import { Suspense, useCallback, useEffect, useMemo, useState } from "react"; import { Link, NavLink, Outlet, useLocation, useNavigate } from "react-router-dom"; import { useAuth } from "../../lib/auth.tsx"; import { AdminTitleContext } from "../../lib/adminTitle.tsx"; -import { AdminWidthContext } from "../../lib/adminWidth.tsx"; +import { AdminWidthContext, type AdminWidth } from "../../lib/adminWidth.tsx"; import { SITE_VERSION } from "../../lib/version.ts"; import { ROLE_LABELS, isSuper } from "../../lib/roles.ts"; import siteLogo from "../../assets/logos/NGU_Logo.svg"; @@ -111,12 +111,13 @@ export default function AdminLayout() { const stableSet = useCallback((value) => setDetail(value), []); const titleContext = useMemo(() => ({ setDetail: stableSet }), [stableSet]); - // Whether the page below asked for extra room (the record editor, - // for its section nav). setWide is a state setter, so it's stable. - const [wide, setWide] = useState(false); + // How much room the page below asked for (adminWidth.tsx): the + // record editor more, for its section nav; the newsletter builder + // the whole window. setWidth is a state setter, so it's stable. + const [width, setWidth] = useState("normal"); // The header, its strip and the footer line up with the content, // however wide the page asked for. - const column = wide ? "max-w-[82rem]" : "max-w-5xl"; + const column = { normal: "max-w-5xl", wide: "max-w-[82rem]", full: "max-w-none" }[width]; useEffect(() => { // Sections only exist in the CMS. Home and Panel already say @@ -211,7 +212,7 @@ export default function AdminLayout() { without ever floating over it. */}
- + diff --git a/src/pages/admin/AdminNewsletter.tsx b/src/pages/admin/AdminNewsletter.tsx index 708a925..5ec552f 100644 --- a/src/pages/admin/AdminNewsletter.tsx +++ b/src/pages/admin/AdminNewsletter.tsx @@ -39,6 +39,8 @@ import { SITE_NAME, SITE_ORIGIN, siteUrl } from '../../lib/site.ts' import { seriesLabel } from '../../lib/eventSeries.ts' import { useWideAdminPage } from '../../lib/adminWidth.tsx' import { PALETTE } from '../../lib/color.ts' +import { PLATFORMS } from '../../lib/platforms.ts' +import { SOCIAL_LINKS } from '../../data/socialLinks.ts' import { DEFAULT_TITLE, newsletterHtml, @@ -73,6 +75,8 @@ const PART_TYPES: Array<[string, string, string]> = [ ['title', 'Title', "The email's heading."], ['picks', 'Picked items', 'Upcoming events, published blog posts or front page cards, each as a card with a button.'], ['footer', 'Footer', 'The closing lines. No unsubscribe link needed: Mailchimp adds its own.'], + ['social', 'Social bar', "A colored band of the site's social icons, each linked."], + ['countdown', 'Event countdown', "The time left until an event, as a picture the site draws each time the email is opened, with a line under it for when pictures don't load. Gmail may keep the time of the first open."], ...(BLOCK_TYPES.filter(([type]) => EMAIL_BLOCKS.includes(type)) as Array<[string, string, string]>), ] const partLabel = (type: string) => PART_TYPES.find(([value]) => value === type)?.[1] ?? type @@ -133,7 +137,17 @@ const PARTS_SPEC = { when: { path: 'type', value: 'header' }, help: "A PNG or JPEG: Gmail and Outlook don't show SVG. Default: none, the words alone", }, - colorField('color', 'Band color', 'Teal, darkest', 'None: no band', ['header']), + colorField('color', 'Band color', 'Teal, darkest', 'None: no band', ['header', 'social', 'countdown']), + { + path: 'event', + label: 'Event', + widget: 'select', + optionsFrom: 'countdownEvents', + required: true, + when: { path: 'type', value: 'countdown' }, + help: 'Upcoming events with a date; a series has no one start to count to', + }, + { path: 'text', label: 'Words above', when: { path: 'type', value: 'countdown' }, help: "Default: the event's title" }, { path: 'text', label: 'Title', full: true, when: { path: 'type', value: 'title' }, help: `Default: ${DEFAULT_TITLE(SITE_NAME)}` }, { path: 'source', @@ -173,6 +187,19 @@ const PARTS_SPEC = { ], children: [ ...(blocksChild.children ?? []), + { + key: 'socials', + label: 'Links', + addLabel: 'Add link', + note: `None added: the site's own (${SOCIAL_LINKS.map((link) => link.label).join(', ')}).`, + when: { path: 'type', value: 'social' }, + title: (row: { platform?: string; url?: string }) => PLATFORMS.find((p) => p.id === row.platform)?.label ?? 'New link', + blank: { platform: '', url: '' }, + fields: [ + { path: 'platform', label: 'Platform', widget: 'select', options: PLATFORMS.map((p) => [p.id, p.label]), required: true }, + { path: 'url', label: 'Link', required: true, help: 'eg. https://www.instagram.com/nextgenerationunity/' }, + ], + }, { key: 'picked', label: 'Picked', @@ -218,7 +245,7 @@ const picksOf = (parts: NewsletterPart[], source: PickSource) => .flatMap((part) => (part.picked ?? []).map((pick) => pick.ref).filter((ref): ref is string => Boolean(ref))) export default function AdminNewsletter() { - useWideAdminPage() + useWideAdminPage('full') const navigate = useNavigate() const { user } = useAuth() const [parts, setParts] = useState(STARTER) @@ -375,6 +402,9 @@ export default function AdminNewsletter() { const href = featuredHref(card) return href ? [{ id: href, label: card.title ?? href }] : [] }), + countdownEvents: events + .filter((event) => !event.is_series && event.starts_on) + .map((event) => ({ id: event.id, label: [event.title, event.date_label].filter(Boolean).join(', ') })), }), [events, posts, cards], ) @@ -387,12 +417,18 @@ export default function AdminNewsletter() { const item = pick.ref ? lookup[sourceOf(part)].get(pick.ref) : undefined return item ? [{ ...item, cta: part.cta?.trim() || item.cta }] : [] }), + eventFor: (id: string) => { + const event = events.find((row) => row.id === id && !row.is_series && row.starts_on) + return event ? { title: event.title, starts_on: event.starts_on, href: siteUrl(eventHref(event.id)) } : null + }, + now: Date.now(), + defaultSocials: SOCIAL_LINKS.map((link) => ({ platform: link.platform, url: link.href })), origin: SITE_ORIGIN, siteName: SITE_NAME, absolute: absoluteFor, } return { content, html: newsletterHtml(content), text: newsletterText(content) } - }, [parts, lookup]) + }, [parts, lookup, events]) /* An unpublished blog post from what's built: the blocks, then each picks section as a heading and link cards. The header, title and @@ -420,7 +456,7 @@ export default function AdminNewsletter() { ] } if (!EMAIL_BLOCKS.includes(part.type)) return [] - const { align: _align, color: _color, size: _size, space: _space, ...block } = part + const { align: _align, color: _color, size: _size, space: _space, socials: _socials, event: _event, ...block } = part return [block] }) const excerpt = parts.find((part) => part.type === 'paragraph' && part.text?.trim())?.text?.trim() ?? null @@ -507,7 +543,8 @@ export default function AdminNewsletter() { )}
-
+ {/* The editor takes what the preview (the email's 600px and its margin) leaves. */} +