Skip to content

๐Ÿ”€ Convert markdown files to notion database. The folder structure is also fully represented as tags in notion.

License

Notifications You must be signed in to change notification settings

Rujuu-prog/markdown2notion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

56 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

markdown2notion

npm version License: MIT codecov

Convert markdown files to notion database. The folder structure is also fully represented as tags in notion.

Please refer to here for how to issue notion token and how to link with DB.

๐Ÿ”— Links

ๆ—ฅๆœฌ่ชžใฎ่ชฌๆ˜Žๆ›ธ๐Ÿ‘‰JP-README.md

๐Ÿ”ฝ Installation

npm install markdown2notion
yarn add markdown2notion

๐Ÿ”ง Usage

javascript and typescript are supported.

markdownToNotion()

import {markdownToNotion} from 'markdown2notion'

async function main(){
    try{
        await markdownToNotion(
        'notion token',
        'notion database id', 
        'markdown folder path', 
        'Column of notion displaying file names. Default is Title', 
        'Column of notion displaying folder name as tag. Default is Tags'
        )
    } catch (error) {
        console.error(error);
    }
}

searchPage()

Since the URL of the page changes every time you use markdownToNotion(), if you want to do something with the URL, please use this function to get the URL of the page.

import {searchPage} from 'markdown2notion'

async function main(){
  try{
      const result = await searchPage(
      'notion token',
      'notion database id', 
      'Column of notion displaying file names. Default is Title', 
      'Column of notion displaying folder name as tag. Default is Tags',
      'search file name',
      'search tags name array'
      )
      // If files with the same filename exist, multiple pages are returned.
      console.log(result)// The object of the notion page is returned. url can be taken from result['results'][0]['url'] or something like that.
  } catch (error) {
      console.error(error);
  }
}

๐Ÿ”ฐ Example

๐Ÿ”ฝmarkdownToNotion()

markdown folder structure

โ”œโ”€โ”€ docs
โ”‚   โ”œโ”€โ”€ sample1
โ”‚   โ”‚   โ”œโ”€โ”€ sample1_1
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ sampleContent1_1.md
โ”‚   โ”‚   โ”œโ”€โ”€ sampleContent1.md
โ”‚   โ”œโ”€โ”€ sample2
โ”‚   โ”‚   โ”œโ”€โ”€ sampleContent2.md
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ index.ts
โ”œโ”€โ”€ .env

notion DB

markdown files

Sample Markdown Folder

index.ts

import {markdownToNotion} from 'markdown2notion'
import * as dotenv from 'dotenv'

async function main() {
    dotenv.config()
    const token = process.env.NOTION_TOKEN
    const databaseId = process.env.NOTION_DATABASE_ID
    try {
      await markdownToNotion(token, databaseId, 'docs', 'Title', 'Tags');
    } catch (error) {
      console.error(error);
    }
}

main()

.env

NOTION_TOKEN=secret_xxxxxxxxxxxxxx
NOTION_DATABASE_ID=xxxxxxxxxxxxxxx

Result

The folder name becomes a tag.

Filtering using tags makes it easier to access specific files.

๐Ÿ”ฝsearchPage()

index.ts

import {searchPage} from 'markdown2notion'
import * as dotenv from 'dotenv'

async function main() {
    dotenv.config()
    const token = process.env.NOTION_TOKEN
    const databaseId = process.env.NOTION_DATABASE_ID
    const title = 'sampleContent1_1';
    const tags = ['sample1_1'];

    try {
      const result = await searchPage(token, databaseId, 'Title', 'Tags', title, tags);
      console.log(result['results'][0]['url']);
    } catch (error) {
      console.error('Error searching for page:', error);
    }
}

main()

result

{
  object: 'list',
  results: [
    {
      object: 'page',
      id: '33.....',
      created_time: '2023-03-29T14:15:00.000Z',
      last_edited_time: '2023-03-29T14:15:00.000Z',
      created_by: [Object],
      last_edited_by: [Object],
      cover: null,
      icon: null,
      parent: [Object],
      archived: false,
      properties: [Object],
      url: 'https://www.notion.so/sampleContent1_1-33...'
    }
  ],
  next_cursor: null,
  has_more: false,
  type: 'page',
  page: {}
}

๐Ÿ‘€ Important Point

If there is a page with the same filename on the DB of notion to be operated on, it will be overwritten.

License

MIT