Skip to content

Commit 4e1ca0d

Browse files
committed
updated blocks code
1 parent 601f212 commit 4e1ca0d

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,8 @@ app.get("/blog/:slug", async (req,res) => {
10981098

10991099
console.log(parsedData)
11001100
const pageContent = await getBlocks(response.id)
1101-
const postHTML = parsePageContentHTML(pageContent)
1101+
let postHTML = parsePageContentHTML(pageContent)
1102+
console.log(postHTML)
11021103
res.render("blog/post", {title: parsedData.Name, postHTML:postHTML, ...parsedData})
11031104
})
11041105

@@ -2215,13 +2216,19 @@ function parseBlockIntoKeyedObject(block, contentObj) {
22152216
}
22162217
}
22172218
function parsePageContentHTML(data) {
2218-
let pageHTML = ""
2219+
let pageHTML = []
2220+
let htmlString = ""
22192221
let prevType = ""
22202222
console.log("parsing")
22212223
for (let i = 0; i < data.length; i++) {
2222-
pageHTML = parseBlockHTML(data[i], pageHTML, prevType)
2224+
htmlString = parseBlockHTML(data[i], htmlString, prevType)
2225+
if(htmlString.length > 10000){
2226+
pageHTML.push(htmlString)
2227+
htmlString = ""
2228+
}
22232229
prevType = data[i].type
22242230
}
2231+
pageHTML.push(htmlString)
22252232
return pageHTML
22262233
}
22272234

@@ -2239,7 +2246,7 @@ function parseBlockHTML(block, pageHTML, prevType) {
22392246
case 'heading_3':
22402247
// For a heading
22412248
console.log(block['heading_3'])
2242-
if(block['heading_3']?.text[0].plain_text?.indexOf("http") == 0){
2249+
if(block['heading_3']?.text[0]?.plain_text?.indexOf("http") == 0){
22432250
console.log("URL DETECTED")
22442251
return pageHTML += `<iframe src='${block['heading_3'].text[0].href}'></iframe>`
22452252
}

lib/notion.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,27 @@ exports.getPage = async (pageId) => {
3535
};
3636

3737
exports.getBlocks = async (blockId) => {
38-
const response = await notion.blocks.children.list({
39-
block_id: blockId,
40-
page_size: 1000,
41-
});
42-
return response.results;
38+
let allBlocks = []
39+
let cursor = undefined;
40+
41+
while (true) {
42+
const response = await notion.blocks.children.list({
43+
block_id: blockId,
44+
start_cursor: cursor,
45+
page_size: 100,
46+
});
47+
48+
allBlocks = allBlocks.concat(response.results);
49+
50+
if (!response.has_more) {
51+
break; // No more pages
52+
}
53+
54+
cursor = response.next_cursor;
55+
}
56+
57+
58+
return allBlocks;
4359
};
4460

4561
exports.createPage = async (database_id, title, message="") => {

public/templates/blog/post.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@
180180
{{/if}}
181181

182182

183-
{{{postHTML}}}
183+
{{#each postHTML}}{{{this}}}{{/each}}
184+
184185

185186

186187

0 commit comments

Comments
 (0)