@kiln-js/md 0.1.0 → 0.1.1
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.js +22 -7
- package/dist/plugin.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/plugin.ts
|
|
3
|
+
import fs from "fs";
|
|
3
4
|
import path from "path";
|
|
4
5
|
|
|
5
6
|
// src/parse.ts
|
|
@@ -51,6 +52,7 @@ function parseMarkdown(src) {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
// src/plugin.ts
|
|
55
|
+
var SUFFIX = ".kiln-md.tsx";
|
|
54
56
|
var norm = (p) => p.replace(/\\/g, "/");
|
|
55
57
|
function generateModule(src, opts) {
|
|
56
58
|
const { frontmatter, tokens, headings } = parseMarkdown(src);
|
|
@@ -71,17 +73,30 @@ function generateModule(src, opts) {
|
|
|
71
73
|
`);
|
|
72
74
|
}
|
|
73
75
|
function mdPlugin(opts = {}) {
|
|
74
|
-
const pagesRoot = norm(path.resolve(process.cwd(), opts.dir ?? "app/pages")) + "/";
|
|
75
|
-
const components = opts.components ? norm(path.resolve(process.cwd(), opts.components)) : undefined;
|
|
76
76
|
const html = opts.html ?? false;
|
|
77
|
+
let root = process.cwd();
|
|
78
|
+
let pagesRoot = "";
|
|
79
|
+
let components = "";
|
|
77
80
|
return {
|
|
78
81
|
name: "kiln:md",
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
configResolved(config) {
|
|
83
|
+
root = config.root;
|
|
84
|
+
pagesRoot = norm(path.resolve(root, opts.dir ?? "app/pages")) + "/";
|
|
85
|
+
components = opts.components ? norm(path.resolve(root, opts.components)) : "";
|
|
86
|
+
},
|
|
87
|
+
resolveId(source) {
|
|
88
|
+
const file = norm(source);
|
|
89
|
+
if (file.endsWith(".md") && file.startsWith(pagesRoot)) {
|
|
90
|
+
return source + SUFFIX;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
load(id) {
|
|
94
|
+
if (!id.endsWith(SUFFIX))
|
|
83
95
|
return;
|
|
84
|
-
|
|
96
|
+
const mdPath = id.slice(0, -SUFFIX.length);
|
|
97
|
+
const src = fs.readFileSync(mdPath, "utf8");
|
|
98
|
+
this.addWatchFile(mdPath);
|
|
99
|
+
return { code: generateModule(src, { components, html }), map: null };
|
|
85
100
|
}
|
|
86
101
|
};
|
|
87
102
|
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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, such as app/markdown.tsx */
|
|
6
6
|
components?: string;
|
|
7
7
|
/** Allow raw HTML inside Markdown. Enable only for trusted content. Default: false */
|
|
8
8
|
html?: boolean;
|