Skip to content

Commit a2c07dc

Browse files
committed
reorg a bit
1 parent 6fdc509 commit a2c07dc

24 files changed

+112
-148
lines changed

docu-notion.config.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,19 @@ const dummyBlockModifier: IPlugin = {
1717
],
1818
};
1919

20-
const dummyBlockModifier2: IPlugin = {
21-
name: "dummyBlockModifier2",
20+
const dummyMarkdownModifier: IPlugin = {
21+
name: "dummyMarkdownModifier",
2222

23-
notionBlockModifications: [
23+
regexMarkdownModifications: [
2424
{
25-
modify: (block: NotionBlock) => {
26-
verbose("dummyBlockModifier2 was called");
27-
},
25+
regex: /aaa(.*)aaa/,
26+
replacementPattern: "bbb$1bbb",
2827
},
2928
],
3029
};
3130

32-
const dummyBlockModifier2Plugin: IPlugin = {
33-
name: "dummyBlockModifier2Plugin",
34-
35-
init: (p: IPlugin): Promise<void> => {
36-
return new Promise((resolve, reject) => {
37-
verbose("****dummyBlockModifier2Plugin init was called");
38-
p.notionBlockModifications = dummyBlockModifier2.notionBlockModifications;
39-
resolve();
40-
});
41-
},
42-
};
43-
4431
const config: IDocuNotionConfig = {
45-
plugins: [dummyBlockModifier, dummyBlockModifier2Plugin],
32+
plugins: [dummyBlockModifier, dummyMarkdownModifier],
4633
};
4734

4835
export default config;

src/TestRun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
IDocuNotionConfig,
77
IDocuNotionContext,
88
NotionBlock,
9-
} from "./config/configuration";
9+
} from "./plugins/pluginTypes";
1010
import { HierarchicalNamedLayoutStrategy } from "./HierarchicalNamedLayoutStrategy";
1111
import { error, logDebug, verbose, warning } from "./log";
1212
import { NotionPage } from "./NotionPage";

src/config/configuration.ts

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,8 @@
1-
// an extension manager that uses cosmicconfig to get a list of plugin functions
2-
// and then runs them in sequence
3-
4-
import { ListBlockChildrenResponseResult } from "notion-to-md/build/types";
51
import * as Cosmic from "cosmiconfig";
6-
import { NotionPage } from "../NotionPage";
7-
import { NotionToMarkdown } from "notion-to-md";
8-
import { BlockObjectResponse } from "@notionhq/client/build/src/api-endpoints";
9-
import { DocuNotionOptions } from "../pull";
10-
import { LayoutStrategy } from "../LayoutStrategy";
112
import defaultConfig from "./default.docunotion.config";
12-
import { error, info, logDebug, verbose } from "../log";
3+
import { error, verbose } from "../log";
134
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
14-
15-
// wrap this into something with a bit better name than the raw thing
16-
export type NotionBlock = BlockObjectResponse;
17-
18-
type linkConversionFunction = (
19-
context: IDocuNotionContext,
20-
markdownLink: string
21-
) => string;
22-
23-
export type IPlugin = {
24-
// this is just for display when debugging
25-
name: string;
26-
// operations on notion blocks before they are converted to markdown
27-
notionBlockModifications?: {
28-
modify: (block: NotionBlock) => void;
29-
}[];
30-
// overrides for the default notion-to-markdown conversions
31-
notionToMarkdownTransforms?: {
32-
type: string;
33-
getStringFromBlock: (
34-
context: IDocuNotionContext,
35-
block: NotionBlock
36-
) => string | Promise<string>;
37-
}[];
38-
39-
// corrections to links after they are converted to markdown
40-
linkModifier?: {
41-
match: RegExp; // does this plugin apply to this link?
42-
convert: linkConversionFunction;
43-
};
44-
45-
// simple regex replacements on the markdown output
46-
regexMarkdownModifications?: IRegexMarkdownModification[];
47-
48-
// Allow a plugin to perform an async operation at the start of docu-notion.
49-
// Notice that the plugin itself is given, so you can add things to it.
50-
init?(plugin: IPlugin): Promise<void>;
51-
};
52-
53-
export type IRegexMarkdownModification = {
54-
// Should match on markdown that you want to replace
55-
regex: RegExp;
56-
// Based on that regex, the outputPattern will be used to replace the matched text
57-
replacementPattern?: string;
58-
// Instead of a pattern, you can use this if you have to ask a server somewhere for help in getting the new markdown
59-
getReplacement?(s: string): Promise<string>;
60-
61-
// If the output is creating things like react elements, you can import their definitions here
62-
imports?: string[];
63-
};
64-
65-
export type IDocuNotionConfig = {
66-
plugins: IPlugin[];
67-
};
68-
export type ICustomNotionToMarkdownConversion = (
69-
block: ListBlockChildrenResponseResult,
70-
context: IDocuNotionContext
71-
) => () => Promise<string>;
72-
73-
export type ICounts = {
74-
output_normally: number;
75-
skipped_because_empty: number;
76-
skipped_because_status: number;
77-
skipped_because_level_cannot_have_content: number;
78-
};
79-
export type IGetBlockChildrenFn = (id: string) => Promise<NotionBlock[]>;
80-
81-
export type IDocuNotionContext = {
82-
layoutStrategy: LayoutStrategy;
83-
options: DocuNotionOptions;
84-
getBlockChildren: IGetBlockChildrenFn;
85-
notionToMarkdown: NotionToMarkdown;
86-
directoryContainingMarkdown: string;
87-
relativeFilePathToFolderContainingPage: string;
88-
pages: NotionPage[];
89-
counts: ICounts;
90-
};
5+
import { IDocuNotionConfig, IPlugin } from "../plugins/pluginTypes";
916

927
// read the plugins from the config file
938
// and add them to the map
@@ -132,19 +47,3 @@ export async function loadConfigAsync(): Promise<IDocuNotionConfig> {
13247
verbose(`Active plugins: [${config.plugins.map(p => p.name).join(", ")}]`);
13348
return config;
13449
}
135-
136-
// export function getMDConversions(): Array<{
137-
// type: string;
138-
// transformer: ICustomNotionToMarkdownConversion;
139-
// }> {
140-
// if (!config || !config.plugins) {
141-
// return [];
142-
// }
143-
// // for each plugin that has a markdownConversion property, return the array of conversions
144-
// return config.plugins.reduce((acc, plugin) => {
145-
// if (plugin.notionToMarkdownTransforms) {
146-
// acc.push(...plugin.notionToMarkdownTransforms);
147-
// }
148-
// return acc;
149-
// }, [] as Array<{ type: string; transformer: ICustomNotionToMarkdownConversion }>);
150-
// }

src/config/default.docunotion.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { standardEscapeHtmlBlockModifier } from "../plugins/EscapeHtmlBlockModif
1313
import { standardHeadingTransformer } from "../plugins/HeadingTransformer";
1414
import { standardNumberedListTransformer } from "../plugins/NumberedListTransformer";
1515
import { standardTableTransformer } from "../plugins/TableTransformer";
16-
import { IDocuNotionConfig } from "./configuration";
16+
import { IDocuNotionConfig } from "../plugins/pluginTypes";
1717
import { standardExternalLinkConversion } from "../plugins/externalLinks";
1818

1919
const defaultConfig: IDocuNotionConfig = {

src/images.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Path from "path";
55
import { makeImagePersistencePlan } from "./MakeImagePersistencePlan";
66
import { warning, logDebug, verbose, info } from "./log";
77
import { ListBlockChildrenResponseResult } from "notion-to-md/build/types";
8-
import { IDocuNotionContext, IPlugin } from "./config/configuration";
8+
import { IDocuNotionContext, IPlugin } from "./plugins/pluginTypes";
99

1010
// We several things here:
1111
// 1) copy images locally instead of leaving them in Notion

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ run();
77
// for plugins to import
88

99
export * as Log from "./log";
10-
export * from "./config/configuration";
10+
export * from "./plugins/pluginTypes";

src/plugins/CalloutTransformer.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NotionBlock } from "../config/configuration";
1+
import { NotionBlock } from "./pluginTypes";
22
import { NotionPage } from "../NotionPage";
33
import { blocksToMarkdown, makeSamplePageObject } from "../TestRun";
44
import { standardCalloutTransformer } from "./CalloutTransformer";

src/plugins/CalloutTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from "notion-to-md/build/types";
66
// import { Client } from "@notionhq/client";
77
// import { getBlockChildren } from "./CustomTransformers";
8-
import { IPlugin, NotionBlock } from "../config/configuration";
8+
import { IPlugin, NotionBlock } from "./pluginTypes";
99

1010
// In Notion, you can make a callout and change its emoji. We map 5 of these
1111
// to the 5 Docusaurus admonition styles.

src/plugins/ColumnListTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NotionToMarkdown } from "notion-to-md";
2-
import { IPlugin, NotionBlock } from "../config/configuration";
2+
import { IPlugin, NotionBlock } from "./pluginTypes";
33

44
export async function notionColumnListToMarkdown(
55
notionToMarkdown: NotionToMarkdown,

src/plugins/ColumnTransformer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NotionAPI } from "notion-client";
22
import { NotionToMarkdown } from "notion-to-md";
33
import { ListBlockChildrenResponseResult } from "notion-to-md/build/types";
4-
import { IGetBlockChildrenFn, IPlugin } from "../config/configuration";
4+
import { IGetBlockChildrenFn, IPlugin } from "./pluginTypes";
55

66
export const standardColumnTransformer: IPlugin = {
77
name: "standardColumnTransformer",

0 commit comments

Comments
 (0)