gatsby-source-notion-api
Advanced tools
Comparing version
const { getPages } = require("./src/notion-api/get-pages") | ||
const { getNotionPageMD } = require("./src/transformers/get-page-md") | ||
const { getNotionPageProperties } = require("./src/transformers/get-page-properties") | ||
const { getNotionPageTitle } = require("./src/transformers/get-page-title") | ||
@@ -9,62 +12,16 @@ const NODE_TYPE = "Notion" | ||
) => { | ||
const { createNode } = actions | ||
const pages = await getPages( | ||
{ token: pluginOptions.token, databaseId: pluginOptions.databaseId }, | ||
reporter, | ||
) | ||
const data = { | ||
pages: await getPages(pluginOptions, reporter), | ||
} | ||
data.pages.forEach((page) => { | ||
const properties = Object.keys(page.properties).reduce((acc, key) => { | ||
if (page.properties[key].type == "title") { | ||
return acc | ||
} | ||
return { | ||
...acc, | ||
[key]: { | ||
id: page.properties[key].id, | ||
key, | ||
value: page.properties[key][page.properties[key].type], | ||
type: page.properties[key].type, | ||
}, | ||
} | ||
}, {}) | ||
const titleProperty = Object.keys(page.properties).find( | ||
(key) => page.properties[key].type == "title", | ||
) | ||
const title = page.properties[titleProperty].title.reduce((acc, chunk) => { | ||
if (chunk.type == "text") { | ||
return acc.concat(chunk.plain_text) | ||
} | ||
if (chunk.type == "mention") { | ||
if (chunk.mention.type == "user") { | ||
return acc.concat(chunk.mention.user.name) | ||
} | ||
if (chunk.mention.type == "date") { | ||
if (chunk.mention.date.end) { | ||
return acc.concat(`${chunk.mention.date.start} → ${chunk.mention.date.start}`) | ||
} | ||
return acc.concat(chunk.mention.date.start) | ||
} | ||
if (chunk.mention.type == "page") { | ||
return acc.concat(chunk.plain_text) | ||
} | ||
} | ||
return acc | ||
}, "") | ||
createNode({ | ||
pages.forEach((page) => { | ||
actions.createNode({ | ||
id: createNodeId(`${NODE_TYPE}-${page.id}`), | ||
title: title.trim(), | ||
properties, | ||
title: getNotionPageTitle(page), | ||
properties: getNotionPageProperties(page), | ||
archived: page.archived, | ||
createdAt: page.created_time, | ||
updatedAt: page.last_edited_time, | ||
markdown: getNotionPageMD(page), | ||
raw: page, | ||
@@ -71,0 +28,0 @@ parent: null, |
{ | ||
"name": "gatsby-source-notion-api", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Gatsby source plugin for official Notion.so API", | ||
@@ -36,3 +36,4 @@ "main": "index.js", | ||
"dependencies": { | ||
"node-fetch": "^2.6.1" | ||
"node-fetch": "^2.6.1", | ||
"or-pipets": "^1.0.1" | ||
}, | ||
@@ -39,0 +40,0 @@ "devDependencies": { |
@@ -93,8 +93,12 @@ <p align="center"> | ||
node { | ||
id | ||
parent | ||
children | ||
internal | ||
title | ||
properties | ||
archived | ||
achived | ||
createdAt | ||
updatedAt | ||
children | ||
markdown | ||
raw | ||
@@ -161,2 +165,6 @@ } | ||
### `markdown` (String) | ||
Markdown contents of the page. Limited by blocks currently supported by Notion API. Unsupported blocks turn into HTML comments specifying that Notion marked this block as non-supported. | ||
## Current state | ||
@@ -163,0 +171,0 @@ |
@@ -17,3 +17,3 @@ const fetch = require("node-fetch") | ||
try { | ||
await fetch(url, { | ||
const result = await fetch(url, { | ||
headers: { | ||
@@ -24,18 +24,16 @@ "Content-Type": "application/json", | ||
}, | ||
}) | ||
.then((res) => res.json()) | ||
.then(async (res) => { | ||
for (let childBlock of res.results) { | ||
if (childBlock.has_children) { | ||
childBlock[childBlock.type].children = await this.getBlocks( | ||
{ id: block.id, block: childBlock, notionVersion, token }, | ||
reporter, | ||
) | ||
} | ||
} | ||
}).then((res) => res.json()) | ||
blockContent = blockContent.concat(res.results) | ||
startCursor = res.next_cursor | ||
hasMore = res.has_more | ||
}) | ||
for (let childBlock of result.results) { | ||
if (childBlock.has_children) { | ||
childBlock.children = await this.getBlocks( | ||
{ id: childBlock.id, block: childBlock, notionVersion, token }, | ||
reporter, | ||
) | ||
} | ||
} | ||
blockContent = blockContent.concat(result.results) | ||
startCursor = result.next_cursor | ||
hasMore = result.has_more | ||
} catch (e) { | ||
@@ -42,0 +40,0 @@ reporter.panic(errorMessage) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
15314
32.05%12
50%227
71.97%182
4.6%2
100%2
100%+ Added
+ Added