Skip to content

Commit 7f95fe7

Browse files
authored
Merge pull request #40 from sillsdev/plugins
Plugins (#40)
2 parents f4be98e + c1b15bf commit 7f95fe7

40 files changed

+2913
-740
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ i18n/
55
node_modules/
66
version.json
77
docs/
8+
yarn-error.log

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@ Options:
129129
| -i, --img-output-path <string> | | Path to directory where images will be stored. If this is not included, images will be placed in the same directory as the document that uses them, which then allows for localization of screenshots. |
130130
| -p, --img-prefix-in-markdown <string> | | When referencing an image from markdown, prefix with this path instead of the full img-output-path. Should be used only in conjunction with --img-output-path. |
131131
| -h, --help | | display help for command |
132+
133+
# Plugins
134+
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).

docu-notion.config.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* This file is only used when testing docu-notion itself, not when it is used as a library.
2+
E.g., if you run `yarn pull-test-tagged`, docu-notion will read this file and use it to configure itself,
3+
using these example plugins.
4+
*/
5+
6+
import { IDocuNotionConfig } from "./dist/config/configuration";
7+
import { IPlugin, Log } from "./dist";
8+
import { NotionBlock } from "./dist/types";
9+
10+
const dummyBlockModifier: IPlugin = {
11+
name: "dummyBlockModifier",
12+
13+
notionBlockModifications: [
14+
{
15+
modify: (block: NotionBlock) => {
16+
Log.verbose("dummyBlockModifier was called");
17+
},
18+
},
19+
],
20+
};
21+
22+
const dummyMarkdownModifier: IPlugin = {
23+
name: "dummyMarkdownModifier",
24+
25+
regexMarkdownModifications: [
26+
{
27+
regex: /aaa(.*)aaa/,
28+
replacementPattern: "bbb$1bbb",
29+
},
30+
],
31+
};
32+
33+
const config: IDocuNotionConfig = {
34+
plugins: [dummyBlockModifier, dummyMarkdownModifier],
35+
};
36+
37+
export default config;

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
"typecheck": "tsc --noEmit",
1616
"notion-download": "node dist/index.js",
1717
"cmdhelp": "ts-node --compiler-options \"{\\\"module\\\": \\\"commonjs\\\"}\" src/index.ts",
18+
"// note that we're not using ts-node at the moment because of ": "https://github.com/Codex-/cosmiconfig-typescript-loader/issues/70",
19+
"ts": "yarn tsc && rm -rf ./docs/ && cross-var node dist/index.js",
1820
"// test out with a private sample notion db": "",
19-
"pull-test-tagged": "cross-var rm -rf ./docs/ && ts-node src/index.ts -n %DOCU_NOTION_INTEGRATION_TOKEN% -r %DOCU_NOTION_TEST_ROOT_PAGE_ID% --log-level debug --status-tag test",
20-
"pull-test-outline": "cross-var rm -rf ./docs/ && ts-node --compiler-options \"{\\\"module\\\": \\\"commonjs\\\"}\" src/index.ts -n %DOCU_NOTION_INTEGRATION_TOKEN% -r %DOCU_NOTION_TEST_ROOT_PAGE_ID% --log-level debug",
21+
"pull-test-tagged": "yarn ts -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
22+
"pull-sample-site": "yarn ts -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
2123
"// test with a semi-stable/public site:": "",
22-
"pull-sample": "cross-var ts-node --compiler-options \"{\\\"module\\\": \\\"commonjs\\\"}\" src/index.ts -n %DOCU_NOTION_INTEGRATION_TOKEN% -r %DOCU_NOTION_SAMPLE_ROOT_PAGE% -m ./sample --locales en,es,fr,de --log-level verbose",
23-
"pull-sample-with-paths": "cross-var ts-node --compiler-options \"{\\\"module\\\": \\\"commonjs\\\"}\" src/index.ts -n %DOCU_NOTION_INTEGRATION_TOKEN% -r %DOCU_NOTION_SAMPLE_ROOT_PAGE% -m ./sample --img-output-path ./sample_img"
24+
"pull-sample": "yarn ts -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE -m ./sample --locales en,es,fr,de --log-level verbose",
25+
"pull-sample-with-paths": "yarn ts -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE -m ./sample --img-output-path ./sample_img",
26+
"postinstall": "patch-package"
2427
},
2528
"repository": {
2629
"type": "git",
@@ -49,9 +52,11 @@
4952
"//chalk@4": "also ESM related problem",
5053
"//notion-client@4": "also ESM related problem",
5154
"dependencies": {
52-
"@notionhq/client": "^1.0.4",
55+
"@notionhq/client": "2.2.3",
5356
"chalk": "^4.1.2",
5457
"commander": "^9.2.0",
58+
"cosmiconfig": "^8.0.0",
59+
"cosmiconfig-typescript-loader": "^4.3.0",
5560
"file-type": "16.5.1",
5661
"fs-extra": "^10.1.0",
5762
"limiter": "^2.1.0",
@@ -60,7 +65,6 @@
6065
"notion-client": "^4",
6166
"notion-to-md": "^2.5.5",
6267
"path": "^0.12.7",
63-
"postinstall-postinstall": "^2.1.0",
6468
"sanitize-filename": "^1.6.3"
6569
},
6670
"devDependencies": {
@@ -78,6 +82,7 @@
7882
"eslint-plugin-prettier": "^3.4.0",
7983
"jest": "^28.1.3",
8084
"lint-staged": "^10.5.4",
85+
"patch-package": "^6.5.1",
8186
"prettier": "^2.2.1",
8287
"semantic-release": "^19.0.2",
8388
"ts-jest": "^28.0.7",

src/DocusaurusTweaks.ts

Lines changed: 0 additions & 102 deletions
This file was deleted.

src/HierarchicalNamedLayoutStrategy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class HierarchicalNamedLayoutStrategy extends LayoutStrategy {
3636
.replaceAll("'", "")
3737
.replaceAll("?", "-");
3838

39-
const context = ("/" + page.context + "/").replaceAll("//", "/");
39+
const context = ("/" + page.layoutContext + "/").replaceAll("//", "/");
4040
const path =
4141
this.rootDirectory + context + sanitizedName + extensionWithDot;
4242

0 commit comments

Comments
 (0)