-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
87 lines (84 loc) · 2.01 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import "dotenv/config";
import { fetchContent } from "./services/fetchContent.js";
import { publishContent } from "./services/publishContent.js";
import { sendEmail } from "./utils/failure/email.js";
const notionData = {
env: process.env.ENVIRONMENT,
pageId: "",
channel: "",
devToContent: {
title: "",
main_image: "",
tags: [],
body_markdown: "",
published: true,
publishedUrl: "",
},
hashnodeContent: {
title: "",
publicationId: "",
contentMarkdown: "",
coverImageOptions: {
coverImageURL: "",
isCoverAttributionHidden: true,
stickCoverToBottom: false,
},
tags: [],
metaTags: {
title: "",
description: "",
image: "",
},
settings: {
enableTableOfContent: true,
},
publishedUrl: "",
},
mediumContent: {
title: "",
contentFormat: "markdown",
content: "",
tags: [],
publishStatus: "public",
notifyFollowers: true,
publishedUrl: "",
},
linkedInContent: {
content: "",
articleUrl: "",
articleImage: "",
articleTitle: "",
publishedUrl: "",
},
twitterContent: {
content: "",
imageUrl: "",
retweetId: "",
publishedUrl: "",
},
};
const main = async () => {
if (notionData.env !== "production") {
console.log("Enter the Page Link ID: ");
const pageLinkId = await new Promise((resolve) => {
process.stdin.once("data", (data) => {
resolve(data.toString().trim());
});
});
const pageId = `${pageLinkId.slice(0, 8)}-${pageLinkId.slice(8,12)}-${pageLinkId.slice(12, 16)}-${pageLinkId.slice(16,20)}-${pageLinkId.slice(20)}`;
notionData.pageId = pageId;
}
try {
await fetchContent(notionData);
} catch (error) {
await sendEmail("Notion Fetch - Error", error.message);
process.exit(1);
}
try {
await publishContent(notionData, "devTo", "twitter");
// await publishContent(notionData, "all", "all");
} catch (error) {
await sendEmail("Publish Content - Error", error.message);
}
};
await main();