Skip to content
Open
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NOTION_API_SECRET=your_notion_api_token_here
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ dist-ssr
*.njsproj
*.sln
*.sw?

.env

notion-data
public/notion-data
154 changes: 120 additions & 34 deletions README-KR.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,145 @@
# notion-dump
# NotionPresso CLI

Notion 페이지의 데이터를 추출하여 로컬에 JSON 형식으로 저장하는 CLI 도구입니다.

## 기능
## 주요 기능

- Notion 페이지의 전체 데이터를 JSON 파일로 저장
- 간단한 명령어로 Notion 페이지 데이터 백업
- **모든 페이지 자동 추출**: `--all` 옵션으로 권한 있는 모든 페이지 일괄 처리
- **개별 페이지 추출**: 특정 페이지 URL로 단일 페이지 처리
- **환경변수 지원**: `.env` 파일에서 API 키 자동 읽기
- **스마트 파일명**: 페이지 제목 기반의 읽기 쉬운 파일명 생성
- **이미지 다운로드**: 페이지 내 이미지 자동 다운로드 및 로컬 저장
- **북마크 메타데이터**: 확장된 북마크 정보 추출
- **선택적 업데이트**: 변경된 페이지만 자동으로 감지하여 업데이트

## 설치

현재 `notion-dump`는 npm에 배포되지 않았습니다. 로컬에서 직접 사용하려면 아래의 단계를 따라주세요.
### npm 설치

1. 프로젝트 클론 및 디렉토리 이동
```bash
npm install -g @notionpresso/cli
```

```bash
git clone https://github.com/notionpresso/cli.git
```
### 로컬 빌드

2. 의존성 설치
```bash
git clone https://github.com/notionpresso/cli.git
cd cli
npm install
npm run build
```

```bash
npm install
```
## 사용 방법

3. 프로젝트 빌드
```bash
npm run build
```
### 1. 환경변수 설정 (권장)

## 사용 방법
프로젝트 루트에 Notion API 토큰을 포함한 `.env` 파일을 생성하세요:

```bash
echo "NOTION_API_SECRET=secret_your_internal_integration_secret_here" > .env
```

> 💡 **API 토큰 얻는 방법:**
>
> 1. [Notion 통합 페이지](https://www.notion.so/my-integrations) 방문
> 2. 새 통합 생성 또는 기존 통합 선택
> 3. "Internal Integration Token" 복사 (`secret_`으로 시작)
> 4. 노션 페이지를 해당 통합과 공유

### 2. 모든 페이지 추출

```bash
npresso --all
```

1. Notion API 토큰 발급받기
2. 통합을 Notion 페이지에 연결하기
3. Notion 페이지 URL 얻기
4. 스크립트 실행
```bash
node ./dist/notionpresso.es.js --page <NotionPageURL> --auth <YourAPIToken>
```
### 3. 개별 페이지 추출

## 옵션 설명
```bash
npresso --page <NotionPageURL>

- `--page`: (필수) Notion 페이지의 URL
- `--auth`: (필수) Notion API 통합의 토큰
# 토큰을 직접 지정하는 경우
npresso --page <NotionPageURL> --auth <YourAPIToken>
```

## 명령어 옵션

- `--all`: 권한 있는 모든 페이지를 자동으로 찾아 추출
- `--page <pageUrl>`: 특정 페이지 URL 또는 ID 지정
- `--auth <token>`: Notion API 토큰 (환경변수 `NOTION_API_SECRET` 사용 권장)
- `--output-dir <dir>`: JSON 파일 출력 디렉토리 (기본값: `notion-data`)
- `--image-dir <dir>`: 이미지 파일 출력 디렉토리 (기본값: `public/notion-data`)

## 출력 결과

- 현재 작업 디렉토리에 `content/[page-id]/index.json` 파일이 생성됩니다.
- `content` 폴더가 없으면 자동으로 생성됩니다.
- 동일한 페이지 ID의 파일이 이미 있으면 덮어쓰기됩니다.
### 파일 구조

```
notion-data/
├── pages.json ← 모든 페이지 목록 (--all 사용시)
├── my-blog-post.json ← 개별 페이지 데이터 (제목 기반 파일명)
└── about-me.json

public/notion-data/
├── my-blog-post/ ← 페이지별 이미지 폴더
│ ├── image1.png
│ └── image2.jpg
└── about-me/
└── profile.jpg
```

### pages.json 형식

```json
{
"pages": [
{
"id": "page-id",
"title": "My Blog Post",
"last_edited_time": "2024-01-01T10:00:00.000Z",
"fileName": "my-blog-post"
}
]
}
```

## 사용 예시

### 초기 설정

```bash
# 1. API 키 설정
echo "NOTION_API_SECRET=secret_your_internal_integration_secret_here" > .env

# 2. 모든 페이지 추출
npresso --all
```

### 개별 페이지 처리

```bash
npresso --page https://notion.so/user/My-Page-abc123def456
```

### 커스텀 디렉토리

```bash
npresso --all --output-dir custom-data --image-dir assets/images
```

## 주요 개선사항

- ✅ **자동 페이지 발견**: Search API로 수동 URL 입력 불필요
- ✅ **읽기 쉬운 파일명**: ID 대신 페이지 제목 기반 파일명
- ✅ **환경변수 지원**: 매번 토큰 입력 불필요
- ✅ **이미지 다운로드**: 완전한 오프라인 백업
- ✅ **증분 업데이트**: 변경된 페이지만 처리로 빠른 동기화
- ✅ **페이지 목록 생성**: 프론트엔드 연동용 `pages.json` 제공

## 주의사항

- 이미지 다운로드 기능은 아직 구현되지 않았습니다.
- 출력 디렉토리와 파일명은 기본값으로 설정되며, 사용자 지정 옵션은 지원하지 않습니다.
- Notion 데이터베이스 추출 기능은 지원하지 않습니다.
- Notion API의 Search 기능 사용으로 모든 페이지가 발견되지 않을 수 있음
- 페이지가 통합(integration)과 공유되어 있어야 접근 가능
- 대량의 페이지 처리시 시간이 소요될 수 있음

## 기여

Expand Down
150 changes: 150 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# NotionPresso CLI

A CLI tool to extract Notion page data and save it locally in JSON format.

## Key Features

- **Automatic Page Discovery**: Extract all accessible pages with `--all` option
- **Individual Page Extraction**: Process specific pages using URL
- **Environment Variable Support**: Auto-read API keys from `.env` file
- **Smart File Naming**: Readable file names based on page titles
- **Image Download**: Automatic download and local storage of page images
- **Bookmark Metadata**: Extended bookmark information extraction
- **Smart Updates**: Selective updates for changed pages only

## Installation

### npm Installation

```bash
npm install -g @notionpresso/cli
```

### Local Build

```bash
git clone https://github.com/notionpresso/cli.git
cd cli
npm install
npm run build
```

## Usage

### 1. Environment Setup (Recommended)

Create a `.env` file in your project root with your Notion API token:

```bash
echo "NOTION_API_SECRET=secret_your_internal_integration_secret_here" > .env
```

> 💡 **How to get your API token:**
>
> 1. Go to [Notion Integrations](https://www.notion.so/my-integrations)
> 2. Create a new integration or select existing one
> 3. Copy the "Internal Integration Token" (starts with `secret_`)
> 4. Share your Notion pages with the integration

### 2. Extract All Pages

```bash
npresso --all
```

### 3. Extract Individual Page

```bash
npresso --page <NotionPageURL>

# With direct token specification
npresso --page <NotionPageURL> --auth <YourAPIToken>
```

## Command Options

- `--all`: Automatically find and extract all accessible pages
- `--page <pageUrl>`: Specify a particular page URL or ID
- `--auth <token>`: Notion API token (recommend using `NOTION_API_SECRET` env var)
- `--output-dir <dir>`: JSON file output directory (default: `notion-data`)
- `--image-dir <dir>`: Image file output directory (default: `public/notion-data`)

## Output Structure

### File Structure

```
notion-data/
├── pages.json ← List of all pages (when using --all)
├── my-blog-post.json ← Individual page data (title-based filename)
└── about-me.json

public/notion-data/
├── my-blog-post/ ← Per-page image folder
│ ├── image1.png
│ └── image2.jpg
└── about-me/
└── profile.jpg
```

### pages.json Format

```json
{
"pages": [
{
"id": "page-id",
"title": "My Blog Post",
"last_edited_time": "2024-01-01T10:00:00.000Z",
"fileName": "my-blog-post"
}
]
}
```

## Usage Examples

### Initial Setup

```bash
# 1. Set API key
echo "NOTION_API_SECRET=secret_your_internal_integration_secret_here" > .env

# 2. Extract all pages
npresso --all
```

### Individual Page Processing

```bash
npresso --page https://notion.so/user/My-Page-abc123def456
```

### Custom Directories

```bash
npresso --all --output-dir custom-data --image-dir assets/images
```

## Key Improvements

- ✅ **Automatic Page Discovery**: No manual URL input needed with Search API
- ✅ **Readable File Names**: Title-based filenames instead of IDs
- ✅ **Environment Variable Support**: No need to input token every time
- ✅ **Image Download**: Complete offline backup
- ✅ **Incremental Updates**: Fast sync by processing only changed pages
- ✅ **Page List Generation**: `pages.json` for frontend integration

## Limitations

- Notion API Search functionality may not discover all pages
- Pages must be shared with the integration to be accessible
- Processing large numbers of pages may take time

## Contributing

Contributions are welcome! Please see the [Contributing Guide](./CONTRIBUTING.md) for details.

## License

MIT License
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{
"name": "@notionpresso/cli",
"private": false,
"version": "0.0.2",
"version": "0.0.3",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"test": "vitest",
"prepare": "ts-patch install && typia patch"
"prepare": "ts-patch install && typia patch",
"cli": "node dist/notionpresso.es.js"
},
"devDependencies": {
"@ryoppippi/unplugin-typia": "^1.0.6",
"@types/node": "^22.7.7",
"dotenv": "^17.2.1",
"ts-patch": "^3.2.1",
"typescript": "^5.6.2",
"typia": "^6.10.2",
Expand Down
Loading