@hozu/content 0.1.0
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 +21 -0
- package/README.md +15 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 olevatorr
|
|
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,15 @@
|
|
|
1
|
+
# @hozu/content
|
|
2
|
+
|
|
3
|
+
Markdown content collections with typed front matter for Hozu.
|
|
4
|
+
|
|
5
|
+
Part of [Hozu](https://github.com/olevatorr/Hozu#readme), an AI-first web framework. Most apps start from
|
|
6
|
+
`npm create hozu@latest`, which installs the right packages and sets up Claude Code or `AGENTS.md` agents.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @hozu/content
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Requires Node 22.18 or newer. Documentation: the [README](https://github.com/olevatorr/Hozu#readme) and the
|
|
13
|
+
agent skill that `create-hozu` writes into each app.
|
|
14
|
+
|
|
15
|
+
MIT © olevatorr
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Infer, Schema } from '@hozu/core';
|
|
2
|
+
export interface Heading {
|
|
3
|
+
depth: number;
|
|
4
|
+
text: string;
|
|
5
|
+
id: string;
|
|
6
|
+
}
|
|
7
|
+
export interface Entry<T> {
|
|
8
|
+
slug: string;
|
|
9
|
+
data: T;
|
|
10
|
+
html: string;
|
|
11
|
+
headings: Heading[];
|
|
12
|
+
}
|
|
13
|
+
export declare class ContentError extends Error {
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function parseCollection<S extends Schema>({ files, schema, }: {
|
|
17
|
+
files: Record<string, string>;
|
|
18
|
+
schema: S;
|
|
19
|
+
}): Entry<Infer<S>>[];
|
|
20
|
+
export declare function loadCollection<S extends Schema>({ dir, schema, }: {
|
|
21
|
+
dir: URL;
|
|
22
|
+
schema: S;
|
|
23
|
+
}): Promise<Entry<Infer<S>>[]>;
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAK/C,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;CACX;AAED,MAAM,WAAW,KAAK,CAAC,CAAC;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,CAAC,CAAA;IACP,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,EAAE,CAAA;CACpB;AAED,qBAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,SAAiB;CAC/B;AAgCD,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,EAAE,EAChD,KAAK,EACL,MAAM,GACP,EAAE;IACD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC7B,MAAM,EAAE,CAAC,CAAA;CACV,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAuBpB;AAED,wBAAsB,cAAc,CAAC,CAAC,SAAS,MAAM,EAAE,EACrD,GAAG,EACH,MAAM,GACP,EAAE;IACD,GAAG,EAAE,GAAG,CAAA;IACR,MAAM,EAAE,CAAC,CAAA;CACV,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAM7B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readdir, readFile } from 'node:fs/promises';
|
|
2
|
+
import { toParse } from '@hozu/core/ir';
|
|
3
|
+
import { Marked } from 'marked';
|
|
4
|
+
import { parse as parseYaml } from 'yaml';
|
|
5
|
+
export class ContentError extends Error {
|
|
6
|
+
name = 'ContentError';
|
|
7
|
+
}
|
|
8
|
+
const FRONT_MATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
9
|
+
const slugify = (text) => text
|
|
10
|
+
.toLowerCase()
|
|
11
|
+
.normalize('NFKD')
|
|
12
|
+
.replace(/[̀-ͯ]/g, '')
|
|
13
|
+
.replace(/[^\p{L}\p{N}]+/gu, '-')
|
|
14
|
+
.replace(/^-+|-+$/g, '') || 'section';
|
|
15
|
+
function render(markdown) {
|
|
16
|
+
const headings = [];
|
|
17
|
+
const used = new Map();
|
|
18
|
+
const marked = new Marked({
|
|
19
|
+
gfm: true,
|
|
20
|
+
renderer: {
|
|
21
|
+
heading({ tokens, depth }) {
|
|
22
|
+
const text = tokens.map((t) => ('text' in t ? t.text : t.raw)).join('');
|
|
23
|
+
const base = slugify(text);
|
|
24
|
+
const n = used.get(base) ?? 0;
|
|
25
|
+
used.set(base, n + 1);
|
|
26
|
+
const id = n ? `${base}-${n + 1}` : base;
|
|
27
|
+
headings.push({ depth, text, id });
|
|
28
|
+
return `<h${depth} id="${id}">${this.parser.parseInline(tokens)}</h${depth}>\n`;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
return { html: marked.parse(markdown, { async: false }), headings };
|
|
33
|
+
}
|
|
34
|
+
export function parseCollection({ files, schema, }) {
|
|
35
|
+
const check = toParse(schema);
|
|
36
|
+
if (!check)
|
|
37
|
+
throw new ContentError('The collection schema is not a Standard Schema');
|
|
38
|
+
return Object.keys(files)
|
|
39
|
+
.filter((name) => name.endsWith('.md'))
|
|
40
|
+
.sort()
|
|
41
|
+
.map((name) => {
|
|
42
|
+
const text = files[name];
|
|
43
|
+
const front = FRONT_MATTER.exec(text);
|
|
44
|
+
let raw = {};
|
|
45
|
+
try {
|
|
46
|
+
raw = front ? (parseYaml(front[1]) ?? {}) : {};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new ContentError(`${name}: invalid front matter: ${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
const parsed = check(raw);
|
|
52
|
+
if (!parsed.ok)
|
|
53
|
+
throw new ContentError(`${name}: ${parsed.issues.join('; ')}`);
|
|
54
|
+
return {
|
|
55
|
+
slug: name.slice(0, -3),
|
|
56
|
+
data: parsed.value,
|
|
57
|
+
...render(front ? text.slice(front[0].length) : text),
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export async function loadCollection({ dir, schema, }) {
|
|
62
|
+
const names = (await readdir(dir)).filter((name) => name.endsWith('.md'));
|
|
63
|
+
const files = Object.fromEntries(await Promise.all(names.map(async (name) => [name, await readFile(new URL(name, dir), 'utf8')])));
|
|
64
|
+
return parseCollection({ files, schema });
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAEpD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAA;AAezC,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,GAAG,cAAc,CAAA;CAC/B;AAED,MAAM,YAAY,GAAG,mCAAmC,CAAA;AAExD,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAC/B,IAAI;KACD,WAAW,EAAE;KACb,SAAS,CAAC,MAAM,CAAC;KACjB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;KACrB,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC;KAChC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,SAAS,CAAA;AAEzC,SAAS,MAAM,CAAC,QAAgB;IAC9B,MAAM,QAAQ,GAAc,EAAE,CAAA;IAC9B,MAAM,IAAI,GAAG,IAAI,GAAG,EAAkB,CAAA;IACtC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,GAAG,EAAE,IAAI;QACT,QAAQ,EAAE;YACR,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAkB;gBACvC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC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C,CAAA;IACzE,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,QAAQ,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,CAAU,CAAC,CAAC,CAC1G,CAAA;IACD,OAAO,eAAe,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;AAC3C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hozu/content",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Markdown content collections with typed front matter for Hozu",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"hozu",
|
|
7
|
+
"framework",
|
|
8
|
+
"ai",
|
|
9
|
+
"agents",
|
|
10
|
+
"ssr",
|
|
11
|
+
"islands",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/olevatorr/Hozu/tree/main/packages/content#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/olevatorr/Hozu/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/olevatorr/Hozu.git",
|
|
21
|
+
"directory": "packages/content"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "olevatorr",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=22.18"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"marked": "18.0.14",
|
|
43
|
+
"yaml": "2.9.1",
|
|
44
|
+
"@hozu/core": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"sideEffects": false
|
|
47
|
+
}
|