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
New document for each page? #71
Comments
At the moment there is no such thing however this could be a feature in the upcoming release. If you have something in mind feel free to share |
I just hit on the same thing - trying to write all pages below a root page into a directory that directly mirrors the structure on Notion. Is there a simple way to discern blocks by page? |
At the moment the way it handles the child page is very different thereby making it difficult to save the child pages to a separate file. This definitely is an interesting use case and I'm working to change the way it deals with the child pages so it may take some time. Any contribution is appreciated. |
I solved this just now by doing the following: async function renderPage(id: string) {
const page = await notion.pages.retrieve({ page_id: id });
const blocks = await n2m.pageToMarkdown(page.id);
// Simple utility function to partition by predicate,
// sorting blocks into children pages and everything else.
// See here for my implementation:
// https://gist.github.com/Radiergummi/ccc83114df365bb5bfd0db619fe8e056
const [ childBlocks, markdownBlocks ] = partition(
blocks,
(block): block is Block => block.type === 'child_page',
);
// ... Process pages here ...
const content = n2m.toMarkdownString( markdownBlocks );
const children = await Promise.all(childBlocks.map(
async child => renderPage(child.blockId),
));
return { content, children }; This works by recursively processing pages, partitioning the blocks of a page into child pages and content blocks, then converting only the content blocks to markdown and recursively running the child page blocks through the render function again. I'm sure that could be somehow abstracted away at the library level, although I don't have a neat suggestion at hand right now. I hope this helps a bit, though. |
Does this work when the child pages are in a column block? |
@souvikinator no, it doesn't. Dang. Going to take a look at the responses and see what I can do to fix this. |
So that is where the issue is arising. Before the |
This feature should be live in the upcoming release. Feel free to reopen the issue. |
I finally got this working (thanks for your help!) but now I've discovered that it tries to put everything into a single markdown file. Is there a way to get it to create a new markdown file for each child page?
The text was updated successfully, but these errors were encountered: