Skip to content

Commit

Permalink
fix incorrect markdown body
Browse files Browse the repository at this point in the history
  • Loading branch information
FranciscoMoretti committed Jul 24, 2024
1 parent df9de34 commit 888ea42
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
16 changes: 12 additions & 4 deletions packages/cli/src/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export type DocuNotionOptions = {
}

let layoutStrategy: LayoutStrategy
let notionToMarkdown: NotionToMarkdown

const counts = {
output_normally: 0,
Expand Down Expand Up @@ -75,7 +74,7 @@ export async function notionPull(options: DocuNotionOptions): Promise<void> {
auth: options.notionToken,
})

notionToMarkdown = new NotionToMarkdown({
const notionToMarkdown = new NotionToMarkdown({
notionClient: cachedNotionClient,
})

Expand Down Expand Up @@ -168,7 +167,14 @@ export async function notionPull(options: DocuNotionOptions): Promise<void> {
group(
`Stage 2: convert ${pages.length} Notion pages to markdown and convertNotionLinkToLocalDocusaurusLink locally...`
)
await outputPages(options, config, pages, cachedNotionClient)
await outputPages(
options,
config,
pages,
cachedNotionClient,
layoutStrategy,
notionToMarkdown
)
endGroup()
group("Stage 3: clean up old files & images...")
await layoutStrategy.cleanupOldFiles()
Expand All @@ -180,7 +186,9 @@ async function outputPages(
options: DocuNotionOptions,
config: IDocuNotionConfig,
pages: Array<NotionPage>,
client: Client
client: Client,
layoutStrategy: LayoutStrategy,
notionToMarkdown: NotionToMarkdown
) {
const context: IDocuNotionContext = {
getBlockChildren: (id: string) => getBlockChildren(id, client),
Expand Down
21 changes: 9 additions & 12 deletions packages/cli/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,15 @@ async function doNotionToMarkdown(
docunotionContext: IDocuNotionContext,
blocks: Array<NotionBlock>
) {
let mdBlocks: any
await (async () => {
mdBlocks = await docunotionContext.notionToMarkdown.blocksToMarkdown(
// We need to provide a copy of blocks.
// Calling blocksToMarkdown can modify the values in the blocks. If it does, and then
// we have to retry, we end up retrying with the modified values, which
// causes various issues (like using the transformed image url instead of the original one).
// Note, currently, we don't do anything else with blocks after this.
// If that changes, we'll need to figure out a more sophisticated approach.
JSON.parse(JSON.stringify(blocks))
)
})
let mdBlocks = await docunotionContext.notionToMarkdown.blocksToMarkdown(
// We need to provide a copy of blocks.
// Calling blocksToMarkdown can modify the values in the blocks. If it does, and then
// we have to retry, we end up retrying with the modified values, which
// causes various issues (like using the transformed image url instead of the original one).
// Note, currently, we don't do anything else with blocks after this.
// If that changes, we'll need to figure out a more sophisticated approach.
JSON.parse(JSON.stringify(blocks))
)

const markdown =
docunotionContext.notionToMarkdown.toMarkdownString(mdBlocks).parent || ""
Expand Down

0 comments on commit 888ea42

Please sign in to comment.