Skip to content

Commit

Permalink
notion-pull --> notion-pull-mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
hatton committed Jul 22, 2022
1 parent 95d8d7a commit 74f34d8
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# notion-pull
# notion-pull-mdx

notion-pull lets you use Notion as your editor for markdown-based static site generators like [Docusaurus](https://docusaurus.io/). Using Notion instead of raw markdown files means that you don't have to teach non-developers how to make git commits and pull requests. It also allows you to leverage Notion's database tools to control workflow, Notion's commenting feature to discuss changes, etc.
notion-pull-mdx lets you use Notion as your editor for markdown-based static site generators like [Docusaurus](https://docusaurus.io/). Using Notion instead of raw markdown files means that you don't have to teach non-developers how to make git commits and pull requests. It also allows you to leverage Notion's database tools to control workflow, Notion's commenting feature to discuss changes, etc.

Example Site: https://sillsdev.github.io/notion-pull-sample-site/
Example Site: https://sillsdev.github.io/notion-pull-mdx-sample-site/

# Instructions

## 1. Set up your documentation site.

First, prepare your markdown-based static file system like [Docusaurus](https://docusaurus.io/). For a shortcut with github actions, search, and deployment to github pages, you can just copy [this template](https://github.com/sillsdev/notion-pull-sample-site).
First, prepare your markdown-based static file system like [Docusaurus](https://docusaurus.io/). For a shortcut with github actions, search, and deployment to github pages, you can just copy [this template](https://github.com/sillsdev/notion-pull-mdx-sample-site).

## 2. In Notion, duplicate the notion-pull template
## 2. In Notion, duplicate the notion-pull-mdx template

Go to [this template page](https://hattonjohn.notion.site/Documentation-Template-Docusaurus-0e998b32da3c47edad0f62a25b49818c). Duplicate it into your own workspace.
You can name it anything you like, e.g. "Documentation Root".

## 3. Create a Notion Integration

In order for notion-pull to read your site via Notion's API, you need to create what Notion calls an "integration". Follow [these instructions](https://developers.notion.com/docs/getting-started) to make an integration and get your token. Limit your integration to "READ" access.
In order for notion-pull-mdx to read your site via Notion's API, you need to create what Notion calls an "integration". Follow [these instructions](https://developers.notion.com/docs/getting-started) to make an integration and get your token. Limit your integration to "READ" access.

## 4. "Invite" your Notion Integration to read you page

Expand All @@ -27,7 +27,7 @@ In Notion, click "Share" on the root of your documentation and "invite" your int

## 5. Add your pages under your Outline page.

Currently, notion-pull expects that each page has only one of the following: subpages, links to other pages, or normal content. Do not mix them. You can add content pages directly here, but then you won't be able to make use of the workflow features. If those matter to you, instead make new pages under the "Database" and then link to them in your outline pages.
Currently, notion-pull-mdx expects that each page has only one of the following: subpages, links to other pages, or normal content. Do not mix them. You can add content pages directly here, but then you won't be able to make use of the workflow features. If those matter to you, instead make new pages under the "Database" and then link to them in your outline pages.

## 6. Pull your pages

Expand All @@ -38,24 +38,24 @@ means that the id is "0456aa5842946PRETEND4f37c97a0e5".
Determine where you want the markdown files and images to land. The following works well for Docusaurus instances:

```
npx notion-pull -n secret_PRETEND123456789PRETEND123456789PRETEND6789 -r 0456aa5842946PRETEND4f37c97a0e5 -m "./docs" -i "./images"
npx notion-pull-mdx -n secret_PRETEND123456789PRETEND123456789PRETEND6789 -r 0456aa5842946PRETEND4f37c97a0e5 -m "./docs" -i "./images"
```

Likely, you will want to store these codes in your environment variables and then use them like this:

```
(windows)
npx notion-pull -n %MY_NOTION_TOKEN% -r %MY_NOTION_DOCS_ROOT_PAGE_ID% -m "./docs" -i "./static/notion_images" -p "/notion_images/"
npx notion-pull-mdx -n %MY_NOTION_TOKEN% -r %MY_NOTION_DOCS_ROOT_PAGE_ID% -m "./docs" -i "./static/notion_images" -p "/notion_images/"
```

```
(linux / mac)
npx notion-pull -n $MY_NOTION_TOKEN -r $MY_NOTION_DOCS_ROOT_PAGE_ID -m "./docs" -i "./static/notion_images" -p "/notion_images/"
npx notion-pull-mdx -n $MY_NOTION_TOKEN -r $MY_NOTION_DOCS_ROOT_PAGE_ID -m "./docs" -i "./static/notion_images" -p "/notion_images/"
```

## 7. Commit

Most projects should probably commit the current markdown and image files each time you run notion-pull.
Most projects should probably commit the current markdown and image files each time you run notion-pull-mdx.

Note that if you choose not to commit, the workflow feature (see below) won't work for you. Imagine the case where a document that previously had a `Status` property of `Publish` now has a different status. You probably want to keep publishing the old version until the new one is ready. But if you don't commit files, your CI system (e.g. Github Actions) won't have the old version around, so it will disappear from your site.

Expand All @@ -65,17 +65,17 @@ One of the big attractions of Notion for large documentation projects is that yo

![image](https://user-images.githubusercontent.com/8448/168929745-e6529375-bb1e-47e9-b8a6-7a1467c8900f.png)

`notion-pull` supports this by letting you link to database pages from your outline.
`notion-pull-mdx` supports this by letting you link to database pages from your outline.

![image](https://user-images.githubusercontent.com/8448/168929668-f83d7c86-75d2-48e9-940c-84c5268a2854.png)

## Known Limitations

notion-pull is not doing anything smart with regards to previously Published but now not Published documents. All it does is ignore every Notion document that doesn't have `status == Publish`. So if the old version of the document is still in your file tree when your static site generator (e.g. Docusaurus) runs, then it will appear on your website. If it isn't there, it won't. If you rename directories or move the document, notion-pull will not realize this and will delete the previously published markdown file.
notion-pull-mdx is not doing anything smart with regards to previously Published but now not Published documents. All it does is ignore every Notion document that doesn't have `status == Publish`. So if the old version of the document is still in your file tree when your static site generator (e.g. Docusaurus) runs, then it will appear on your website. If it isn't there, it won't. If you rename directories or move the document, notion-pull-mdx will not realize this and will delete the previously published markdown file.

Links from one document to another in Notion are not yet converted to local links.

Notion-pull makes some attempt to keep the right order of things, but there are definitely cases where it isn't smart enough yet.
notion-pull-mdx makes some attempt to keep the right order of things, but there are definitely cases where it isn't smart enough yet.

# Localization

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "notion-pull",
"name": "notion-pull-mdx",
"version": "0.0.0-development",
"description": "Download Notion pages as markdown and image files, preserving hierarchy and enabling workflow properties. Works with Docusaurus.",
"main": "./dist/index.js",
Expand All @@ -20,7 +20,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/sillsdev/notion-pull.git"
"url": "git+https://github.com/sillsdev/notion-pull-mdx.git"
},
"license": "MIT",
"author": {
Expand All @@ -37,9 +37,9 @@
"markdown"
],
"bugs": {
"url": "https://github.com/sillsdev/notion-pull/issues"
"url": "https://github.com/sillsdev/notion-pull-mdx/issues"
},
"homepage": "https://github.com/sillsdev/notion-pull#readme",
"homepage": "https://github.com/sillsdev/notion-pull-mdx#readme",
"//file-type": "have to use this version before they switched to ESM, which gives a compile error related to require()",
"//node-fetch@2.6.6file-type": "have to use this version before they switched to ESM, which gives a compile error related to require()",
"//chalk@4": "also ESM related problem",
Expand Down
2 changes: 1 addition & 1 deletion src/DocusaurusTweaks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function notionEmbedsToMDX(input: string): {
regex: /\[.*\]\((http.*(\.(gif|GIF)))\)/gm,
...gif,
},
// This is included in notion-pull just because we built notion-pull for our own doc site, and it needs this.
// This is included in notion-pull-mdx just because we built notion-pull-mdx for our own doc site, and it needs this.
// bloomPUB: {
// regex: /\[.*\]\((.*bloomlibrary\.org.*.*book.*)\)/gm,
// // enhance: it would be nice if we could fill in the `host` parameter for analytics
Expand Down
2 changes: 1 addition & 1 deletion src/NotionPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const notionLimiter = new RateLimiter({
let notionClient: Client;

// Notion has 2 kinds of pages: a normal one which is just content, and what I'm calling a "database page", which has whatever properties you put on it.
// notion-pull supports the later via links from outline pages. That is, you put the database pages in a database, then separately, in the outline, you
// notion-pull-mdx supports the later via links from outline pages. That is, you put the database pages in a database, then separately, in the outline, you
// create pages for each node of the outline and then add links from those to the database pages. In this way, we get the benefits of database
// pages (metadata, workflow, etc) and also normal pages (order, position in the outline).
export enum PageType {
Expand Down
2 changes: 1 addition & 1 deletion src/css/notion-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
.notion-row {
display: grid;
grid-auto-flow: column;
/* at the moment, notion-pull doesn't give us column widths or ratios. So we
/* at the moment, notion-pull-mdx doesn't give us column widths or ratios. So we
could let css layout decide the widths. Instead at the moment we're saying
let's just have each column be equal. This is easier for the author using
Notion to remember than having to guess at what the layout will be. */
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { program } from "commander";
import { notionPull } from "./pull";
const pkg = require("../package.json");
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.log(`notion-pull version ${pkg.version}`);
console.log(`notion-pull-mdx version ${pkg.version}`);

program.name("notion-pull").description("");
program.name("notion-pull-mdx").description("");
program
.requiredOption("-n, --notion-token <string>", "notion api token")
.requiredOption(
Expand Down Expand Up @@ -35,5 +35,5 @@ program.showHelpAfterError();
program.parse();

void notionPull(program.opts()).then(() =>
console.log("Notion-pull Finished.")
console.log("notion-pull-mdx Finished.")
);
4 changes: 2 additions & 2 deletions src/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let notionToMarkdown: NotionToMarkdown;
const pages = new Array<NotionPage>();

export async function notionPull(options: any): Promise<void> {
// It's helpful when troubleshooting CI secrets and environment variables to see what options actually made it to notion-pull.
// It's helpful when troubleshooting CI secrets and environment variables to see what options actually made it to notion-pull-mdx.
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const optionsForLogging = { ...options };
// Just show the first few letters of the notion token, which start with "secret" anyhow.
Expand Down Expand Up @@ -101,7 +101,7 @@ async function getPagesRecursively(
if (!rootLevel && pageInfo.hasParagraphs && pageInfo.childPages.length) {
console.error(
error(
`Skipping "${pageInTheOutline.nameOrTitle}" and its children. Notion-pull does not support pages that are both levels and have content at the same time.`
`Skipping "${pageInTheOutline.nameOrTitle}" and its children. notion-pull-mdx does not support pages that are both levels and have content at the same time.`
)
);
return;
Expand Down

0 comments on commit 74f34d8

Please sign in to comment.