@mdwrk/lander-markdown-content-adapter 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/README.md +38 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @mdwrk/lander-markdown-content-adapter
|
|
2
|
+
|
|
3
|
+
**Markdown and frontmatter adapter**
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://github.com/groupsum/markdown_workspace/blob/master/packages/lander/lander-markdown-content-adapter/README.md"><img alt="Hits" src="https://visitor-badge.laobi.icu/badge?page_id=groupsum.markdown_workspace.packages_lander_lander_markdown_content_adapter_README&left_text=hits" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/@mdwrk/lander-markdown-content-adapter"><img alt="Downloads" src="https://img.shields.io/npm/dm/%40mdwrk%2Flander-markdown-content-adapter?label=downloads" /></a>
|
|
8
|
+
<a href="../../../package.json"><img alt="Node" src="https://img.shields.io/badge/node-20.x%20%7C%2021.x%20%7C%2022.x-339933?logo=node.js&logoColor=white" /></a>
|
|
9
|
+
<a href="../../../LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" /></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
This package converts frontmatter-plus-body markdown into lander page specs.
|
|
13
|
+
|
|
14
|
+
## Why
|
|
15
|
+
Use it when your source of truth is markdown files and you still want to target the lander content contract cleanly.
|
|
16
|
+
|
|
17
|
+
## What
|
|
18
|
+
- Frontmatter splitting and simple parsing.
|
|
19
|
+
- Markdown body adaptation into a page-spec structure.
|
|
20
|
+
- A bridge between source markdown files and the lander compiler.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
Node.js 20.x through 22.x, matching the workspace engine contract in the root package manifest.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @mdwrk/lander-markdown-content-adapter @mdwrk/lander-core
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
```ts
|
|
31
|
+
import { markdownToPageSpec } from "@mdwrk/lander-markdown-content-adapter";
|
|
32
|
+
|
|
33
|
+
const parsed = markdownToPageSpec("---\ntitle: Hello\nslug: /hello/\n---\nMdWrk body copy.");
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Related
|
|
37
|
+
- [Packages index](../../README.md) - family and package navigation
|
|
38
|
+
- [Root README](../../../README.md) - repo overview
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PageSpec } from "@mdwrk/lander-content-contract";
|
|
2
|
+
import { LANDER_MARKDOWN_CONTENT_ADAPTER_VERSION } from "./version.js";
|
|
3
|
+
export { LANDER_MARKDOWN_CONTENT_ADAPTER_VERSION };
|
|
4
|
+
export interface ParsedMarkdownPage {
|
|
5
|
+
metadata: Record<string, unknown>;
|
|
6
|
+
body: string;
|
|
7
|
+
page: PageSpec;
|
|
8
|
+
}
|
|
9
|
+
export declare function splitFrontmatter(raw: string): {
|
|
10
|
+
frontmatter: string;
|
|
11
|
+
body: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function parseSimpleFrontmatter(frontmatter: string): Record<string, unknown>;
|
|
14
|
+
export declare function markdownToPageSpec(raw: string): ParsedMarkdownPage;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAElF,OAAO,EAAE,uCAAuC,EAAE,MAAM,cAAc,CAAC;AAEvE,OAAO,EAAE,uCAAuC,EAAE,CAAC;AAEnD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;CAChB;AAUD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAKnF;AAED,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CASnF;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CA2BlE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { normalizeRouteSlug } from "@mdwrk/lander-core";
|
|
2
|
+
import { LANDER_MARKDOWN_CONTENT_ADAPTER_VERSION } from "./version.js";
|
|
3
|
+
export { LANDER_MARKDOWN_CONTENT_ADAPTER_VERSION };
|
|
4
|
+
const parseScalar = (value) => {
|
|
5
|
+
const trimmed = value.trim();
|
|
6
|
+
if (trimmed === "true")
|
|
7
|
+
return true;
|
|
8
|
+
if (trimmed === "false")
|
|
9
|
+
return false;
|
|
10
|
+
if (/^["'].*["']$/.test(trimmed))
|
|
11
|
+
return trimmed.slice(1, -1);
|
|
12
|
+
return trimmed;
|
|
13
|
+
};
|
|
14
|
+
export function splitFrontmatter(raw) {
|
|
15
|
+
const normalized = String(raw ?? "").replace(/^\uFEFF/, "").replace(/\r\n?/g, "\n");
|
|
16
|
+
const match = /^---\n([\s\S]*?)\n---\n?/.exec(normalized);
|
|
17
|
+
if (!match)
|
|
18
|
+
return { frontmatter: "", body: normalized.trim() };
|
|
19
|
+
return { frontmatter: match[1] ?? "", body: normalized.slice(match[0].length).trim() };
|
|
20
|
+
}
|
|
21
|
+
export function parseSimpleFrontmatter(frontmatter) {
|
|
22
|
+
const output = {};
|
|
23
|
+
const lines = frontmatter.split("\n");
|
|
24
|
+
for (const line of lines) {
|
|
25
|
+
const match = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line);
|
|
26
|
+
if (!match)
|
|
27
|
+
continue;
|
|
28
|
+
output[match[1]] = parseScalar(match[2] ?? "");
|
|
29
|
+
}
|
|
30
|
+
return output;
|
|
31
|
+
}
|
|
32
|
+
export function markdownToPageSpec(raw) {
|
|
33
|
+
const { frontmatter, body } = splitFrontmatter(raw);
|
|
34
|
+
const metadata = parseSimpleFrontmatter(frontmatter);
|
|
35
|
+
const title = String(metadata.title ?? metadata.h1 ?? "Untitled Page");
|
|
36
|
+
const h1 = String(metadata.h1 ?? title);
|
|
37
|
+
const slug = normalizeRouteSlug(String(metadata.slug ?? `/${title.toLowerCase().replace(/[^a-z0-9]+/g, "-")}/`));
|
|
38
|
+
const kind = String(metadata.kind ?? metadata.contentType ?? "docs_bridge");
|
|
39
|
+
const description = String(metadata.description ?? body.split(/\n\s*\n/)[0] ?? title);
|
|
40
|
+
const intro = String(metadata.intro ?? description);
|
|
41
|
+
const faqs = Array.isArray(metadata.faq) ? metadata.faq : undefined;
|
|
42
|
+
const page = {
|
|
43
|
+
kind,
|
|
44
|
+
slug,
|
|
45
|
+
title,
|
|
46
|
+
description,
|
|
47
|
+
h1,
|
|
48
|
+
intro,
|
|
49
|
+
sections: [
|
|
50
|
+
{
|
|
51
|
+
id: "content",
|
|
52
|
+
kind: "markdown",
|
|
53
|
+
body,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
faq: faqs,
|
|
57
|
+
};
|
|
58
|
+
return { metadata, body, page };
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB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AAC,QAAQ,CAAC,GAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;IACjF,MAAM,IAAI,GAAa;QACrB,IAAI;QACJ,IAAI;QACJ,KAAK;QACL,WAAW;QACX,EAAE;QACF,KAAK;QACL,QAAQ,EAAE;YACR;gBACE,EAAE,EAAE,SAAS;gBACb,IAAI,EAAE,UAAU;gBAChB,IAAI;aACL;SACF;QACD,GAAG,EAAE,IAAI;KACV,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uCAAuC,UAAU,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uCAAuC,GAAG,OAAO,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdwrk/lander-markdown-content-adapter",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=20 <23"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"README.md"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"keywords": [
|
|
18
|
+
"lander",
|
|
19
|
+
"markdown",
|
|
20
|
+
"frontmatter"
|
|
21
|
+
],
|
|
22
|
+
"description": "Markdown frontmatter and body adapter for portable lander content specs.",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@mdwrk/lander-content-contract": "^0.1.2",
|
|
25
|
+
"@mdwrk/lander-core": "^0.1.2"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "npm run build -w @mdwrk/lander-core && tsc -p tsconfig.json",
|
|
29
|
+
"typecheck": "npm run build -w @mdwrk/lander-core && tsc --noEmit -p tsconfig.json",
|
|
30
|
+
"lint": "npm run typecheck",
|
|
31
|
+
"test": "npm run typecheck",
|
|
32
|
+
"prepack": "npm run build"
|
|
33
|
+
},
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./version": {
|
|
40
|
+
"types": "./dist/version.d.ts",
|
|
41
|
+
"import": "./dist/version.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"main": "./dist/index.js",
|
|
45
|
+
"types": "./dist/index.d.ts",
|
|
46
|
+
"author": "Jacob Stewart <jacob@swarmauri.com>",
|
|
47
|
+
"homepage": "https://mdwrk.com"
|
|
48
|
+
}
|