Skip to content

Commit c7c302b

Browse files
committed
Merge branch 'main' into release
2 parents 20f2d27 + 0fe6659 commit c7c302b

File tree

3 files changed

+130
-6
lines changed

3 files changed

+130
-6
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ You can name it anything you like, e.g. "Documentation Root".
1717

1818
## 3. Create a Notion Integration
1919

20-
In order for docu-notion 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.
20+
In order for docu-notion 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. Remember to limit your integration to "READ" access.
2121

22-
## 4. "Invite" your Notion Integration to read you page
22+
## 4. Connect your Integration
2323

24-
In Notion, click "Share" on the root of your documentation and "invite" your integration to it.
24+
Go to the page that will be the root of your site. This page should have, as direct children, your "Outline" (required) and "Database" (optional) pages. Follow [these instructions](https://developers.notion.com/docs/create-a-notion-integration#give-your-integration-page-permissions).
2525

26-
![image](https://user-images.githubusercontent.com/8448/168930238-1dcf46df-a690-4839-bf4c-c63157f104d8.png)
26+
<img width="318" alt="image" src="https://github.com/sillsdev/docu-notion/assets/8448/810c6dca-f9ab-4370-93b4-dc1479332af7">
2727

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

@@ -35,7 +35,7 @@ First, determine the id of your root page by clicking "Share" and looking at the
3535
https://www.notion.so/hattonjohn/My-Docs-0456aa5842946bdbea3a4f37c97a0e5
3636
means that the id is "0456aa5842946PRETEND4f37c97a0e5".
3737

38-
Determine where you want the markdown files and images to land. The following works well for Docusaurus instances:
38+
Try it out:
3939

4040
```
4141
npx @sillsdev/docu-notion -n secret_PRETEND123456789PRETEND123456789PRETEND6789 -r 0456aa5842946PRETEND4f37c97a0e5"

src/latex.spec.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import { NotionToMarkdown } from "notion-to-md";
2+
import { HierarchicalNamedLayoutStrategy } from "./HierarchicalNamedLayoutStrategy";
3+
import { LayoutStrategy } from "./LayoutStrategy";
4+
import { NotionPage } from "./NotionPage";
5+
6+
import { getMarkdownFromNotionBlocks } from "./transform";
7+
8+
import { IDocuNotionContext } from "./plugins/pluginTypes";
9+
import { convertInternalUrl } from "./plugins/internalLinks";
10+
11+
import { initNotionClient } from "./pull";
12+
import { NotionBlock } from "./types";
13+
14+
import { IDocuNotionConfig } from "./config/configuration";
15+
16+
import defaultConfig from "./config/default.docunotion.config";
17+
18+
test("Latex Rendering", async () => {
19+
const pages = new Array<NotionPage>();
20+
const counts = {
21+
output_normally: 0,
22+
skipped_because_empty: 0,
23+
skipped_because_status: 0,
24+
skipped_because_level_cannot_have_content: 0,
25+
};
26+
27+
const notionClient = initNotionClient("");
28+
29+
const layoutStrategy = new HierarchicalNamedLayoutStrategy();
30+
31+
const config: IDocuNotionConfig = defaultConfig;
32+
33+
const context: IDocuNotionContext = {
34+
getBlockChildren: (id: string) => {
35+
return new Promise<NotionBlock[]>(resolve =>
36+
resolve(new Array<NotionBlock>())
37+
);
38+
},
39+
directoryContainingMarkdown: "", // this changes with each page
40+
relativeFilePathToFolderContainingPage: "", // this changes with each page
41+
layoutStrategy: layoutStrategy,
42+
notionToMarkdown: new NotionToMarkdown({ notionClient }),
43+
options: {
44+
notionToken: "",
45+
rootPage: "",
46+
locales: [""],
47+
markdownOutputPath: "",
48+
imgOutputPath: "",
49+
imgPrefixInMarkdown: "",
50+
statusTag: "",
51+
},
52+
53+
pages: pages,
54+
counts: counts, // review will this get copied or pointed to?
55+
imports: [],
56+
convertNotionLinkToLocalDocusaurusLink: (url: string) =>
57+
convertInternalUrl(context, url),
58+
};
59+
60+
const blocks: Array<NotionBlock> = [
61+
{
62+
object: "block",
63+
id: "169e1c47-6706-4518-adca-73086b2738ac",
64+
parent: {
65+
type: "page_id",
66+
page_id: "2acc11a4-82a9-4759-b429-fa011c164888",
67+
},
68+
created_time: "2023-08-18T15:51:00.000Z",
69+
last_edited_time: "2023-08-18T15:51:00.000Z",
70+
created_by: {
71+
object: "user",
72+
id: "af5c163e-82b1-49d1-9f1c-539907bb9fb9",
73+
},
74+
last_edited_by: {
75+
object: "user",
76+
id: "af5c163e-82b1-49d1-9f1c-539907bb9fb9",
77+
},
78+
has_children: false,
79+
archived: false,
80+
type: "paragraph",
81+
paragraph: {
82+
rich_text: [
83+
{
84+
type: "equation",
85+
equation: { expression: "x" },
86+
annotations: {
87+
bold: false,
88+
italic: false,
89+
strikethrough: false,
90+
underline: false,
91+
code: false,
92+
color: "default",
93+
},
94+
plain_text: "x",
95+
href: null,
96+
},
97+
],
98+
color: "default",
99+
},
100+
},
101+
];
102+
103+
expect(await getMarkdownFromNotionBlocks(context, config, blocks)).toContain(
104+
"$x$"
105+
);
106+
});

src/pull.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export async function notionPull(options: DocuNotionOptions): Promise<void> {
5757
const optionsForLogging = { ...options };
5858
// Just show the first few letters of the notion token, which start with "secret" anyhow.
5959
optionsForLogging.notionToken =
60-
optionsForLogging.notionToken.substring(0, 3) + "...";
60+
optionsForLogging.notionToken.substring(0, 10) + "...";
6161

6262
const config = await loadConfigAsync();
6363

@@ -80,6 +80,24 @@ export async function notionPull(options: DocuNotionOptions): Promise<void> {
8080

8181
info("Connecting to Notion...");
8282

83+
// Do a quick test to see if we can connect to the root so that we can give a better error than just a generic "could not find page" one.
84+
try {
85+
await executeWithRateLimitAndRetries("retrieving root page", async () => {
86+
await notionClient.pages.retrieve({ page_id: options.rootPage });
87+
});
88+
} catch (e: any) {
89+
error(
90+
`docu-notion could not retrieve the root page from Notion. \r\na) Check that the root page id really is "${
91+
options.rootPage
92+
}".\r\nb) Check that your Notion API token (the "Integration Secret") is correct. It starts with "${
93+
optionsForLogging.notionToken
94+
}".\r\nc) Check that your root page includes your "integration" in its "connections".\r\nThis internal error message may help:\r\n ${
95+
e.message as string
96+
}`
97+
);
98+
exit(1);
99+
}
100+
83101
group(
84102
"Stage 1: walk children of the page named 'Outline', looking for pages..."
85103
);

0 commit comments

Comments
 (0)