Skip to content

A CLI for saving code snippets to a Notion page directly from your editor.

Notifications You must be signed in to change notification settings

mnfwu/save-to-notion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

save-to-notion

A CLI for saving code snippets to a Notion page directly from your editor.

Download dependencies

Run npm i in the root of the project to download dependencies.

Link for console command

In the root, run npm link . to gain access to the stn command in your terminal.

Create an integration at Notion

For save-to-notion to work, you'll need an integration token from Notion. Follow step 1 in the Notion Developers 'Getting Started' guide to set this up.

Get your Notion page ID

You'll also need to provide a page ID. save-to-notion will send your code snippet to this page. You can find your page ID by 'Sharing' your page to the web, then taking the alphanumeric section of the URL. For instance, your link may look like:

https://www.notion.so/My-Sample-Page-abcd1234zyxw0987qwertyuuiop

In this case, "abcd1234zyxw0987qwertyuuiop" would be your page ID.

Set .env variables and programming language.

Add a .env file to the root folder and add two keys: "INTEGRATION_TOKEN" and "PAGE_ID". Set them equal to your Notion integration token and page ID, respectively. If these variables are not present, save-to-notion will prompt you to enter them via the command line. You can do this when setting up your .env variables for the first time instead of creating a .env file. Currently, the only way to change the page ID is to manually change it in the .env file.

INTEGRATION_TOKEN=poiuytrewq12345678
PAGE_ID=abcd1234zyxw0987qwertyuuiop

You also need to select a programming language. The easiest way to do this is to run stn -l. Alternatively, you can set the CODE_LANG .env variable yourself.

You're good to go!

Place an in line comment (e.g. // stn, # stn, etc.) at the start of where you would like to copy, place a closing in line comment (e.g // stnend, # stnend) at the end. Then run .stn [filepath] in your console. save-to-notion will automatically create a block containing that code in your Notion page.

// stn
const exampleFn = () => {
  return "hello save-to-notion";
};
// stnend

Options

-h Help
-l Set programming language

Note: stn currently supports Javascript, Python, Ruby, Rust, Go, Java, C++, HTML, and CSS.

About

A CLI for saving code snippets to a Notion page directly from your editor.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published