@kiln-js/md 0.1.1 → 0.2.0-hotfix

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zxsty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @kiln-js/md
2
+
3
+ [![npm](https://img.shields.io/npm/v/%40kiln-js%2Fmd)](https://www.npmjs.com/package/@kiln-js/md)
4
+ [![license](https://img.shields.io/npm/l/%40kiln-js%2Fmd)](LICENSE)
5
+
6
+ Markdown pages for Kiln with customizable tag components
7
+
8
+ Part of [Kiln](https://github.com/kiln-js/kiln), a file-based server-side rendering framework for React and Vite.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ bun add -d @kiln-js/md
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { defineConfig } from "vite";
20
+ import { md } from "@kiln-js/md";
21
+
22
+ export default defineConfig({
23
+ plugins: [md({ dir: "app/pages", components: "app/markdown.tsx" })],
24
+ });
25
+ ```
26
+
27
+ ## Styling
28
+
29
+ Every Markdown tag is rendered by a component in the module you pass as `components`.
30
+ Tags you do not override render as plain HTML. Markdown files in `app/pages` become routes.
31
+
32
+ ## Documentation
33
+
34
+ See the [Kiln repository](https://github.com/kiln-js/kiln) for the full API reference and guides.
35
+
36
+ ## Development
37
+
38
+ This repository is generated from the Kiln monorepo. Make changes there, then run `scripts/publish-repo.ps1` to publish them here. Report issues in this repository, and send pull requests to the monorepo.
39
+
40
+ ## License
41
+
42
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { KilnPlugin } from "@kiln-js/vite-plugin";
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): KilnPlugin;
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
- const file = norm(source);
89
- if (file.endsWith(".md") && file.startsWith(pagesRoot)) {
90
- return source + SUFFIX;
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, such as app/markdown.tsx */
5
+ /** Module whose default export maps tag names to components. */
6
6
  components?: string;
7
- /** Allow raw HTML inside Markdown. Enable only for trusted content. Default: false */
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,51 @@
1
1
  {
2
- "name": "@kiln-js/md",
3
- "version": "0.1.1",
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 && tsc -p tsconfig.json --emitDeclarationOnly",
33
- "typecheck": "tsc -p tsconfig.json --noEmit",
34
- "prepublishOnly": "bun run build"
35
- },
36
- "dependencies": {
37
- "@kiln-js/vite-plugin": "*",
38
- "marked": "^14.1.2"
39
- },
40
- "peerDependencies": {
41
- "react": ">=18",
42
- "vite": ">=5"
43
- },
44
- "devDependencies": {
45
- "@types/node": "^22.0.0",
46
- "@types/react": "^18.3.0",
47
- "react": "^18.3.1",
48
- "vite": "5.4.21"
49
- }
2
+ "name": "@kiln-js/md",
3
+ "version": "0.2.0-hotfix",
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
+ "repository": "github:kiln-js/md",
29
+ "homepage": "https://kiln-js.vercel.app",
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "build": "bun build ./src/index.ts ./src/runtime.ts --outdir ./dist --target bun --packages external \u0026\u0026 tsc -p tsconfig.json --emitDeclarationOnly",
35
+ "typecheck": "tsc -p tsconfig.json --noEmit",
36
+ "prepublishOnly": "bun run build"
37
+ },
38
+ "dependencies": {
39
+ "marked": "^14.1.2"
40
+ },
41
+ "peerDependencies": {
42
+ "react": "\u003e=18",
43
+ "vite": "\u003e=5"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.0.0",
47
+ "@types/react": "^18.3.0",
48
+ "react": "^18.3.1",
49
+ "vite": "5.4.21"
50
+ }
50
51
  }