Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions __tests__/__fakes__/fakeDestination.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,15 @@ export class FakeDestinationRepository<T extends Page>
// no-op in fake repository for testing
return Promise.resolve();
}

async deletePagesInDatabaseByInternalId({
databaseId,
mkNotesInternalId,
}: {
databaseId: string;
mkNotesInternalId: string;
}): Promise<void> {
// no-op in fake repository for testing
return Promise.resolve();
}
}
27 changes: 27 additions & 0 deletions docs/content/docs/cli/guides/cli-commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ mk-notes sync -i <path> -d <notionUrl> -k <notionApiKey>

- `-l, --lock`: Lock the Notion page after syncing to prevent further editing. This is useful when you want to preserve the synchronized content and prevent accidental modifications.

- `-f, --flat`: **Database destination only** - Flattens the directory structure so all markdown files are created as direct children of the database, not nested as child pages. This option is only available when the destination is a Notion database. If used with a page destination, an error will be thrown.

### Destination Types

Mk Notes supports two types of destinations:
Expand Down Expand Up @@ -192,6 +194,31 @@ This command will:
2. Delete those existing pages
3. Create new pages as database items with the content from your markdown files

#### Flat Sync to a Database

```bash
mk-notes sync \
--input ./my-docs \
--destination https://notion.so/myworkspace/database-123456 \
--notion-api-key secret_abc123... \
--flat
```

The `--flat` option creates all markdown files as direct children of the database, ignoring the directory structure. This is useful when you want a flat list of all documents in your database without nested page hierarchies.

This command will:

1. Read all markdown files in the directory
2. Flatten the directory structure
3. Create all files as direct database items (no nested pages)
4. Each file becomes a separate database entry

<Callout type="warning" title="Database Only">

The `--flat` option only works with database destinations. If you try to use it with a page destination, MK Notes will throw an error.

</Callout>

## `preview-sync`

The `preview-sync` command lets you preview how your markdown files will be organized in Notion before actually performing the synchronization. This is useful for verifying the structure before making any changes.
Expand Down
39 changes: 39 additions & 0 deletions docs/content/docs/cli/guides/database-sync.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,45 @@ Clean sync only works for pages that have an `id` defined in their frontmatter.

</Callout>

### Flat Sync

By default, MK Notes preserves your directory structure when syncing to a database, creating nested pages for subdirectories. The `--flat` option flattens this structure, creating all markdown files as direct children of the database:

```bash
mk-notes sync \
--input ./docs \
--destination https://notion.so/myworkspace/database-123456 \
--notion-api-key secret_abc123... \
--flat
```

**When to use flat sync:**

- You want all documents at the same level in your database
- You prefer to organize using database views and filters rather than page hierarchies
- Your directory structure is just for file organization, not content hierarchy

**Example:**

With a directory structure like:
```
docs/
guides/
getting-started.md
advanced.md
api/
authentication.md
```

- **Without `--flat`**: Creates nested pages (guides → getting-started, advanced)
- **With `--flat`**: Creates all four files as direct database entries

<Callout type="warning" title="Database Only">

The `--flat` option only works with database destinations. Using it with a page destination will result in an error.

</Callout>

---

## Adding Custom Database Properties
Expand Down
Loading