Skip to content

Commit 242bfac

Browse files
authored
Merge pull request #4 from wiremind/feat/add-dry-run-and-fix-notion-block-generating
feat: add output file option for dry-run mode and improve error handling
2 parents 8c29032 + c8752ab commit 242bfac

File tree

7 files changed

+297
-44
lines changed

7 files changed

+297
-44
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,39 @@ go install github.com/wiremind/markdown-to-notionapi/cmd/notion-md@latest
3434

3535
4. **Upload Markdown**:
3636
```bash
37-
notion-md --page-id YOUR_PAGE_ID --md document.md
37+
md2notion --page-id YOUR_PAGE_ID --md document.md
3838
```
3939

4040
## Usage Examples
4141

4242
### Append to existing page
4343
```bash
44-
notion-md --page-id abc123def456 --md notes.md
44+
md2notion --page-id abc123def456 --md notes.md
4545
```
4646

4747
### Read from stdin
4848
```bash
49-
cat README.md | notion-md --page-id abc123def456
49+
cat README.md | md2notion --page-id abc123def456
5050
```
5151

5252
### Replace page content
5353
```bash
54-
notion-md --page-id abc123def456 --md document.md --replace
54+
md2notion --page-id abc123def456 --md document.md --replace
5555
```
5656

5757
### Create new page
5858
```bash
59-
notion-md --create --parent-id xyz789 --title "My Document" --md notes.md
59+
md2notion --create --parent-id xyz789 --title "My Document" --md notes.md
6060
```
6161

6262
### Dry run (preview JSON)
6363
```bash
64-
notion-md --page-id abc123def456 --md notes.md --dry-run
64+
md2notion --page-id abc123def456 --md notes.md --dry-run
6565
```
6666

6767
### Handle relative images
6868
```bash
69-
notion-md --page-id abc123def456 --md notes.md --image-base-url "https://example.com/assets/"
69+
md2notion --page-id abc123def456 --md notes.md --image-base-url "https://example.com/assets/"
7070
```
7171

7272
## Supported Markdown
@@ -89,7 +89,7 @@ notion-md --page-id abc123def456 --md notes.md --image-base-url "https://example
8989
## Command Line Options
9090

9191
```
92-
Usage: notion-md [options]
92+
Usage: md2notion [options]
9393
9494
Options:
9595
--page-id string Notion page ID to append blocks to (required unless --create is set)
@@ -103,7 +103,7 @@ Options:
103103
--dry-run Print JSON that would be sent, don't call API
104104
--notion-version string Notion API version (default "2022-06-28")
105105
-v, --verbose Verbose output
106-
--timeout duration HTTP request timeout (default 15s)
106+
--timeout duration HTTP request timeout (default 1000s)
107107
-h, --help Show help
108108
109109
Environment Variables:

cmd/notion-md/main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
const (
1515
defaultNotionVersion = "2022-06-28"
16-
defaultTimeout = 15 * time.Second
16+
defaultTimeout = 1000 * time.Second
1717
)
1818

1919
func main() {
@@ -30,6 +30,7 @@ func main() {
3030
flag.BoolVar(&config.Create, "create", false, "Create a new page")
3131
flag.StringVar(&config.ImageBaseURL, "image-base-url", "", "Base URL for relative image paths")
3232
flag.BoolVar(&config.DryRun, "dry-run", false, "Print JSON that would be sent, don't call API")
33+
flag.StringVar(&config.OutputFile, "output-file", "", "File to write dry-run output to (default: stdout)")
3334
flag.StringVar(&config.NotionVersion, "notion-version", defaultNotionVersion, "Notion API version")
3435
flag.BoolVar(&config.Verbose, "v", false, "Verbose output")
3536
flag.BoolVar(&config.Verbose, "verbose", false, "Verbose output")
@@ -44,10 +45,12 @@ func main() {
4445
fmt.Fprintf(os.Stderr, " %s --page-id abc123 --md document.md\n", os.Args[0])
4546
fmt.Fprintf(os.Stderr, " cat notes.md | %s --page-id abc123\n", os.Args[0])
4647
fmt.Fprintf(os.Stderr, " %s --create --parent-id xyz789 --title \"My Document\" --md notes.md\n", os.Args[0])
48+
fmt.Fprintf(os.Stderr, " %s --dry-run --md document.md\n", os.Args[0])
49+
fmt.Fprintf(os.Stderr, " %s --dry-run --md document.md --output-file output.json\n", os.Args[0])
4750
fmt.Fprintf(os.Stderr, "\nOptions:\n")
4851
flag.PrintDefaults()
4952
fmt.Fprintf(os.Stderr, "\nEnvironment Variables:\n")
50-
fmt.Fprintf(os.Stderr, " NOTION_TOKEN Notion integration token (required)\n")
53+
fmt.Fprintf(os.Stderr, " NOTION_TOKEN Notion integration token (required unless --dry-run is used)\n")
5154
fmt.Fprintf(os.Stderr, "\nSupported Markdown:\n")
5255
fmt.Fprintf(os.Stderr, " - Headings (# ## ###)\n")
5356
fmt.Fprintf(os.Stderr, " - Paragraphs with **bold**, *italic*, `code`, ~~strikethrough~~, [links](url)\n")
@@ -72,9 +75,10 @@ func main() {
7275

7376
// Get Notion token from environment
7477
notionToken := os.Getenv("NOTION_TOKEN")
75-
if notionToken == "" {
78+
if notionToken == "" && !config.DryRun {
7679
fmt.Fprintf(os.Stderr, "Error: NOTION_TOKEN environment variable is required\n")
7780
fmt.Fprintf(os.Stderr, "Get your token from: https://www.notion.so/my-integrations\n")
81+
fmt.Fprintf(os.Stderr, "Note: Use --dry-run flag to test conversion without API token\n")
7882
os.Exit(1)
7983
}
8084

dist/md2notion

84 KB
Binary file not shown.

0 commit comments

Comments
 (0)