Skip to content

Commit b104238

Browse files
committed
add hashnode posts
1 parent 61fc822 commit b104238

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

‎backend/firebase/functions/src/hashnode/scheduledNotionToHashNode.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { sendTopic } from '../utilities/googleapis';
33
import {
44
queryPurrfectStreamHashnode,
55
patchPurrfectPage,
6+
queryByHashnode,
7+
getNotionPageMarkdown,
68
} from '../utilities/notion.server';
79
import { createPublicationStory } from '../utilities/hashnode';
810

@@ -24,6 +26,20 @@ export const scheduledNotionToHashnode = functions.pubsub
2426
await sendTopic(topicId, pod);
2527
}
2628
}
29+
30+
console.log('Checking for hashnode missing');
31+
const posts = await queryByHashnode('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,45 @@ export const hashnodeToNotionPubSub = functions.pubsub
3753

3854
let input;
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+
input = {
68+
title: page.title,
69+
subtitle: page.excerpt,
70+
slug: `${page._type}-${page.slug}`,
71+
contentMarkdown: post.content,
72+
coverImageURL: `https://media.codingcat.dev/image/upload/f_auto,c_limit,w_1920,q_auto/${page?.coverPhoto?.public_id}`,
73+
isRepublished: {
74+
originalArticleURL: `https://codingcat.dev/${page._type}/${page.slug}`,
75+
},
76+
tags: [
77+
{
78+
_id: '56744721958ef13879b94cad',
79+
name: 'JavaScript',
80+
slug: 'javascript',
81+
},
82+
{
83+
_id: '56744722958ef13879b94f1b',
84+
name: 'Web Development',
85+
slug: 'web-development',
86+
},
87+
{
88+
_id: '56744723958ef13879b955a9',
89+
name: 'Beginner Developers',
90+
slug: 'beginners',
91+
},
92+
],
93+
};
94+
break;
4095
case 'podcast':
4196
input = {
4297
title: page.title,

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,56 @@ export const queryByDevto = async (
473473
return await formatPosts(raw, _type, false, true);
474474
};
475475

476+
export const queryByHashnode = async (
477+
_type: string,
478+
page_size?: number,
479+
start_cursor?: string | null
480+
) => {
481+
const sorts: any = [
482+
{
483+
property: 'start',
484+
direction: 'ascending',
485+
},
486+
];
487+
const filter: any = {
488+
and: [
489+
{
490+
property: 'slug',
491+
url: {
492+
is_not_empty: true,
493+
},
494+
},
495+
{
496+
property: 'published',
497+
select: {
498+
equals: 'published',
499+
},
500+
},
501+
{
502+
property: 'hashnode',
503+
url: {
504+
is_empty: true,
505+
},
506+
},
507+
{
508+
property: 'start',
509+
date: {
510+
is_not_empty: true,
511+
},
512+
},
513+
],
514+
};
515+
516+
const raw = await notionClient.databases.query({
517+
database_id: getNotionDbByType(_type),
518+
start_cursor: start_cursor ? start_cursor : undefined,
519+
page_size,
520+
filter,
521+
sorts,
522+
});
523+
return await formatPosts(raw, _type, false, true);
524+
};
525+
476526
export const queryAll = async (
477527
_type: string,
478528
page_size?: number,

0 commit comments

Comments
 (0)