@kiln-js/md 0.1.1 → 0.1.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/dist/index.d.ts +2 -2
- package/dist/index.js +15 -10
- package/dist/plugin.d.ts +2 -2
- package/package.json +47 -48
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
2
|
import { type MdOptions } from "./plugin";
|
|
3
3
|
export type { MdOptions } from "./plugin";
|
|
4
|
-
export declare function md(options?: MdOptions):
|
|
4
|
+
export declare function md(options?: MdOptions): Plugin;
|
|
5
5
|
export default md;
|
package/dist/index.js
CHANGED
|
@@ -77,6 +77,7 @@ function mdPlugin(opts = {}) {
|
|
|
77
77
|
let root = process.cwd();
|
|
78
78
|
let pagesRoot = "";
|
|
79
79
|
let components = "";
|
|
80
|
+
const isPage = (file) => norm(file).endsWith(".md") && norm(file).startsWith(pagesRoot);
|
|
80
81
|
return {
|
|
81
82
|
name: "kiln:md",
|
|
82
83
|
configResolved(config) {
|
|
@@ -84,29 +85,33 @@ function mdPlugin(opts = {}) {
|
|
|
84
85
|
pagesRoot = norm(path.resolve(root, opts.dir ?? "app/pages")) + "/";
|
|
85
86
|
components = opts.components ? norm(path.resolve(root, opts.components)) : "";
|
|
86
87
|
},
|
|
87
|
-
resolveId(source) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
resolveId(source, importer) {
|
|
89
|
+
if (!source.endsWith(".md"))
|
|
90
|
+
return;
|
|
91
|
+
const abs = path.isAbsolute(source) ? source : path.resolve(importer ? path.dirname(importer.split("?")[0]) : root, source);
|
|
92
|
+
if (isPage(abs))
|
|
93
|
+
return norm(abs) + SUFFIX;
|
|
92
94
|
},
|
|
93
95
|
load(id) {
|
|
94
96
|
if (!id.endsWith(SUFFIX))
|
|
95
97
|
return;
|
|
96
98
|
const mdPath = id.slice(0, -SUFFIX.length);
|
|
97
|
-
const src = fs.readFileSync(mdPath, "utf8");
|
|
98
99
|
this.addWatchFile(mdPath);
|
|
100
|
+
const src = fs.readFileSync(mdPath, "utf8");
|
|
99
101
|
return { code: generateModule(src, { components, html }), map: null };
|
|
102
|
+
},
|
|
103
|
+
transform(code, id) {
|
|
104
|
+
const file = id.split("?")[0];
|
|
105
|
+
if (!isPage(file))
|
|
106
|
+
return;
|
|
107
|
+
return { code: generateModule(code, { components, html }), map: null };
|
|
100
108
|
}
|
|
101
109
|
};
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
// src/index.ts
|
|
105
113
|
function md(options = {}) {
|
|
106
|
-
return
|
|
107
|
-
name: "@kiln-js/md",
|
|
108
|
-
vite: () => [mdPlugin(options)]
|
|
109
|
-
};
|
|
114
|
+
return mdPlugin(options);
|
|
110
115
|
}
|
|
111
116
|
var src_default = md;
|
|
112
117
|
export {
|
package/dist/plugin.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import type { Plugin } from "vite";
|
|
|
2
2
|
export interface MdOptions {
|
|
3
3
|
/** Folder whose .md files become pages. Default: app/pages */
|
|
4
4
|
dir?: string;
|
|
5
|
-
/** Module whose default export maps tag names to components
|
|
5
|
+
/** Module whose default export maps tag names to components. */
|
|
6
6
|
components?: string;
|
|
7
|
-
/** Allow raw HTML inside Markdown.
|
|
7
|
+
/** Allow raw HTML inside Markdown. Default: false */
|
|
8
8
|
html?: boolean;
|
|
9
9
|
}
|
|
10
10
|
export declare function generateModule(src: string, opts: {
|
package/package.json
CHANGED
|
@@ -1,50 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name":
|
|
3
|
-
"version":
|
|
4
|
-
"description":
|
|
5
|
-
"license":
|
|
6
|
-
"type":
|
|
7
|
-
"exports":
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"files":
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"keywords":
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"publishConfig":
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"scripts":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"dependencies":
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
2
|
+
"name": "@kiln-js/md",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Markdown pages for Kiln with customizable tag components",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./runtime": {
|
|
13
|
+
"types": "./dist/runtime.d.ts",
|
|
14
|
+
"import": "./dist/runtime.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"kiln",
|
|
23
|
+
"markdown",
|
|
24
|
+
"mdx",
|
|
25
|
+
"react",
|
|
26
|
+
"ssr"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "bun build ./src/index.ts ./src/runtime.ts --outdir ./dist --target bun --packages external \u0026\u0026 tsc -p tsconfig.json --emitDeclarationOnly",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
34
|
+
"prepublishOnly": "bun run build"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"marked": "^14.1.2"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"react": "\u003e=18",
|
|
41
|
+
"vite": "\u003e=5"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^22.0.0",
|
|
45
|
+
"@types/react": "^18.3.0",
|
|
46
|
+
"react": "^18.3.1",
|
|
47
|
+
"vite": "5.4.21"
|
|
48
|
+
}
|
|
50
49
|
}
|