-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
97 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,44 @@ | ||
# notion-parse | ||
An NPM module for downloading and Notion content and saving it as Markdown for NextJS | ||
|
||
I use this to download my Notion content and save it as Markdown for my NextJS blog. It's a work in progress, but it's working for me so far. | ||
|
||
I also use ContentLayer to make sure my fontmatter has the right fields. | ||
|
||
## Usage | ||
|
||
Here is how I use the module in my NextJS project. | ||
|
||
```js | ||
|
||
// @ts-check | ||
|
||
const NotionParse = require('@kodaps/notion-parse'); | ||
const dotenv = require('dotenv'); | ||
|
||
dotenv.config(); | ||
|
||
const go = async () => { | ||
|
||
if (process.env.NOTION_TOKEN) { | ||
await NotionParse.parseNotion(process.env.NOTION_TOKEN, './src/content', [ | ||
{ databaseId: process.env.NOTION_PORTFOLIO_DATABASE_ID || '', contentType: 'Portfolio' }, | ||
{ databaseId: process.env.NOTION_NEWSLETTER_DATABASE_ID || '', contentType: 'Newsletter', languageField: 'lang' }, | ||
//{ databaseId: process.env.NOTION_PAGE_DATABASE_ID || '', contentType: 'Page', languageField: 'lang' }, | ||
{ databaseId: process.env.NOTION_POST_DATABASE_ID || '', contentType: 'Post', languageField: 'lang', filterFields: [ 'translation', 'createdAt', 'status', 'Type'] }, | ||
{ databaseId: process.env.NOTION_BITS_DATABASE_ID || '', contentType: 'Bit', languageField: 'lang' }, | ||
]) | ||
} | ||
|
||
}; | ||
|
||
go().then(() => { | ||
console.log('Done'); | ||
}); | ||
|
||
``` | ||
|
||
This supposed several things : | ||
1. that the files are stored in a subfolder of the folder passed in as parameter (here `./src/content`) based on the content type | ||
2. that the ContentLayer type names map to the subfolders. So for instance for the `Post` content type, the files will be stored in `./src/content/post` | ||
3. that the Notion token and database IDs are stored in environment variables, and that there is one database per content type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import { Client } from "@notionhq/client"; | ||
import { DatabaseObjectResponse, PageObjectResponse, PartialDatabaseObjectResponse, PartialPageObjectResponse } from "@notionhq/client/build/src/api-endpoints"; | ||
interface DocumentType { | ||
databaseId: string; | ||
languageField?: string; | ||
contentType: string; | ||
filterFields?: Array<string>; | ||
} | ||
declare const parseNotionPage: (page: PageObjectResponse | PartialPageObjectResponse | PartialDatabaseObjectResponse | DatabaseObjectResponse, contentType: string) => Promise<{ | ||
export declare const parseNotionPage: (page: PageObjectResponse | PartialPageObjectResponse | PartialDatabaseObjectResponse | DatabaseObjectResponse, contentType: string) => Promise<{ | ||
[key: string]: any; | ||
}>; | ||
declare const getDatabase: (notion: Client, database_id: string, contentType: string) => Promise<{ | ||
[key: string]: any; | ||
}[]>; | ||
declare const parseNotion: (token: string, contentRoot: string, contentTypes: Array<DocumentType>) => Promise<void>; | ||
export { getDatabase, parseNotionPage, parseNotion, }; | ||
export declare const parseNotion: (token: string, contentRoot: string, contentTypes: Array<DocumentType>) => Promise<void>; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters