-
Notifications
You must be signed in to change notification settings - Fork 63
feat: weekly newsletter with upcoming events #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iiio2
wants to merge
21
commits into
main
Choose a base branch
from
email-render-ts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7d141a4
weekly newsletter
razbakov 8d64a6c
render email in ts.
iiio2 3a34a49
add firebase to get data.
iiio2 9c9a961
get events from firebase.
iiio2 fd68f7b
get events between seven days of a specific place
iiio2 c5eb367
get profile data.
iiio2 ba6c242
fix code formatting.
iiio2 2f54c20
remove repetitive code.
iiio2 e77b729
build scheduleEmail.
iiio2 620f326
refactor code.
iiio2 103be6d
add weekly.html in .gitignore
iiio2 a519056
fix some issues.
iiio2 9d523be
improve weekly newsletter
razbakov 54ed8e0
Merge pull request #359 from we-dance/email-render-ts-alex
iiio2 62269c6
clean up code.
iiio2 eb5c93f
format weekly.mjml
iiio2 ce4ad94
remove emails folder.
iiio2 0446dcb
format code.
iiio2 44aef5a
fix newsletter
razbakov 59f0295
fix emails
razbakov 96d4b75
fix newsletter
razbakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,3 +96,4 @@ sw.* | |
|
|
||
| # Firebase | ||
| .vscode | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
iiio2 marked this conversation as resolved.
Outdated
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
iiio2 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| const { createSSRApp } = require("vue"); | ||
| const { renderToString } = require("vue/server-renderer"); | ||
| import mjml2html = require("mjml"); | ||
| import * as fs from "fs"; | ||
| import * as moment from "moment"; | ||
| import { firestore } from "../firebase"; | ||
|
|
||
| export async function renderEmail(type: string, data: any, customUtms = {}) { | ||
| const template = fs.readFileSync(`./templates/${type}.mjml`, "utf8"); | ||
|
iiio2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| const defaultUtms = { | ||
| campaign: type, | ||
| medium: "email", | ||
| source: "newsletter", | ||
| }; | ||
|
|
||
| const utm = { | ||
| ...defaultUtms, | ||
| ...customUtms, | ||
| }; | ||
|
|
||
| const app = createSSRApp({ | ||
| data: () => { | ||
| return data; | ||
| }, | ||
| template, | ||
| methods: { | ||
| link(url: string, utmContent = "") { | ||
| return ( | ||
| url + | ||
| "?utm_campaign=" + | ||
| utm.campaign + | ||
| "&utm_medium=" + | ||
| utm.medium + | ||
| "&utm_source=" + | ||
| utm.source + | ||
| "&utm_content=" + | ||
| utmContent | ||
| ); | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| app.config.compilerOptions.isCustomElement = (tag: any) => | ||
| tag.startsWith("mj"); | ||
|
|
||
| return mjml2html(await renderToString(app)).html; | ||
| } | ||
|
|
||
| export async function getWeeklyData(city: string) { | ||
| const today = new Date().toISOString().slice(0, 10); | ||
| const then = new Date(); | ||
|
iiio2 marked this conversation as resolved.
Outdated
|
||
| then.setDate(then.getDate() + 7); | ||
| const sevenDaysFromNow = then.toISOString().slice(0, 10); | ||
| const data = []; | ||
| let profile: any = {}; | ||
|
iiio2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| const profileDocs = ( | ||
| await firestore.collection("profiles").where("username", "==", city).get() | ||
| ).docs; | ||
|
|
||
| for (const doc of profileDocs) { | ||
| profile = { id: doc.id, ...doc.data() }; | ||
| } | ||
|
|
||
| let usernames = Object.keys(profile.watch?.list); | ||
|
iiio2 marked this conversation as resolved.
Outdated
|
||
|
|
||
| for (let username of usernames) { | ||
| const eventDocs = ( | ||
| await firestore | ||
| .collection("posts") | ||
| .where("startDate", ">", today) | ||
| .where("startDate", "<", sevenDaysFromNow) | ||
| .where("username", "==", username) | ||
|
iiio2 marked this conversation as resolved.
Outdated
|
||
| .get() | ||
| ).docs; | ||
|
|
||
| for (const doc of eventDocs) { | ||
| const event = { | ||
| id: doc.id, | ||
| ...doc.data(), | ||
| } as any; | ||
|
|
||
| data.push(event); | ||
| } | ||
| } | ||
|
|
||
| const events: any = { | ||
| intro: | ||
| "Hope you had a great weekend and are ready with your dancing shoes on for a fantastic week ahead.", | ||
| title: `${city} Dance Calendar`, | ||
| links: { | ||
| telegram: profile.telegram, | ||
| instagram: profile.instagram, | ||
| facebook: profile.facebook, | ||
| addEvent: "https://wedance.vip/events/-/edit", | ||
| city: `https://wedance.vip/${city}`, | ||
| }, | ||
| days: data.map((event) => ({ | ||
| day: moment(event.startDate).format("dddd"), | ||
| date: moment(event.startDate).format("D MMM"), | ||
| events: [ | ||
| { | ||
| title: event.name, | ||
| organizer: event.org.name, | ||
| venue: event.venue?.name, | ||
| format: event.eventType, | ||
| time: moment(event.startDate).format("hh:mm"), | ||
| link: event.link, | ||
| cover: event.cover, | ||
| styles: Object.keys(event.styles), | ||
| }, | ||
| ], | ||
| })), | ||
| }; | ||
|
|
||
| return events; | ||
| } | ||
|
iiio2 marked this conversation as resolved.
Outdated
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.