Skip to content

Commit

Permalink
Make children optional
Browse files Browse the repository at this point in the history
  • Loading branch information
vojto committed Nov 3, 2023
1 parent 66ee9a7 commit 09094d0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/convertors/logseq/logseq-convertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class LogseqConvertor extends Convertor {
const subject = note['page-name']

// Get all the HTML and backlinks for the current note
const {html, backlinks} = this.parseBlocks(children)
const {html, backlinks} = this.parseBlocks(children ?? [])
// Update the backlinks with the note ids from the page name to id map
const updatedBacklinks = backlinks.map((b) => ({
label: b.label,
Expand Down Expand Up @@ -121,7 +121,7 @@ export class LogseqConvertor extends Convertor {
})

// If the block has children then we need to get the html for the children
if (block.children.length) {
if (block.children?.length) {
const {html: childHtml, backlinks: childBacklinks} = this.parseBlocks(
block.children,
)
Expand Down
6 changes: 3 additions & 3 deletions src/convertors/logseq/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const baseBlockSchema = z.object({
})

type BlockSchema = z.infer<typeof baseBlockSchema> & {
children: BlockSchema[]
children?: BlockSchema[]
}

const blockSchema: z.ZodType<BlockSchema> = baseBlockSchema.extend({
children: z.lazy(() => blockSchema.array()),
children: z.lazy(() => blockSchema.array()).optional(),
})

const noteSchema = z.object({
'page-name': z.string(),
id: z.string(),
properties: propertiesSchema.nullable(),
children: z.array(blockSchema),
children: z.array(blockSchema).optional(),
})

export const exportSchema = z.object({
Expand Down
6 changes: 3 additions & 3 deletions src/convertors/logseq/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface LogseqNote {
'page-name': string
id: string
properties: LogseqProperties | null
children: LogseqBlock[]
children?: LogseqBlock[]
}

export type LogseqProperties = Record<string, string | number | Array<string>>
Expand All @@ -21,11 +21,11 @@ export interface LogseqNoteBlock {
content: string
properties: LogseqProperties | null
id: string
children: LogseqBlock[]
children?: LogseqBlock[]
}

export interface LogseqWhiteboardBlock {
children: LogseqBlock[]
children?: LogseqBlock[]
}

export class LogseqConversionError extends ConversionError {
Expand Down

0 comments on commit 09094d0

Please sign in to comment.