Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example to parse any block text #416

Merged
merged 7 commits into from
Jul 18, 2023
Merged

Add example to parse any block text #416

merged 7 commits into from
Jul 18, 2023

Conversation

jessmitch42
Copy link
Contributor

@jessmitch42 jessmitch42 commented Jul 3, 2023

Adds example of how to parse the text from any type of block that is currently supported by the public API. This example includes retrieving the block children for a page (notion.blocks.children.list()) and parsing the text from each block returned. The text is then printed to the command line.
The page used can be set in the .env file, along with the integration key.
This example is not intended to have any "real-word" application other than providing devs with some helpful functions to use in their own Notion apps.
Based on a request to support customers looking for help with this.
Note: I tried to prioritize readability over making it as succinct as possible.

@jessmitch42 jessmitch42 added the examples Issues related to `examples` label Jul 3, 2023
@jessmitch42 jessmitch42 self-assigned this Jul 3, 2023
@jessmitch42 jessmitch42 changed the title Add block type example Add example to parse any block text Jul 3, 2023
@jessmitch42 jessmitch42 requested a review from a team July 6, 2023 20:13
rhart92
rhart92 previously approved these changes Jul 17, 2023
Copy link
Contributor

@rhart92 rhart92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments but looks good 👍

examples/parse-text-from-any-block-type/index.js Outdated Show resolved Hide resolved
examples/parse-text-from-any-block-type/index.js Outdated Show resolved Hide resolved
examples/parse-text-from-any-block-type/index.js Outdated Show resolved Hide resolved
examples/parse-text-from-any-block-type/index.js Outdated Show resolved Hide resolved
async function retrieveBlockChildren(id) {
console.log("Retrieving blocks (async)...")

const blocks = await notion.blocks.children.list({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include pagination here? We have a helper called iteratePaginatedAPI included in the SDK 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh cool, thanks! I'll add it

Copy link
Contributor Author

@jessmitch42 jessmitch42 Jul 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! Thanks for the review. 🙏 Looks like it needs another approval to merge so I re-requested another one.

@jessmitch42 jessmitch42 requested a review from rhart92 July 18, 2023 14:52
@rhart92 rhart92 merged commit 15f21c5 into makenotion:main Jul 18, 2023
rhart92 pushed a commit that referenced this pull request Oct 3, 2023
* add block text example

* clean up comments

* add embed option

* update comment:

* pr feeedback: name change, updated switch case, join richtext array without comma

* use iteratePaginatedAPI helper to capture all blocks on page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Issues related to `examples`
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants