@rasenganjs/mdx 1.0.0 → 1.0.2
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 +4 -4
- package/lib/index.d.ts +6 -31
- package/lib/index.js +6 -67
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +0 -1
- package/lib/utils/create-filter.d.ts +8 -0
- package/lib/utils/create-filter.js +23 -0
- package/lib/utils/create-filter.js.map +1 -0
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +2 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/plugin.d.ts +33 -0
- package/lib/utils/plugin.js +73 -0
- package/lib/utils/plugin.js.map +1 -0
- package/package.json +51 -47
- package/lib/utils/generate-page.d.ts +0 -10
- package/lib/utils/generate-page.js +0 -18
- package/lib/utils/generate-page.js.map +0 -1
- package/src/components/index.tsx +0 -219
- package/src/index.ts +0 -82
- package/src/types/index.ts +0 -15
- package/src/utils/generate-page.tsx +0 -24
- package/src/utils/index.ts +0 -3
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Rasengan MDX Plugin
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@rasenganjs%2Fmdx)
|
|
4
|
+

|
|
5
5
|
[](https://github.com/rasengan-dev/rasengan-mdx-plugin/blob/main/LICENSE)
|
|
6
6
|
|
|
7
7
|
MDX plugin for Rasengan.Js
|
|
@@ -40,7 +40,7 @@ export default defineConfig({
|
|
|
40
40
|
// Define aliases
|
|
41
41
|
vite: {
|
|
42
42
|
plugins: [
|
|
43
|
-
mdx(),
|
|
43
|
+
...mdx(),
|
|
44
44
|
],
|
|
45
45
|
},
|
|
46
46
|
});
|
|
@@ -98,7 +98,7 @@ We also have a [Twitter](https://twitter.com/rasenganjs) account where you can f
|
|
|
98
98
|
|
|
99
99
|
## License
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
[MIT licensed](https://github.com/rasengan-dev/rasengan-image/blob/main/LICENSE).
|
|
102
102
|
|
|
103
103
|
## Authors
|
|
104
104
|
|
package/lib/index.d.ts
CHANGED
|
@@ -1,35 +1,10 @@
|
|
|
1
|
-
export * from './types/index.js';
|
|
2
|
-
export * from "./utils/index.js";
|
|
3
|
-
export * from './components/index.js';
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
2
|
+
* License: MIT
|
|
6
3
|
*
|
|
7
|
-
*
|
|
8
|
-
* - Resolves the Vite configuration and stores it for later use.
|
|
9
|
-
* - Transforms MDX files by applying the `@mdx-js/rollup` transformation.
|
|
10
|
-
* - Extracts frontmatter data from the MDX files and creates a `metadata` object.
|
|
11
|
-
* - Appends the `metadata` object to the transformed MDX content.
|
|
4
|
+
* Copyright (c) 2024 Dilane Kombou
|
|
12
5
|
*
|
|
13
|
-
*
|
|
6
|
+
* This package is inspired by @mdx-js/rollup to provide a custom implement of the MDX plugin for RasenganJs.
|
|
14
7
|
*/
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Stores the resolved Vite configuration for later use.
|
|
20
|
-
*
|
|
21
|
-
* @param resolvedConfig - The resolved Vite configuration object.
|
|
22
|
-
*/
|
|
23
|
-
configResolved(resolvedConfig: unknown): void;
|
|
24
|
-
/**
|
|
25
|
-
* Transforms an MDX file by applying the `@mdx-js/rollup` transformation, extracting frontmatter data, and appending a `metadata` object to the transformed content.
|
|
26
|
-
*
|
|
27
|
-
* @param code - The content of the MDX file.
|
|
28
|
-
* @param id - The ID of the MDX file.
|
|
29
|
-
* @returns An object containing the transformed MDX code and a source map, or `null` if the file is not an MDX file.
|
|
30
|
-
*/
|
|
31
|
-
transform(code: string, id: string): Promise<{
|
|
32
|
-
code: string;
|
|
33
|
-
map: import("rollup").SourceMapInput;
|
|
34
|
-
}>;
|
|
35
|
-
};
|
|
8
|
+
export * from './types/index.js';
|
|
9
|
+
import { plugin } from "./utils/index.js";
|
|
10
|
+
export default plugin;
|
package/lib/index.js
CHANGED
|
@@ -1,72 +1,11 @@
|
|
|
1
|
-
import mdx from '@mdx-js/rollup';
|
|
2
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
3
|
-
import matter from 'gray-matter';
|
|
4
|
-
export * from './types/index.js';
|
|
5
|
-
export * from "./utils/index.js";
|
|
6
|
-
export * from './components/index.js';
|
|
7
1
|
/**
|
|
8
|
-
*
|
|
2
|
+
* License: MIT
|
|
9
3
|
*
|
|
10
|
-
*
|
|
11
|
-
* - Resolves the Vite configuration and stores it for later use.
|
|
12
|
-
* - Transforms MDX files by applying the `@mdx-js/rollup` transformation.
|
|
13
|
-
* - Extracts frontmatter data from the MDX files and creates a `metadata` object.
|
|
14
|
-
* - Appends the `metadata` object to the transformed MDX content.
|
|
4
|
+
* Copyright (c) 2024 Dilane Kombou
|
|
15
5
|
*
|
|
16
|
-
*
|
|
6
|
+
* This package is inspired by @mdx-js/rollup to provide a custom implement of the MDX plugin for RasenganJs.
|
|
17
7
|
*/
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
name: "vite-plugin-rasengan-mdx",
|
|
23
|
-
// Apply transformation of the mdx file before other plugins
|
|
24
|
-
enforce: 'pre',
|
|
25
|
-
/**
|
|
26
|
-
* Stores the resolved Vite configuration for later use.
|
|
27
|
-
*
|
|
28
|
-
* @param resolvedConfig - The resolved Vite configuration object.
|
|
29
|
-
*/
|
|
30
|
-
configResolved(resolvedConfig) {
|
|
31
|
-
// store the resolved config
|
|
32
|
-
config = resolvedConfig;
|
|
33
|
-
},
|
|
34
|
-
/**
|
|
35
|
-
* Transforms an MDX file by applying the `@mdx-js/rollup` transformation, extracting frontmatter data, and appending a `metadata` object to the transformed content.
|
|
36
|
-
*
|
|
37
|
-
* @param code - The content of the MDX file.
|
|
38
|
-
* @param id - The ID of the MDX file.
|
|
39
|
-
* @returns An object containing the transformed MDX code and a source map, or `null` if the file is not an MDX file.
|
|
40
|
-
*/
|
|
41
|
-
async transform(code, id) {
|
|
42
|
-
if (!filter(id)) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
const { content, data: frontmatter } = matter(code);
|
|
46
|
-
// Apply transformation of the mdx file
|
|
47
|
-
const result = await mdx().transform(content, id);
|
|
48
|
-
// Extract the file name from the path
|
|
49
|
-
const fileName = id
|
|
50
|
-
.split("/")
|
|
51
|
-
.pop()
|
|
52
|
-
.replace(/.page.mdx?$/, "");
|
|
53
|
-
// TODO: Consider other params of metadata from frontmatter
|
|
54
|
-
const metadata = {
|
|
55
|
-
path: frontmatter.path || `/${fileName}`,
|
|
56
|
-
metadata: frontmatter.metadata || {
|
|
57
|
-
title: fileName,
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
code: `
|
|
62
|
-
${result.code}
|
|
63
|
-
const metadata = ${JSON.stringify(metadata)};
|
|
64
|
-
|
|
65
|
-
MDXContent.metadata = metadata;
|
|
66
|
-
`,
|
|
67
|
-
map: result.map,
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
}
|
|
8
|
+
export * from './types/index.js';
|
|
9
|
+
import { plugin } from "./utils/index.js";
|
|
10
|
+
export default plugin;
|
|
72
11
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,eAAe,MAAM,CAAC"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a filter function that can be used to filter a list of IDs based on include and exclude patterns.
|
|
3
|
+
*
|
|
4
|
+
* @param include - A string or array of strings representing the patterns to include.
|
|
5
|
+
* @param exclude - A string or array of strings representing the patterns to exclude.
|
|
6
|
+
* @returns A function that takes an ID string and returns `true` if the ID should be included, `false` otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export default function createFilter(include: string, exclude?: string): (id: string) => boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import micromatch from 'micromatch';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a filter function that can be used to filter a list of IDs based on include and exclude patterns.
|
|
4
|
+
*
|
|
5
|
+
* @param include - A string or array of strings representing the patterns to include.
|
|
6
|
+
* @param exclude - A string or array of strings representing the patterns to exclude.
|
|
7
|
+
* @returns A function that takes an ID string and returns `true` if the ID should be included, `false` otherwise.
|
|
8
|
+
*/
|
|
9
|
+
export default function createFilter(include, exclude) {
|
|
10
|
+
return function (id) {
|
|
11
|
+
if (typeof id !== "string")
|
|
12
|
+
return false;
|
|
13
|
+
const matcher = micromatch.matcher(include);
|
|
14
|
+
if (exclude) {
|
|
15
|
+
const excluder = micromatch.matcher(exclude);
|
|
16
|
+
return matcher(id) && !excluder(id);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return matcher(id);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=create-filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-filter.js","sourceRoot":"","sources":["../../src/utils/create-filter.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,OAAe,EACf,OAAgB;IAEhB,OAAO,UAAU,EAAU;QAC1B,IAAI,OAAO,EAAE,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAEvC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE5C,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7C,OAAO,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC;QACrB,CAAC;IACJ,CAAC,CAAC;AACH,CAAC"}
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export {
|
|
1
|
+
import plugin from "./plugin.js";
|
|
2
|
+
export { plugin };
|
package/lib/utils/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export {
|
|
1
|
+
import plugin from "./plugin.js";
|
|
2
|
+
export { plugin };
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Vite plugin that transforms MDX files into a format that can be used in a RasenganJs application.
|
|
3
|
+
*
|
|
4
|
+
* The plugin performs the following tasks:
|
|
5
|
+
* - Resolves the Vite configuration and stores it for later use.
|
|
6
|
+
* - Transforms MDX files by applying the `@mdx-js/rollup` transformation.
|
|
7
|
+
* - Extracts frontmatter data from the MDX files and creates a `metadata` object.
|
|
8
|
+
* - Appends the `metadata` object to the transformed MDX content.
|
|
9
|
+
*
|
|
10
|
+
* The transformed MDX content can then be used in the RasenganJs application, with the `metadata` object providing additional information about the content.
|
|
11
|
+
*/
|
|
12
|
+
export default function plugin(): {
|
|
13
|
+
name: string;
|
|
14
|
+
enforce: string;
|
|
15
|
+
config(config: unknown, env: any): void;
|
|
16
|
+
/**
|
|
17
|
+
* Stores the resolved Vite configuration for later use.
|
|
18
|
+
*
|
|
19
|
+
* @param resolvedConfig - The resolved Vite configuration object.
|
|
20
|
+
*/
|
|
21
|
+
configResolved(resolvedConfig: unknown): void;
|
|
22
|
+
/**
|
|
23
|
+
* Transforms an MDX file by applying the `@mdx-js/rollup` transformation, extracting frontmatter data, and appending a `metadata` object to the transformed content.
|
|
24
|
+
*
|
|
25
|
+
* @param code - The content of the MDX file.
|
|
26
|
+
* @param id - The ID of the MDX file.
|
|
27
|
+
* @returns An object containing the transformed MDX code and a source map, or `null` if the file is not an MDX file.
|
|
28
|
+
*/
|
|
29
|
+
transform(code: string, id: string): Promise<{
|
|
30
|
+
code: string;
|
|
31
|
+
map: import("rollup").SourceMapInput;
|
|
32
|
+
}>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import mdx from '@mdx-js/rollup';
|
|
2
|
+
import matter from 'gray-matter';
|
|
3
|
+
import createFilter from './create-filter.js';
|
|
4
|
+
/**
|
|
5
|
+
* A Vite plugin that transforms MDX files into a format that can be used in a RasenganJs application.
|
|
6
|
+
*
|
|
7
|
+
* The plugin performs the following tasks:
|
|
8
|
+
* - Resolves the Vite configuration and stores it for later use.
|
|
9
|
+
* - Transforms MDX files by applying the `@mdx-js/rollup` transformation.
|
|
10
|
+
* - Extracts frontmatter data from the MDX files and creates a `metadata` object.
|
|
11
|
+
* - Appends the `metadata` object to the transformed MDX content.
|
|
12
|
+
*
|
|
13
|
+
* The transformed MDX content can then be used in the RasenganJs application, with the `metadata` object providing additional information about the content.
|
|
14
|
+
*/
|
|
15
|
+
export default function plugin() {
|
|
16
|
+
let config;
|
|
17
|
+
const filter = createFilter("**/*.md?(x)");
|
|
18
|
+
const mdxInstance = mdx();
|
|
19
|
+
return {
|
|
20
|
+
name: "vite-plugin-rasengan-mdx",
|
|
21
|
+
// Apply transformation of the mdx file before other plugins
|
|
22
|
+
enforce: 'pre',
|
|
23
|
+
config(config, env) {
|
|
24
|
+
mdxInstance.config(config, env);
|
|
25
|
+
},
|
|
26
|
+
/**
|
|
27
|
+
* Stores the resolved Vite configuration for later use.
|
|
28
|
+
*
|
|
29
|
+
* @param resolvedConfig - The resolved Vite configuration object.
|
|
30
|
+
*/
|
|
31
|
+
configResolved(resolvedConfig) {
|
|
32
|
+
// store the resolved config
|
|
33
|
+
config = resolvedConfig;
|
|
34
|
+
},
|
|
35
|
+
/**
|
|
36
|
+
* Transforms an MDX file by applying the `@mdx-js/rollup` transformation, extracting frontmatter data, and appending a `metadata` object to the transformed content.
|
|
37
|
+
*
|
|
38
|
+
* @param code - The content of the MDX file.
|
|
39
|
+
* @param id - The ID of the MDX file.
|
|
40
|
+
* @returns An object containing the transformed MDX code and a source map, or `null` if the file is not an MDX file.
|
|
41
|
+
*/
|
|
42
|
+
async transform(code, id) {
|
|
43
|
+
if (!filter(id)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const { content, data: frontmatter } = matter(code);
|
|
47
|
+
// Apply transformation of the mdx file
|
|
48
|
+
const result = await mdxInstance.transform(content, id);
|
|
49
|
+
// Extract the file name from the path
|
|
50
|
+
const fileName = id
|
|
51
|
+
.split("/")
|
|
52
|
+
.pop()
|
|
53
|
+
.replace(/.page.mdx?$/, "");
|
|
54
|
+
// TODO: Consider other params of metadata from frontmatter
|
|
55
|
+
const metadata = {
|
|
56
|
+
path: frontmatter.path || `/${fileName}`,
|
|
57
|
+
metadata: frontmatter.metadata || {
|
|
58
|
+
title: fileName,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
code: `
|
|
63
|
+
${result.code}
|
|
64
|
+
const metadata = ${JSON.stringify(metadata)};
|
|
65
|
+
|
|
66
|
+
MDXContent.metadata = metadata;
|
|
67
|
+
`,
|
|
68
|
+
map: result.map,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/utils/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,gBAAgB,CAAA;AAChC,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM;IAC7B,IAAI,MAAe,CAAC;IACpB,MAAM,MAAM,GAAG,YAAY,CAAC,aAAa,CAAC,CAAC;IAC3C,MAAM,WAAW,GAAI,GAAG,EAAE,CAAC;IAE3B,OAAO;QACN,IAAI,EAAE,0BAA0B;QAEhC,4DAA4D;QAC5D,OAAO,EAAE,KAAK;QAEd,MAAM,CAAC,MAAe,EAAE,GAAQ;YAC/B,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACjC,CAAC;QAED;;;;WAIG;QACH,cAAc,CAAC,cAAuB;YACrC,4BAA4B;YAC5B,MAAM,GAAG,cAAc,CAAC;QACzB,CAAC;QAED;;;;;;WAMG;QACH,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,EAAU;YACvC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;gBACjB,OAAO,IAAI,CAAC;YACb,CAAC;YAED,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAEpD,uCAAuC;YACvC,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAExD,sCAAsC;YACtC,MAAM,QAAQ,GAAG,EAAE;iBACjB,KAAK,CAAC,GAAG,CAAC;iBACV,GAAG,EAAE;iBACL,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;YAE7B,2DAA2D;YAC3D,MAAM,QAAQ,GAAG;gBAChB,IAAI,EAAE,WAAW,CAAC,IAAI,IAAI,IAAI,QAAQ,EAAE;gBACxC,QAAQ,EAAE,WAAW,CAAC,QAAQ,IAAI;oBACjC,KAAK,EAAE,QAAQ;iBACf;aACD,CAAC;YAEF,OAAO;gBACN,IAAI,EAAE;YACE,MAAM,CAAC,IAAI;6BACM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;;;SAG5C;gBACL,GAAG,EAAE,MAAM,CAAC,GAAG;aACf,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,49 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
"name": "@rasenganjs/mdx",
|
|
3
|
+
"private": false,
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"description": "RasenganJS plugin for MDX support",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./lib/index.js",
|
|
11
|
+
"require": "./lib/index.js",
|
|
12
|
+
"types": "./lib/types/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "dilane3",
|
|
17
|
+
"email": "komboudilane125@gmail.com",
|
|
18
|
+
"url": "https://dilane3.com",
|
|
19
|
+
"twitter": "https://twitter.com/dilanekombou",
|
|
20
|
+
"github": "https://github.com/dilane3"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/rasengan-dev/rasengan-mdx-plugin.git",
|
|
25
|
+
"issues": "https://github.com/rasengan-dev/rasengan-mdx-plugin/issues"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build:clean": "rm -rf ./lib",
|
|
30
|
+
"build": "npm run build:clean && tsc",
|
|
31
|
+
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
|
|
32
|
+
"pack": "npm pack --pack-destination ./release",
|
|
33
|
+
"deploy": "npm publish --access public"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/micromatch": "^4.0.7",
|
|
37
|
+
"@types/node": "^22.7.4",
|
|
38
|
+
"@types/react": "^18.0.0",
|
|
39
|
+
"typescript": "^5.2.2"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@mdx-js/rollup": "^3.0.1",
|
|
43
|
+
"gray-matter": "^4.0.3",
|
|
44
|
+
"micromatch": "^4.0.7",
|
|
45
|
+
"path-browserify": "^1.0.1",
|
|
46
|
+
"prism-react-renderer": "^2.3.1",
|
|
47
|
+
"prismjs": "^1.29.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"rasengan": "*",
|
|
51
|
+
"react": "^18.3.1"
|
|
52
|
+
}
|
|
49
53
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type PageComponent } from "rasengan";
|
|
2
|
-
import { MDXPageComponent } from "../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Generates a React component from an MDXPageComponent.
|
|
5
|
-
*
|
|
6
|
-
* @param MDXPage - The MDXPageComponent to generate the React component from.
|
|
7
|
-
* @param className - An optional CSS class name to apply to the MDXRenderer component.
|
|
8
|
-
* @returns A React component that renders the MDXPage content using the MDXRenderer.
|
|
9
|
-
*/
|
|
10
|
-
export default function generatePage(MDXPage: MDXPageComponent, className?: string): PageComponent;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { MDXRenderer } from "../components/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Generates a React component from an MDXPageComponent.
|
|
5
|
-
*
|
|
6
|
-
* @param MDXPage - The MDXPageComponent to generate the React component from.
|
|
7
|
-
* @param className - An optional CSS class name to apply to the MDXRenderer component.
|
|
8
|
-
* @returns A React component that renders the MDXPage content using the MDXRenderer.
|
|
9
|
-
*/
|
|
10
|
-
export default function generatePage(MDXPage, className = "") {
|
|
11
|
-
const Page = () => {
|
|
12
|
-
return _jsx(MDXRenderer, { className: className, children: MDXPage });
|
|
13
|
-
};
|
|
14
|
-
Page.path = MDXPage.metadata.path;
|
|
15
|
-
Page.metadata = MDXPage.metadata.metadata;
|
|
16
|
-
return Page;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=generate-page.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generate-page.js","sourceRoot":"","sources":["../../src/utils/generate-page.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,OAAyB,EACzB,SAAS,GAAG,EAAE;IAEd,MAAM,IAAI,GAAkB,GAAG,EAAE;QAChC,OAAO,KAAC,WAAW,IAAC,SAAS,EAAE,SAAS,YAAG,OAAO,GAAe,CAAC;IACnE,CAAC,CAAC;IAEF,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IAClC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAE1C,OAAO,IAAI,CAAC;AACb,CAAC"}
|
package/src/components/index.tsx
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { themes, Highlight } from "prism-react-renderer";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { MDXPageComponent } from "../types/index.js";
|
|
4
|
-
|
|
5
|
-
type ComponentWithTextChildrenProps = {
|
|
6
|
-
children: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
type MDXRendererProps = {
|
|
10
|
-
children: MDXPageComponent;
|
|
11
|
-
className?: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type CodeBlockProps = ComponentWithTextChildrenProps & {
|
|
15
|
-
className?: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* A React component that renders a code block with syntax highlighting and a copy button.
|
|
21
|
-
*
|
|
22
|
-
* The component uses the `prism-react-renderer` library to provide syntax highlighting for the code block.
|
|
23
|
-
* It also includes a copy button that allows the user to copy the code to their clipboard.
|
|
24
|
-
*
|
|
25
|
-
* @param {object} props - The component props.
|
|
26
|
-
* @param {string} props.children - The code content to be displayed in the code block.
|
|
27
|
-
* @param {string} [props.className] - The CSS class name to apply to the code block.
|
|
28
|
-
* @returns {React.ReactElement} - The rendered code block component.
|
|
29
|
-
*/
|
|
30
|
-
const CodeBlock = ({ children, className = "" }: CodeBlockProps): React.ReactElement => {
|
|
31
|
-
const language = className.replace(/language-/, "");
|
|
32
|
-
|
|
33
|
-
if (!language) {
|
|
34
|
-
return <SimpleBlock>{children}</SimpleBlock>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<Highlight
|
|
39
|
-
theme={themes.oneDark}
|
|
40
|
-
code={children.trim()}
|
|
41
|
-
language={language}
|
|
42
|
-
>
|
|
43
|
-
{({ className, tokens, getLineProps, getTokenProps }: any) => {
|
|
44
|
-
const [copied, setCopied] = React.useState(false);
|
|
45
|
-
|
|
46
|
-
React.useEffect(() => {
|
|
47
|
-
/**
|
|
48
|
-
* Sets the `copied` state to `false` after 2 seconds, effectively hiding the "copied" indicator.
|
|
49
|
-
* This function is called after the user's clipboard is updated with the code content.
|
|
50
|
-
*/
|
|
51
|
-
const timer = setTimeout(() => {
|
|
52
|
-
setCopied(false);
|
|
53
|
-
}, 2000);
|
|
54
|
-
|
|
55
|
-
return () => clearTimeout(timer);
|
|
56
|
-
}, [copied]);
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Copies the trimmed text content of the `children` prop to the user's clipboard.
|
|
60
|
-
* This function is called when the "Copy" button is clicked in the code block component.
|
|
61
|
-
* It sets the `copied` state to `true` for 2 seconds to display a "copied" indicator.
|
|
62
|
-
*/
|
|
63
|
-
const handleCopy = () => {
|
|
64
|
-
navigator.clipboard.writeText(children.trim());
|
|
65
|
-
setCopied(true);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<pre
|
|
70
|
-
className={className}
|
|
71
|
-
style={{
|
|
72
|
-
color: "#fff",
|
|
73
|
-
backgroundColor: "#1d2529",
|
|
74
|
-
borderRadius: "20px",
|
|
75
|
-
overflow: "hidden",
|
|
76
|
-
padding: "0px",
|
|
77
|
-
}}
|
|
78
|
-
>
|
|
79
|
-
<div
|
|
80
|
-
style={{
|
|
81
|
-
width: "100%",
|
|
82
|
-
height: "50px",
|
|
83
|
-
backgroundColor: "#28373f",
|
|
84
|
-
display: "flex",
|
|
85
|
-
justifyContent: "space-between",
|
|
86
|
-
alignItems: "center",
|
|
87
|
-
paddingLeft: "20px",
|
|
88
|
-
paddingRight: "20px",
|
|
89
|
-
}}
|
|
90
|
-
>
|
|
91
|
-
<span>Filename</span>
|
|
92
|
-
|
|
93
|
-
<button className='copy-button' onClick={handleCopy}>
|
|
94
|
-
{copied ? (
|
|
95
|
-
<svg
|
|
96
|
-
xmlns='http://www.w3.org/2000/svg'
|
|
97
|
-
viewBox='0 0 24 24'
|
|
98
|
-
width='24'
|
|
99
|
-
height='24'
|
|
100
|
-
color='#f0f0f0'
|
|
101
|
-
fill='none'
|
|
102
|
-
>
|
|
103
|
-
<path
|
|
104
|
-
d='M22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22C17.5228 22 22 17.5228 22 12Z'
|
|
105
|
-
stroke='currentColor'
|
|
106
|
-
strokeWidth='1.5'
|
|
107
|
-
/>
|
|
108
|
-
<path
|
|
109
|
-
d='M8 12.5L10.5 15L16 9'
|
|
110
|
-
stroke='currentColor'
|
|
111
|
-
strokeWidth='1.5'
|
|
112
|
-
strokeLinecap='round'
|
|
113
|
-
strokeLinejoin='round'
|
|
114
|
-
/>
|
|
115
|
-
</svg>
|
|
116
|
-
) : (
|
|
117
|
-
<svg
|
|
118
|
-
xmlns='http://www.w3.org/2000/svg'
|
|
119
|
-
viewBox='0 0 24 24'
|
|
120
|
-
width='24'
|
|
121
|
-
height='24'
|
|
122
|
-
color='#f0f0f0'
|
|
123
|
-
fill='none'
|
|
124
|
-
>
|
|
125
|
-
<path
|
|
126
|
-
d='M9 15C9 12.1716 9 10.7574 9.87868 9.87868C10.7574 9 12.1716 9 15 9L16 9C18.8284 9 20.2426 9 21.1213 9.87868C22 10.7574 22 12.1716 22 15V16C22 18.8284 22 20.2426 21.1213 21.1213C20.2426 22 18.8284 22 16 22H15C12.1716 22 10.7574 22 9.87868 21.1213C9 20.2426 9 18.8284 9 16L9 15Z'
|
|
127
|
-
stroke='currentColor'
|
|
128
|
-
strokeWidth='1.5'
|
|
129
|
-
strokeLinecap='round'
|
|
130
|
-
strokeLinejoin='round'
|
|
131
|
-
/>
|
|
132
|
-
<path
|
|
133
|
-
d='M16.9999 9C16.9975 6.04291 16.9528 4.51121 16.092 3.46243C15.9258 3.25989 15.7401 3.07418 15.5376 2.90796C14.4312 2 12.7875 2 9.5 2C6.21252 2 4.56878 2 3.46243 2.90796C3.25989 3.07417 3.07418 3.25989 2.90796 3.46243C2 4.56878 2 6.21252 2 9.5C2 12.7875 2 14.4312 2.90796 15.5376C3.07417 15.7401 3.25989 15.9258 3.46243 16.092C4.51121 16.9528 6.04291 16.9975 9 16.9999'
|
|
134
|
-
stroke='currentColor'
|
|
135
|
-
strokeWidth='1.5'
|
|
136
|
-
strokeLinecap='round'
|
|
137
|
-
strokeLinejoin='round'
|
|
138
|
-
/>
|
|
139
|
-
</svg>
|
|
140
|
-
)}
|
|
141
|
-
</button>
|
|
142
|
-
</div>
|
|
143
|
-
|
|
144
|
-
<div
|
|
145
|
-
style={{
|
|
146
|
-
padding: "20px",
|
|
147
|
-
fontSize: "14px",
|
|
148
|
-
}}
|
|
149
|
-
>
|
|
150
|
-
<code>
|
|
151
|
-
{tokens.map((line: any, i: number) => (
|
|
152
|
-
<div key={i} {...getLineProps({ line })}>
|
|
153
|
-
<span
|
|
154
|
-
style={{
|
|
155
|
-
opacity: 0.6,
|
|
156
|
-
marginRight: "5px",
|
|
157
|
-
}}
|
|
158
|
-
>
|
|
159
|
-
{i + 1}
|
|
160
|
-
</span>
|
|
161
|
-
<span> </span>
|
|
162
|
-
{line.map((token: any, key: number) => (
|
|
163
|
-
<span key={key} {...getTokenProps({ token })} />
|
|
164
|
-
))}
|
|
165
|
-
</div>
|
|
166
|
-
))}
|
|
167
|
-
</code>
|
|
168
|
-
</div>
|
|
169
|
-
</pre>
|
|
170
|
-
);
|
|
171
|
-
}}
|
|
172
|
-
</Highlight>
|
|
173
|
-
);
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const SimpleBlock = ({ children }: ComponentWithTextChildrenProps): React.ReactElement => {
|
|
177
|
-
return (
|
|
178
|
-
<span
|
|
179
|
-
className="simple-block"
|
|
180
|
-
style={{
|
|
181
|
-
fontSize: "14px",
|
|
182
|
-
borderRadius: "5px",
|
|
183
|
-
paddingLeft: "3.6px",
|
|
184
|
-
paddingRight: "3.6px",
|
|
185
|
-
paddingTop: "2px",
|
|
186
|
-
paddingBottom: "2px",
|
|
187
|
-
marginInline: "0px",
|
|
188
|
-
backgroundColor: "#f7f7f7",
|
|
189
|
-
border: "1px solid #f0f0f0",
|
|
190
|
-
}}
|
|
191
|
-
>{children}</span>
|
|
192
|
-
);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Renders an MDX content component with a custom code block component.
|
|
197
|
-
*
|
|
198
|
-
* @param {MDXRendererProps} props - The props for the MDX renderer.
|
|
199
|
-
* @param {React.ReactNode} props.children - The MDX content to render.
|
|
200
|
-
* @param {string} [props.className] - An optional CSS class name to apply to the rendered section.
|
|
201
|
-
* @returns {React.ReactElement} - The rendered MDX content with the custom code block component.
|
|
202
|
-
*/
|
|
203
|
-
const MDXRenderer = ({ children: MDXContent, className }: MDXRendererProps): React.ReactElement => {
|
|
204
|
-
return (
|
|
205
|
-
<section className={"rasengan-markdown-body " + className}>
|
|
206
|
-
<MDXContent
|
|
207
|
-
components={{
|
|
208
|
-
code: CodeBlock,
|
|
209
|
-
}}
|
|
210
|
-
/>
|
|
211
|
-
</section>
|
|
212
|
-
);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
export {
|
|
216
|
-
MDXRenderer,
|
|
217
|
-
CodeBlock,
|
|
218
|
-
SimpleBlock
|
|
219
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import mdx from '@mdx-js/rollup'
|
|
2
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
3
|
-
import matter from 'gray-matter';
|
|
4
|
-
|
|
5
|
-
export * from './types/index.js';
|
|
6
|
-
export * from "./utils/index.js";
|
|
7
|
-
export * from './components/index.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A Vite plugin that transforms MDX files into a format that can be used in a RasenganJs application.
|
|
11
|
-
*
|
|
12
|
-
* The plugin performs the following tasks:
|
|
13
|
-
* - Resolves the Vite configuration and stores it for later use.
|
|
14
|
-
* - Transforms MDX files by applying the `@mdx-js/rollup` transformation.
|
|
15
|
-
* - Extracts frontmatter data from the MDX files and creates a `metadata` object.
|
|
16
|
-
* - Appends the `metadata` object to the transformed MDX content.
|
|
17
|
-
*
|
|
18
|
-
* The transformed MDX content can then be used in the RasenganJs application, with the `metadata` object providing additional information about the content.
|
|
19
|
-
*/
|
|
20
|
-
export default function rasengan() {
|
|
21
|
-
let config: unknown;
|
|
22
|
-
const filter = createFilter(/\.mdx?$/);
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
name: "vite-plugin-rasengan-mdx",
|
|
26
|
-
|
|
27
|
-
// Apply transformation of the mdx file before other plugins
|
|
28
|
-
enforce: 'pre',
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Stores the resolved Vite configuration for later use.
|
|
32
|
-
*
|
|
33
|
-
* @param resolvedConfig - The resolved Vite configuration object.
|
|
34
|
-
*/
|
|
35
|
-
configResolved(resolvedConfig: unknown) {
|
|
36
|
-
// store the resolved config
|
|
37
|
-
config = resolvedConfig;
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Transforms an MDX file by applying the `@mdx-js/rollup` transformation, extracting frontmatter data, and appending a `metadata` object to the transformed content.
|
|
42
|
-
*
|
|
43
|
-
* @param code - The content of the MDX file.
|
|
44
|
-
* @param id - The ID of the MDX file.
|
|
45
|
-
* @returns An object containing the transformed MDX code and a source map, or `null` if the file is not an MDX file.
|
|
46
|
-
*/
|
|
47
|
-
async transform(code: string, id: string) {
|
|
48
|
-
if (!filter(id)) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const { content, data: frontmatter } = matter(code);
|
|
53
|
-
|
|
54
|
-
// Apply transformation of the mdx file
|
|
55
|
-
const result = await mdx().transform(content, id);
|
|
56
|
-
|
|
57
|
-
// Extract the file name from the path
|
|
58
|
-
const fileName = id
|
|
59
|
-
.split("/")
|
|
60
|
-
.pop()
|
|
61
|
-
.replace(/.page.mdx?$/, "");
|
|
62
|
-
|
|
63
|
-
// TODO: Consider other params of metadata from frontmatter
|
|
64
|
-
const metadata = {
|
|
65
|
-
path: frontmatter.path || `/${fileName}`,
|
|
66
|
-
metadata: frontmatter.metadata || {
|
|
67
|
-
title: fileName,
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
code: `
|
|
73
|
-
${result.code}
|
|
74
|
-
const metadata = ${JSON.stringify(metadata)};
|
|
75
|
-
|
|
76
|
-
MDXContent.metadata = metadata;
|
|
77
|
-
`,
|
|
78
|
-
map: result.map,
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}
|
package/src/types/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {type Metadata } from "rasengan";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A React functional component that represents an MDX page.
|
|
5
|
-
*
|
|
6
|
-
* The `MDXPageComponent` type extends the `React.FC<ReactComponentProps>` type, which means it is a React functional component that accepts the standard props for a React component.
|
|
7
|
-
*
|
|
8
|
-
* The `MDXPageComponent` type also has an optional `metadata` property of type `Metadata`, which can be used to store metadata about the page.
|
|
9
|
-
*/
|
|
10
|
-
export type MDXPageComponent = React.FC<any> & {
|
|
11
|
-
metadata?: {
|
|
12
|
-
path: string;
|
|
13
|
-
metadata: Metadata;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type PageComponent } from "rasengan";
|
|
2
|
-
import { MDXPageComponent } from "../types/index.js";
|
|
3
|
-
import { MDXRenderer } from "../components/index.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generates a React component from an MDXPageComponent.
|
|
7
|
-
*
|
|
8
|
-
* @param MDXPage - The MDXPageComponent to generate the React component from.
|
|
9
|
-
* @param className - An optional CSS class name to apply to the MDXRenderer component.
|
|
10
|
-
* @returns A React component that renders the MDXPage content using the MDXRenderer.
|
|
11
|
-
*/
|
|
12
|
-
export default function generatePage(
|
|
13
|
-
MDXPage: MDXPageComponent,
|
|
14
|
-
className = ""
|
|
15
|
-
): PageComponent {
|
|
16
|
-
const Page: PageComponent = () => {
|
|
17
|
-
return <MDXRenderer className={className}>{MDXPage}</MDXRenderer>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
Page.path = MDXPage.metadata.path;
|
|
21
|
-
Page.metadata = MDXPage.metadata.metadata;
|
|
22
|
-
|
|
23
|
-
return Page;
|
|
24
|
-
}
|
package/src/utils/index.ts
DELETED