Skip to content

Commit 61fc822

Browse files
committed
add posts to devto
1 parent 70cc1dc commit 61fc822

4 files changed

Lines changed: 571 additions & 14 deletions

File tree

‎backend/firebase/functions/src/devto/scheduledNotionToDevto.ts‎

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { sendTopic } from '../utilities/googleapis';
33
import {
44
queryPurrfectStreamDevTo,
55
patchPurrfectPage,
6+
queryByDevto,
7+
getNotionPageMarkdown,
68
} from '../utilities/notion.server';
79
import { addArticle } from '../utilities/devto';
810

@@ -24,6 +26,20 @@ export const scheduledNotionToDevto = functions.pubsub
2426
await sendTopic(topicId, pod);
2527
}
2628
}
29+
30+
console.log('Checking for devto missing');
31+
const posts = await queryByDevto('post', 1);
32+
console.log('Posts:', JSON.stringify(posts));
33+
34+
if (posts?.results) {
35+
const needposts = posts?.results;
36+
console.log('Posts to add to pub/sub', JSON.stringify(needposts));
37+
38+
for (const p of needposts) {
39+
await sendTopic(topicId, p);
40+
}
41+
}
42+
2743
return true;
2844
});
2945

@@ -37,6 +53,30 @@ export const devtoToNotionPubSub = functions.pubsub
3753

3854
let data;
3955
switch (page._type) {
56+
case 'post':
57+
const post = await getNotionPageMarkdown({
58+
_type: page._type,
59+
slug: page?.properties?.slug?.url,
60+
preview: false,
61+
});
62+
63+
if (!post || !post.content) {
64+
break;
65+
}
66+
67+
data = {
68+
article: {
69+
title: page.title,
70+
published: true,
71+
tags: ['podcast', 'webdev', 'javascript', 'beginners'],
72+
main_image: `https://media.codingcat.dev/image/upload/b_rgb:5e1186,c_pad,w_1000,h_420/${page?.coverPhoto?.public_id}`,
73+
canonical_url: `https://codingcat.dev/${page._type}/${page.slug}`,
74+
description: page.excerpt,
75+
organization_id: '1009',
76+
body_markdown: post.content,
77+
},
78+
};
79+
break;
4080
case 'podcast':
4181
data = {
4282
article: {
@@ -93,7 +133,7 @@ export const devtoToNotionPubSub = functions.pubsub
93133

94134
return purrfectPagePatchRes;
95135
} else {
96-
console.log('No Data matched for article');
136+
console.error('No Data matched for article');
97137
return;
98138
}
99139
});
@@ -113,5 +153,18 @@ export const httpNotionToDevto = functions.https.onRequest(async (req, res) => {
113153
await sendTopic(topicId, pod);
114154
}
115155
}
156+
157+
console.log('Checking for devto missing');
158+
const posts = await queryByDevto('post', 1);
159+
console.log('Posts:', JSON.stringify(posts));
160+
161+
if (posts?.results) {
162+
const needposts = posts?.results;
163+
console.log('Posts to add to pub/sub', JSON.stringify(needposts));
164+
165+
for (const p of needposts) {
166+
await sendTopic(topicId, p);
167+
}
168+
}
116169
res.send({ msg: 'started' });
117170
});

‎backend/firebase/functions/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export { scheduledNotionToFirestore } from './firebase/notion';
3232
export {
3333
scheduledNotionToDevto,
3434
devtoToNotionPubSub,
35+
httpNotionToDevto,
3536
} from './devto/scheduledNotionToDevto';
3637

3738
// Notion to Devto

‎backend/firebase/functions/src/utilities/notion.server.ts‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,56 @@ export const queryByPublished = async (
423423
return await formatPosts(raw, _type, false, true);
424424
};
425425

426+
export const queryByDevto = async (
427+
_type: string,
428+
page_size?: number,
429+
start_cursor?: string | null
430+
) => {
431+
const sorts: any = [
432+
{
433+
property: 'start',
434+
direction: 'ascending',
435+
},
436+
];
437+
const filter: any = {
438+
and: [
439+
{
440+
property: 'slug',
441+
url: {
442+
is_not_empty: true,
443+
},
444+
},
445+
{
446+
property: 'published',
447+
select: {
448+
equals: 'published',
449+
},
450+
},
451+
{
452+
property: 'devto',
453+
url: {
454+
is_empty: true,
455+
},
456+
},
457+
{
458+
property: 'start',
459+
date: {
460+
is_not_empty: true,
461+
},
462+
},
463+
],
464+
};
465+
466+
const raw = await notionClient.databases.query({
467+
database_id: getNotionDbByType(_type),
468+
start_cursor: start_cursor ? start_cursor : undefined,
469+
page_size,
470+
filter,
471+
sorts,
472+
});
473+
return await formatPosts(raw, _type, false, true);
474+
};
475+
426476
export const queryAll = async (
427477
_type: string,
428478
page_size?: number,

0 commit comments

Comments
 (0)