@sillsdev/docu-notion 0.13.2-alpha.2 → 0.13.2-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -1
- package/dist/config/default.docunotion.config.js +2 -2
- package/dist/plugins/ColumnTransformer.js +5 -2
- package/dist/plugins/VideoTransformer.d.ts +2 -0
- package/dist/plugins/VideoTransformer.js +25 -0
- package/dist/plugins/VideoTransformer.spec.d.ts +1 -0
- package/dist/plugins/VideoTransformer.spec.js +88 -0
- package/dist/plugins/embedTweaks.d.ts +0 -2
- package/dist/plugins/embedTweaks.js +1 -23
- package/dist/plugins/embedTweaks.spec.js +0 -47
- package/dist/plugins/externalLinks.spec.js +13 -0
- package/dist/plugins/pluginTypes.d.ts +1 -0
- package/dist/pull.d.ts +1 -0
- package/dist/pull.js +42 -8
- package/dist/transform.js +8 -7
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ Currently, docu-notion expects that each page has only one of the following: sub
|
|
|
31
31
|
|
|
32
32
|
## 6. Pull your pages
|
|
33
33
|
|
|
34
|
-
First, determine the id of your root page by clicking "Share" and looking at the
|
|
34
|
+
First, determine the id of your root page by clicking "Share" and looking at the url it gives you. E.g.
|
|
35
35
|
https://www.notion.so/hattonjohn/My-Docs-0456aa5842946bdbea3a4f37c97a0e5
|
|
36
36
|
means that the id is "0456aa5842946PRETEND4f37c97a0e5".
|
|
37
37
|
|
|
@@ -133,3 +133,16 @@ Options:
|
|
|
133
133
|
# Plugins
|
|
134
134
|
|
|
135
135
|
If your project needs some processing that docu-notion doesn't already provide, you can provide a plugin that does it. See the [plugin readme](src/plugins/README.md).
|
|
136
|
+
|
|
137
|
+
# Callouts ➜ Admonitions
|
|
138
|
+
|
|
139
|
+
To map Notion callouts to Docusaurus admonitions, ensure the icon is for the type you want.
|
|
140
|
+
|
|
141
|
+
- ℹ️ ➜ note
|
|
142
|
+
- 📝➜ note
|
|
143
|
+
- 💡➜ tip
|
|
144
|
+
- ❗➜ info
|
|
145
|
+
- ⚠️➜ caution
|
|
146
|
+
- 🔥➜ danger
|
|
147
|
+
|
|
148
|
+
The default admonition type, if no matching icon is found, is "note".
|
|
@@ -10,6 +10,7 @@ const EscapeHtmlBlockModifier_1 = require("../plugins/EscapeHtmlBlockModifier");
|
|
|
10
10
|
const HeadingTransformer_1 = require("../plugins/HeadingTransformer");
|
|
11
11
|
const NumberedListTransformer_1 = require("../plugins/NumberedListTransformer");
|
|
12
12
|
const TableTransformer_1 = require("../plugins/TableTransformer");
|
|
13
|
+
const VideoTransformer_1 = require("../plugins/VideoTransformer");
|
|
13
14
|
const externalLinks_1 = require("../plugins/externalLinks");
|
|
14
15
|
const defaultConfig = {
|
|
15
16
|
plugins: [
|
|
@@ -24,14 +25,13 @@ const defaultConfig = {
|
|
|
24
25
|
CalloutTransformer_1.standardCalloutTransformer,
|
|
25
26
|
TableTransformer_1.standardTableTransformer,
|
|
26
27
|
NumberedListTransformer_1.standardNumberedListTransformer,
|
|
28
|
+
VideoTransformer_1.standardVideoTransformer,
|
|
27
29
|
// Link modifiers, which are special because they can read metadata from all the pages in order to figure out the correct url
|
|
28
30
|
internalLinks_1.standardInternalLinkConversion,
|
|
29
31
|
externalLinks_1.standardExternalLinkConversion,
|
|
30
32
|
// Regexps plus javascript `import`s that operate on the Markdown output
|
|
31
33
|
embedTweaks_1.imgurGifEmbed,
|
|
32
34
|
embedTweaks_1.gifEmbed,
|
|
33
|
-
embedTweaks_1.youtubeEmbed,
|
|
34
|
-
embedTweaks_1.vimeoEmbed,
|
|
35
35
|
],
|
|
36
36
|
};
|
|
37
37
|
exports.default = defaultConfig;
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.standardColumnTransformer = void 0;
|
|
13
13
|
const notion_client_1 = require("notion-client");
|
|
14
|
+
const pull_1 = require("../pull");
|
|
14
15
|
exports.standardColumnTransformer = {
|
|
15
16
|
name: "standardColumnTransformer",
|
|
16
17
|
notionToMarkdownTransforms: [
|
|
@@ -49,8 +50,10 @@ function getColumnWidth(block) {
|
|
|
49
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
51
|
const unofficialNotionClient = new notion_client_1.NotionAPI();
|
|
51
52
|
const blockId = block.id;
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const recordMap = yield (0, pull_1.executeWithRateLimitAndRetries)(`unofficialNotionClient.getPage(${blockId}) in getColumnWidth()`, () => {
|
|
54
|
+
// Yes, it is odd to call 'getPage' for a block, but that's how we access the format info.
|
|
55
|
+
return unofficialNotionClient.getPage(blockId);
|
|
56
|
+
});
|
|
54
57
|
const blockResult = recordMap.block[blockId];
|
|
55
58
|
// ENHANCE: could we use https://github.com/NotionX/react-notion-x/tree/master/packages/notion-types
|
|
56
59
|
// to get away from "any", which might be particularly helpful in the future
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.standardVideoTransformer = void 0;
|
|
4
|
+
const log_1 = require("../log");
|
|
5
|
+
exports.standardVideoTransformer = {
|
|
6
|
+
name: "video",
|
|
7
|
+
notionToMarkdownTransforms: [
|
|
8
|
+
{
|
|
9
|
+
type: "video",
|
|
10
|
+
getStringFromBlock: (context, block) => {
|
|
11
|
+
const video = block.video;
|
|
12
|
+
if (video.type === "external") {
|
|
13
|
+
if (!context.imports)
|
|
14
|
+
context.imports = [];
|
|
15
|
+
context.imports.push(`import ReactPlayer from "react-player";`);
|
|
16
|
+
return `<ReactPlayer controls url="${video.external.url}" />`;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
(0, log_1.warning)(`[standardVideoTransformer] Found Notion "video" block with type ${video.type}. The best docu-notion can do for now is ignore it.`);
|
|
20
|
+
}
|
|
21
|
+
return "";
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const log_1 = require("../log");
|
|
13
|
+
const VideoTransformer_1 = require("./VideoTransformer");
|
|
14
|
+
const pluginTestRun_1 = require("./pluginTestRun");
|
|
15
|
+
test("youtube embedded", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
const config = { plugins: [VideoTransformer_1.standardVideoTransformer] };
|
|
17
|
+
const result = yield (0, pluginTestRun_1.blocksToMarkdown)(config, [
|
|
18
|
+
{
|
|
19
|
+
object: "block",
|
|
20
|
+
type: "video",
|
|
21
|
+
video: {
|
|
22
|
+
caption: [
|
|
23
|
+
{
|
|
24
|
+
type: "text",
|
|
25
|
+
text: {
|
|
26
|
+
content: "A video about editing in Notion",
|
|
27
|
+
link: null,
|
|
28
|
+
},
|
|
29
|
+
plain_text: "A video about editing in Notion",
|
|
30
|
+
href: null,
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
type: "external",
|
|
34
|
+
external: { url: "https://www.youtube.com/watch?v=FXIrojSK3Jo" },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
expect(result).toContain(`import ReactPlayer from "react-player";`);
|
|
39
|
+
expect(result).toContain(`<ReactPlayer controls url="https://www.youtube.com/watch?v=FXIrojSK3Jo" />`);
|
|
40
|
+
}));
|
|
41
|
+
test("vimeo embedded", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
(0, log_1.setLogLevel)("verbose");
|
|
43
|
+
const config = { plugins: [VideoTransformer_1.standardVideoTransformer] };
|
|
44
|
+
const result = yield (0, pluginTestRun_1.blocksToMarkdown)(config, [
|
|
45
|
+
{
|
|
46
|
+
object: "block",
|
|
47
|
+
type: "video",
|
|
48
|
+
video: {
|
|
49
|
+
caption: [],
|
|
50
|
+
type: "external",
|
|
51
|
+
external: { url: "https://vimeo.com/4613611xx" },
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
]);
|
|
55
|
+
expect(result).toContain(`import ReactPlayer from "react-player";`);
|
|
56
|
+
expect(result).toContain(`<ReactPlayer controls url="https://vimeo.com/4613611xx" />`);
|
|
57
|
+
}));
|
|
58
|
+
test("video link, not embedded", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
(0, log_1.setLogLevel)("verbose");
|
|
60
|
+
const config = { plugins: [VideoTransformer_1.standardVideoTransformer] };
|
|
61
|
+
const result = yield (0, pluginTestRun_1.blocksToMarkdown)(config, [
|
|
62
|
+
{
|
|
63
|
+
object: "block",
|
|
64
|
+
type: "paragraph",
|
|
65
|
+
paragraph: {
|
|
66
|
+
rich_text: [
|
|
67
|
+
{
|
|
68
|
+
type: "text",
|
|
69
|
+
text: {
|
|
70
|
+
content: "https://vimeo.com/4613611xx",
|
|
71
|
+
link: {
|
|
72
|
+
url: "https://vimeo.com/4613611xx",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
annotations: {
|
|
76
|
+
code: false,
|
|
77
|
+
},
|
|
78
|
+
plain_text: "https://vimeo.com/4613611xx",
|
|
79
|
+
href: "https://vimeo.com/4613611xx",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
color: "default",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
]);
|
|
86
|
+
expect(result).toContain("[https://vimeo.com/4613611xx](https://vimeo.com/4613611xx)");
|
|
87
|
+
expect(result).not.toContain(`import`);
|
|
88
|
+
}));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.imgurGifEmbed = exports.gifEmbed = void 0;
|
|
4
4
|
exports.gifEmbed = {
|
|
5
5
|
name: "gif",
|
|
6
6
|
regexMarkdownModifications: [
|
|
@@ -22,25 +22,3 @@ exports.imgurGifEmbed = {
|
|
|
22
22
|
},
|
|
23
23
|
],
|
|
24
24
|
};
|
|
25
|
-
exports.youtubeEmbed = {
|
|
26
|
-
name: "youtube",
|
|
27
|
-
regexMarkdownModifications: [
|
|
28
|
-
{
|
|
29
|
-
regex: /\[.*\]\((.*youtube\.com\/watch.*)\)/,
|
|
30
|
-
imports: [`import ReactPlayer from "react-player";`],
|
|
31
|
-
replacementPattern: `<ReactPlayer controls url="$1" />`,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
};
|
|
35
|
-
exports.vimeoEmbed = {
|
|
36
|
-
name: "vimeo",
|
|
37
|
-
regexMarkdownModifications: [
|
|
38
|
-
{
|
|
39
|
-
regex: /\[.*\]\((https:\/\/.*vimeo.*)\)/,
|
|
40
|
-
// we use to have the following, but the above should handle both the player an not-player urls.
|
|
41
|
-
//regex: /\[.*\]\((.*player\.vimeo.*)\)/gm, // player.vimeo
|
|
42
|
-
imports: [`import ReactPlayer from "react-player";`],
|
|
43
|
-
replacementPattern: `<ReactPlayer controls url="$1" />`,
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
};
|
|
@@ -12,53 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
const log_1 = require("../log");
|
|
13
13
|
const pluginTestRun_1 = require("./pluginTestRun");
|
|
14
14
|
const embedTweaks_1 = require("./embedTweaks");
|
|
15
|
-
test("youtube", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const config = { plugins: [embedTweaks_1.youtubeEmbed] };
|
|
17
|
-
const result = yield (0, pluginTestRun_1.blocksToMarkdown)(config, [
|
|
18
|
-
{
|
|
19
|
-
object: "block",
|
|
20
|
-
id: "e6ddd1d4-36d4-4925-94c1-5dff4662c1f3",
|
|
21
|
-
has_children: false,
|
|
22
|
-
archived: false,
|
|
23
|
-
type: "video",
|
|
24
|
-
video: {
|
|
25
|
-
caption: [
|
|
26
|
-
{
|
|
27
|
-
type: "text",
|
|
28
|
-
text: {
|
|
29
|
-
content: "A video about editing in Notion",
|
|
30
|
-
link: null,
|
|
31
|
-
},
|
|
32
|
-
plain_text: "A video about editing in Notion",
|
|
33
|
-
href: null,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
type: "external",
|
|
37
|
-
external: { url: "https://www.youtube.com/watch?v=FXIrojSK3Jo" },
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
]);
|
|
41
|
-
expect(result).toContain(`import ReactPlayer from "react-player";`);
|
|
42
|
-
expect(result).toContain(`<ReactPlayer controls url="https://www.youtube.com/watch?v=FXIrojSK3Jo" />`);
|
|
43
|
-
}));
|
|
44
|
-
test("vimeo", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
(0, log_1.setLogLevel)("verbose");
|
|
46
|
-
const config = { plugins: [embedTweaks_1.vimeoEmbed] };
|
|
47
|
-
const result = yield (0, pluginTestRun_1.blocksToMarkdown)(config, [
|
|
48
|
-
{
|
|
49
|
-
object: "block",
|
|
50
|
-
id: "39ff83a3-2fb5-4411-a715-960656a177ff",
|
|
51
|
-
type: "video",
|
|
52
|
-
video: {
|
|
53
|
-
caption: [],
|
|
54
|
-
type: "external",
|
|
55
|
-
external: { url: "https://vimeo.com/4613611xx" },
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
]);
|
|
59
|
-
expect(result).toContain(`import ReactPlayer from "react-player";`);
|
|
60
|
-
expect(result).toContain(`<ReactPlayer controls url="https://vimeo.com/4613611xx" />`);
|
|
61
|
-
}));
|
|
62
15
|
test("imgur", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
16
|
(0, log_1.setLogLevel)("verbose");
|
|
64
17
|
const config = { plugins: [embedTweaks_1.imgurGifEmbed] };
|
|
@@ -23,6 +23,19 @@ test("links turned into bookmarks", () => __awaiter(void 0, void 0, void 0, func
|
|
|
23
23
|
});
|
|
24
24
|
expect(results.trim()).toBe("[https://github.com](https://github.com)");
|
|
25
25
|
}));
|
|
26
|
+
test("video links turned into bookmarks", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
|
+
(0, log_1.setLogLevel)("debug");
|
|
28
|
+
const results = yield getMarkdown({
|
|
29
|
+
object: "block",
|
|
30
|
+
type: "bookmark",
|
|
31
|
+
bookmark: {
|
|
32
|
+
caption: [],
|
|
33
|
+
url: "https://vimeo.com/4613611xx",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
expect(results).toContain("[https://vimeo.com/4613611xx](https://vimeo.com/4613611xx)");
|
|
37
|
+
expect(results).not.toContain(`import`);
|
|
38
|
+
}));
|
|
26
39
|
test("external link inside callout", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
40
|
const results = yield getMarkdown({
|
|
28
41
|
type: "callout",
|
package/dist/pull.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export type DocuNotionOptions = {
|
|
|
9
9
|
statusTag: string;
|
|
10
10
|
};
|
|
11
11
|
export declare function notionPull(options: DocuNotionOptions): Promise<void>;
|
|
12
|
+
export declare function executeWithRateLimitAndRetries<T>(label: string, asyncFunction: () => Promise<T>): Promise<T>;
|
|
12
13
|
export declare function initNotionClient(notionToken: string): Client;
|
package/dist/pull.js
CHANGED
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.initNotionClient = exports.notionPull = void 0;
|
|
35
|
+
exports.initNotionClient = exports.executeWithRateLimitAndRetries = exports.notionPull = void 0;
|
|
36
36
|
const fs = __importStar(require("fs-extra"));
|
|
37
37
|
const notion_to_md_1 = require("notion-to-md");
|
|
38
38
|
const HierarchicalNamedLayoutStrategy_1 = require("./HierarchicalNamedLayoutStrategy");
|
|
@@ -188,12 +188,45 @@ const notionLimiter = new limiter_1.RateLimiter({
|
|
|
188
188
|
let notionClient;
|
|
189
189
|
function getPageMetadata(id) {
|
|
190
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
yield
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
return yield executeWithRateLimitAndRetries(`pages.retrieve(${id})`, () => {
|
|
192
|
+
return notionClient.pages.retrieve({
|
|
193
|
+
page_id: id,
|
|
194
|
+
});
|
|
194
195
|
});
|
|
195
196
|
});
|
|
196
197
|
}
|
|
198
|
+
// While everything works fine locally, on Github Actions we are getting a lot of timeouts, so
|
|
199
|
+
// we're trying this extra retry-able wrapper.
|
|
200
|
+
function executeWithRateLimitAndRetries(label, asyncFunction) {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
yield rateLimit();
|
|
203
|
+
const kRetries = 10;
|
|
204
|
+
let lastException = undefined;
|
|
205
|
+
for (let i = 0; i < kRetries; i++) {
|
|
206
|
+
try {
|
|
207
|
+
return yield asyncFunction();
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
lastException = e;
|
|
211
|
+
if ((e === null || e === void 0 ? void 0 : e.code) === "notionhq_client_request_timeout" ||
|
|
212
|
+
e.message.includes("timeout") ||
|
|
213
|
+
e.message.includes("Timeout") ||
|
|
214
|
+
e.message.includes("limit") ||
|
|
215
|
+
e.message.includes("Limit")) {
|
|
216
|
+
const secondsToWait = i + 1;
|
|
217
|
+
(0, log_1.info)(`While doing "${label}", got error "${e.message}". Will retry after ${secondsToWait}s...`);
|
|
218
|
+
yield new Promise(resolve => setTimeout(resolve, 1000 * secondsToWait));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
throw e;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
(0, log_1.error)(`Error: could not complete "${label}" after ${kRetries} retries.`);
|
|
226
|
+
throw lastException;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
exports.executeWithRateLimitAndRetries = executeWithRateLimitAndRetries;
|
|
197
230
|
function rateLimit() {
|
|
198
231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
232
|
if (notionLimiter.getTokensRemaining() < 1) {
|
|
@@ -213,10 +246,11 @@ function getBlockChildren(id) {
|
|
|
213
246
|
// Note: there is a now a collectPaginatedAPI() in the notion client, so
|
|
214
247
|
// we could switch to using that (I don't know if it does rate limiting?)
|
|
215
248
|
do {
|
|
216
|
-
yield
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
249
|
+
const response = yield executeWithRateLimitAndRetries(`getBlockChildren(${id})`, () => {
|
|
250
|
+
return notionClient.blocks.children.list({
|
|
251
|
+
start_cursor: start_cursor,
|
|
252
|
+
block_id: id,
|
|
253
|
+
});
|
|
220
254
|
});
|
|
221
255
|
if (!overallResult) {
|
|
222
256
|
overallResult = response;
|
package/dist/transform.js
CHANGED
|
@@ -44,9 +44,12 @@ function getMarkdownFromNotionBlocks(context, config, blocks) {
|
|
|
44
44
|
markdown = doLinkFixes(context, markdown, config);
|
|
45
45
|
//console.log("markdown after link fixes", markdown);
|
|
46
46
|
// simple regex-based tweaks. These are usually related to docusaurus
|
|
47
|
-
const
|
|
47
|
+
const body = yield doTransformsOnMarkdown(context, config, markdown);
|
|
48
48
|
// console.log("markdown after regex fixes", markdown);
|
|
49
49
|
// console.log("body after regex", body);
|
|
50
|
+
const uniqueImports = [...new Set(context.imports)];
|
|
51
|
+
const imports = uniqueImports.join("\n");
|
|
52
|
+
context.imports = []; // reset for next page
|
|
50
53
|
return `${imports}\n${body}`;
|
|
51
54
|
});
|
|
52
55
|
}
|
|
@@ -65,7 +68,6 @@ function doNotionBlockTransforms(blocks, config) {
|
|
|
65
68
|
}
|
|
66
69
|
}
|
|
67
70
|
function doTransformsOnMarkdown(context, config, input) {
|
|
68
|
-
var _a;
|
|
69
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
72
|
const regexMods = config.plugins
|
|
71
73
|
.filter(plugin => !!plugin.regexMarkdownModifications)
|
|
@@ -81,7 +83,6 @@ function doTransformsOnMarkdown(context, config, input) {
|
|
|
81
83
|
let body = input;
|
|
82
84
|
//console.log("body before regex: " + body);
|
|
83
85
|
let match;
|
|
84
|
-
const imports = new Set();
|
|
85
86
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
86
87
|
for (const mod of regexMods) {
|
|
87
88
|
let replacement = undefined;
|
|
@@ -103,7 +104,6 @@ function doTransformsOnMarkdown(context, config, input) {
|
|
|
103
104
|
replacement = yield mod.getReplacement(context, matchAsThePluginWouldExpectIt);
|
|
104
105
|
}
|
|
105
106
|
else if (mod.replacementPattern) {
|
|
106
|
-
console.log(`mod.replacementPattern.replace("$1", ${match[2]}`);
|
|
107
107
|
replacement = mod.replacementPattern.replace("$1", match[2]);
|
|
108
108
|
}
|
|
109
109
|
if (replacement !== undefined) {
|
|
@@ -114,14 +114,15 @@ function doTransformsOnMarkdown(context, config, input) {
|
|
|
114
114
|
precedingPart +
|
|
115
115
|
partStartingFromThisMatch.replace(original, replacement);
|
|
116
116
|
// add any library imports
|
|
117
|
-
(
|
|
117
|
+
if (!context.imports)
|
|
118
|
+
context.imports = [];
|
|
119
|
+
context.imports.push(...(mod.imports || []));
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
}
|
|
122
124
|
(0, log_1.logDebug)("doTransformsOnMarkdown", "body after regex: " + body);
|
|
123
|
-
|
|
124
|
-
return { body, imports: [...uniqueImports].join("\n") };
|
|
125
|
+
return body;
|
|
125
126
|
});
|
|
126
127
|
}
|
|
127
128
|
function doNotionToMarkdown(docunotionContext, blocks) {
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"// typescript check": "",
|
|
12
12
|
"tsc": "tsc",
|
|
13
13
|
"// test out with a private sample notion db": "",
|
|
14
|
+
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr",
|
|
14
15
|
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
|
|
15
16
|
"pull-sample-site": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
|
|
16
17
|
"// test with a semi-stable/public site:": "",
|
|
@@ -89,5 +90,5 @@
|
|
|
89
90
|
"volta": {
|
|
90
91
|
"node": "18.16.0"
|
|
91
92
|
},
|
|
92
|
-
"version": "0.13.2-alpha.
|
|
93
|
+
"version": "0.13.2-alpha.4"
|
|
93
94
|
}
|