Skip to content

Commit d2c646f

Browse files
authored
Intuitive notion plugin and timestamp, date, and time in object-transform (#28)
* improves notion * fix tests
1 parent 4d9a094 commit d2c646f

File tree

9 files changed

+1078
-39
lines changed

9 files changed

+1078
-39
lines changed

bun.lockb

4.81 KB
Binary file not shown.

docs/docs/plugins/distributors/notion.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,10 @@ The Notion plugin works seamlessly with the Object Transform plugin to map your
2828
"plugin": "@curatedotfun/object-transform",
2929
"config": {
3030
"mappings": {
31-
"Title": {
32-
"template": "{{title}} by {{author}}"
33-
},
34-
"URL": {
35-
"field": "url"
36-
},
37-
"Tags": {
38-
"field": "categories"
39-
},
40-
"Published": {
41-
"field": "publishDate"
42-
}
31+
"title": "{{title}} by {{author}}",
32+
"url": "{{source}}",
33+
"tags": "[{{categories}}]",
34+
"published": "{{createdAt}}"
4335
}
4436
}
4537
},
@@ -48,14 +40,20 @@ The Notion plugin works seamlessly with the Object Transform plugin to map your
4840
"plugin": "@curatedotfun/notion",
4941
"config": {
5042
"token": "your_integration_token",
51-
"databaseId": "your_database_id"
43+
"databaseId": "your_database_id",
44+
"fields": {
45+
"title": "title",
46+
"url": "url",
47+
"tags": "multi_select",
48+
"published": "date"
49+
}
5250
}
5351
}
5452
]
5553
}
5654
```
5755

58-
The Notion plugin will automatically format each property based on its value type:
56+
By default, the Notion plugin will automatically format each property based on its value type:
5957

6058
- **Strings** → Rich Text
6159
- **Dates** (or date strings) → Date
@@ -64,6 +62,8 @@ The Notion plugin will automatically format each property based on its value typ
6462
- **Arrays** → Multi-select
6563
- **Other types** → Rich Text (converted to string)
6664

65+
Although you should explicitly specify the field types using the `fields` configuration option (see below).
66+
6767
:::tip
6868
Design your database schema to match your transformed object structure. The plugin will create pages with properties matching your object's field names.
6969
:::
@@ -74,13 +74,47 @@ You need to specify:
7474

7575
- `token`: Notion Internal Integration Token
7676
- `databaseId`: Your database ID extracted from the URL
77+
- `fields`: A mapping of field names to Notion property types
7778

7879
```json
7980
{
8081
"plugin": "@curatedotfun/notion",
8182
"config": {
8283
"token": "secret_...", // Your Notion integration token
83-
"databaseId": "..." // Your Notion database ID
84+
"databaseId": "...", // Your Notion database ID
85+
"fields": {
86+
"title": "title",
87+
"description": "rich_text",
88+
"date": "date",
89+
"count": "number",
90+
"isPublished": "checkbox",
91+
"tags": "multi_select",
92+
"category": "select",
93+
"website": "url",
94+
"email": "email",
95+
"phone": "phone"
96+
}
8497
}
8598
}
8699
```
100+
101+
### Supported Property Types
102+
103+
The `fields` configuration allows you to explicitly specify how each field should be formatted in Notion. This gives you precise control over the data types and ensures your content is properly formatted in your Notion database.
104+
105+
For more information about Notion database properties, see the [Notion Database Properties documentation](https://www.notion.com/help/database-properties).
106+
107+
The following property types are supported:
108+
109+
| Property Type | Description |
110+
|---------------|-------------|
111+
| `title` | The main title of the page. Each page requires exactly one title property. |
112+
| `rich_text` | Formatted text content that can include styling. |
113+
| `date` | A date or date range value. |
114+
| `number` | A numeric value. |
115+
| `checkbox` | A boolean (true/false) value. |
116+
| `multi_select` | Multiple tags or categories from a predefined list. |
117+
| `select` | A single option from a predefined list. |
118+
| `url` | A web address link. |
119+
| `email` | An email address. |
120+
| `phone` | A phone number. |

docs/docs/plugins/transformers/object-transform.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The Object Transform plugin enables object-to-object mapping using [Mustache](ht
1212
- **Template-based Field Values**: Use Mustache templates to format each field's value
1313
- **Flexible Output Structure**: Define any number of output fields with custom names
1414
- **Array Support**: Handle array fields with direct mapping and array combinations
15+
- **Default Templates**: Built-in templates for common values like timestamps and formatted dates
1516

1617
## 📝 Usage
1718

@@ -122,8 +123,59 @@ Access nested properties using dot notation:
122123
}
123124
```
124125

126+
### Default Templates
127+
128+
The plugin provides built-in templates that generate values automatically:
129+
130+
| Template | Description | Example Output |
131+
|----------|-------------|----------------|
132+
| `{{timestamp}}` | Current timestamp in milliseconds | `1616155200000` |
133+
| `{{date}}` | Current date in YYYY-MM-DD format | `2025-03-19` |
134+
| `{{time}}` | Current time in HH:mm:ss format | `21:55:00` |
135+
136+
You can also customize the date and time formats:
137+
138+
```json
139+
{
140+
"mappings": {
141+
"created": "{{timestamp}}",
142+
"formattedDate": "{{date:yyyy/MM/dd}}",
143+
"longDate": "{{date:MMMM do, yyyy}}",
144+
"shortTime": "{{time:HH:mm}}"
145+
}
146+
}
147+
```
148+
149+
The format strings follow the [date-fns format](https://date-fns.org/v4.1.0/docs/format) pattern.
150+
151+
Default templates are case-insensitive, so `{{TIMESTAMP}}`, `{{Timestamp}}`, and `{{timestamp}}` all work the same way.
152+
125153
## 💡 Examples
126154

155+
### Using Default Templates
156+
157+
```json
158+
{
159+
"transform": {
160+
"plugin": "@curatedotfun/object-transform",
161+
"config": {
162+
"mappings": {
163+
"id": "post-{{timestamp}}",
164+
"title": "{{title}}",
165+
"content": "{{content}}",
166+
"metadata": {
167+
"createdAt": "{{timestamp}}",
168+
"formattedDate": "{{date:MMMM do, yyyy}}",
169+
"formattedTime": "{{time}}"
170+
}
171+
}
172+
}
173+
}
174+
}
175+
```
176+
177+
This will generate an object with a unique ID based on the current timestamp, along with formatted date and time values.
178+
127179
### Database Entry Transform
128180

129181
Transform a tweet into a database-compatible format:

packages/notion/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curatedotfun/notion",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"description": "Notion plugin for curatedotfun",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -34,7 +34,8 @@
3434
"scripts": {
3535
"build": "rspack build && tsc -p tsconfig.build.json",
3636
"dev": "rspack serve",
37-
"lint": "tsc --noEmit"
37+
"lint": "tsc --noEmit",
38+
"test": "vitest"
3839
},
3940
"dependencies": {
4041
"@notionhq/client": "^2.2.15"
@@ -43,6 +44,7 @@
4344
"@curatedotfun/types": "workspace:*",
4445
"@curatedotfun/utils": "workspace:*",
4546
"@rspack/cli": "latest",
46-
"typescript": "^5.0.0"
47+
"typescript": "^5.0.0",
48+
"vitest": "^3.0.7"
4749
}
4850
}

0 commit comments

Comments
 (0)