@hamur/content 0.0.0-stage → 0.0.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.
Files changed (183) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +14 -2
  3. package/dist/chunks/bun-render-65mwzeq2.js +58 -0
  4. package/dist/chunks/bun-render-7jxnxg3v.js +714 -0
  5. package/dist/chunks/bun-render-mxhn5twt.js +130 -0
  6. package/dist/chunks/bun-render-w7fh3fg7.js +36 -0
  7. package/dist/src/adapters/html.js +134 -0
  8. package/dist/src/adapters/preact.js +126 -0
  9. package/dist/src/adapters/react.js +116 -0
  10. package/dist/src/adapters/solid.js +153 -0
  11. package/dist/src/adapters/svelte.js +90 -0
  12. package/dist/src/adapters/vue.js +166 -0
  13. package/dist/src/index.js +2732 -0
  14. package/dist/src/query.js +97 -0
  15. package/dist/src/render.js +12 -0
  16. package/dist/src/server/index.js +349 -0
  17. package/dist/types/src/adapters/html.d.ts +54 -0
  18. package/dist/types/src/adapters/page.d.ts +21 -0
  19. package/dist/types/src/adapters/preact.d.ts +53 -0
  20. package/dist/types/src/adapters/prose.d.ts +21 -0
  21. package/dist/types/src/adapters/react.d.ts +53 -0
  22. package/dist/types/src/adapters/search.d.ts +12 -0
  23. package/dist/types/src/adapters/solid.d.ts +54 -0
  24. package/dist/types/src/adapters/svelte-page.d.ts +9 -0
  25. package/dist/types/src/adapters/svelte-search.d.ts +9 -0
  26. package/dist/types/src/adapters/svelte.d.ts +24 -0
  27. package/dist/types/src/adapters/vue.d.ts +189 -0
  28. package/dist/types/src/build/api.d.ts +24 -0
  29. package/dist/types/src/build/dev-route.d.ts +4 -0
  30. package/dist/types/src/build/dev.d.ts +48 -0
  31. package/dist/types/src/build/graphql.d.ts +10 -0
  32. package/dist/types/src/build/image.d.ts +16 -0
  33. package/dist/types/src/build/index.d.ts +76 -0
  34. package/dist/types/src/build/live.d.ts +6 -0
  35. package/dist/types/src/build/prerender.d.ts +8 -0
  36. package/dist/types/src/build/query.d.ts +10 -0
  37. package/dist/types/src/build/raw.d.ts +23 -0
  38. package/dist/types/src/build/search.d.ts +9 -0
  39. package/dist/types/src/build/types.d.ts +16 -0
  40. package/dist/types/src/component.d.ts +10 -0
  41. package/dist/types/src/config.d.ts +6 -0
  42. package/dist/types/src/define.d.ts +14 -0
  43. package/dist/types/src/error.d.ts +4 -0
  44. package/dist/types/src/image.d.ts +15 -0
  45. package/dist/types/src/index.d.ts +64 -0
  46. package/dist/types/src/loaders/data.d.ts +12 -0
  47. package/dist/types/src/loaders/file.d.ts +3 -0
  48. package/dist/types/src/loaders/git.d.ts +27 -0
  49. package/dist/types/src/loaders/glob.d.ts +14 -0
  50. package/dist/types/src/module.d.ts +3 -0
  51. package/dist/types/src/query.d.ts +17 -0
  52. package/dist/types/src/render.d.ts +9 -0
  53. package/dist/types/src/runtime/client.d.ts +25 -0
  54. package/dist/types/src/runtime/dev-client.d.ts +4 -0
  55. package/dist/types/src/runtime/dev-plugin.d.ts +12 -0
  56. package/dist/types/src/runtime/dev-store.d.ts +5 -0
  57. package/dist/types/src/runtime/live.d.ts +36 -0
  58. package/dist/types/src/runtime/navigation.d.ts +35 -0
  59. package/dist/types/src/runtime/page-plugin.d.ts +2 -0
  60. package/dist/types/src/runtime/page-source.d.ts +12 -0
  61. package/dist/types/src/runtime/query.d.ts +100 -0
  62. package/dist/types/src/runtime/raw-path.d.ts +2 -0
  63. package/dist/types/src/runtime/refresh-body.d.ts +4 -0
  64. package/dist/types/src/runtime/search-loaders.d.ts +7 -0
  65. package/dist/types/src/runtime/search-plugin.d.ts +2 -0
  66. package/dist/types/src/runtime/search-store.d.ts +19 -0
  67. package/dist/types/src/runtime/search.d.ts +28 -0
  68. package/dist/types/src/runtime/sections.d.ts +36 -0
  69. package/dist/types/src/runtime/server-store.d.ts +4 -0
  70. package/dist/types/src/runtime/store.d.ts +31 -0
  71. package/dist/types/src/server/door-dev-static.d.ts +3 -0
  72. package/dist/types/src/server/door-dev.d.ts +4 -0
  73. package/dist/types/src/server/door-static.d.ts +2 -0
  74. package/dist/types/src/server/door.d.ts +3 -0
  75. package/dist/types/src/server/endpoint.d.ts +1 -0
  76. package/dist/types/src/server/graphql.d.ts +24 -0
  77. package/dist/types/src/server/index.d.ts +10 -0
  78. package/dist/types/src/server/install.d.ts +1 -0
  79. package/dist/types/src/server/live.d.ts +10 -0
  80. package/dist/types/src/server/query.d.ts +15 -0
  81. package/dist/types/src/server/refresh.d.ts +2 -0
  82. package/dist/types/src/server/rest.d.ts +62 -0
  83. package/dist/types/src/server/search.d.ts +5 -0
  84. package/dist/types/src/server-config.d.ts +12 -0
  85. package/dist/types/src/source.d.ts +24 -0
  86. package/dist/types/src/types.d.ts +293 -0
  87. package/package.json +110 -4
  88. package/src/adapters/ContentRenderer.svelte +27 -0
  89. package/src/adapters/ProseA.svelte +11 -0
  90. package/src/adapters/ProseBlockquote.svelte +7 -0
  91. package/src/adapters/ProseCode.svelte +7 -0
  92. package/src/adapters/ProseEm.svelte +7 -0
  93. package/src/adapters/ProseH1.svelte +7 -0
  94. package/src/adapters/ProseH2.svelte +7 -0
  95. package/src/adapters/ProseH3.svelte +7 -0
  96. package/src/adapters/ProseH4.svelte +7 -0
  97. package/src/adapters/ProseH5.svelte +7 -0
  98. package/src/adapters/ProseH6.svelte +7 -0
  99. package/src/adapters/ProseHr.svelte +5 -0
  100. package/src/adapters/ProseImg.svelte +5 -0
  101. package/src/adapters/ProseLi.svelte +7 -0
  102. package/src/adapters/ProseOl.svelte +7 -0
  103. package/src/adapters/ProseP.svelte +7 -0
  104. package/src/adapters/ProsePre.svelte +21 -0
  105. package/src/adapters/ProseStrong.svelte +7 -0
  106. package/src/adapters/ProseTable.svelte +7 -0
  107. package/src/adapters/ProseUl.svelte +7 -0
  108. package/src/adapters/html.ts +152 -0
  109. package/src/adapters/page.ts +52 -0
  110. package/src/adapters/preact.ts +154 -0
  111. package/src/adapters/prose.ts +55 -0
  112. package/src/adapters/react.ts +142 -0
  113. package/src/adapters/search.ts +32 -0
  114. package/src/adapters/solid.ts +183 -0
  115. package/src/adapters/svelte-defaults.ts +41 -0
  116. package/src/adapters/svelte-page.ts +29 -0
  117. package/src/adapters/svelte-search.ts +36 -0
  118. package/src/adapters/svelte.ts +30 -0
  119. package/src/adapters/test/OwnA.svelte +7 -0
  120. package/src/adapters/test/OwnH1.svelte +7 -0
  121. package/src/adapters/test/OwnPre.svelte +7 -0
  122. package/src/adapters/test/support.ts +106 -0
  123. package/src/adapters/vue.ts +182 -0
  124. package/src/build/api.ts +201 -0
  125. package/src/build/dev-route.ts +5 -0
  126. package/src/build/dev.ts +299 -0
  127. package/src/build/graphql.ts +197 -0
  128. package/src/build/image.ts +60 -0
  129. package/src/build/index.ts +597 -0
  130. package/src/build/live.ts +34 -0
  131. package/src/build/prerender.ts +34 -0
  132. package/src/build/query.ts +70 -0
  133. package/src/build/raw.ts +157 -0
  134. package/src/build/search.ts +64 -0
  135. package/src/build/types.ts +108 -0
  136. package/src/component.ts +86 -0
  137. package/src/config.ts +156 -0
  138. package/src/define.ts +33 -0
  139. package/src/env.d.ts +34 -0
  140. package/src/error.ts +4 -0
  141. package/src/image.ts +41 -0
  142. package/src/index.ts +103 -0
  143. package/src/loaders/data.ts +186 -0
  144. package/src/loaders/file.ts +53 -0
  145. package/src/loaders/git.ts +266 -0
  146. package/src/loaders/glob.ts +179 -0
  147. package/src/module.ts +26 -0
  148. package/src/query.ts +82 -0
  149. package/src/render.ts +16 -0
  150. package/src/runtime/client.ts +75 -0
  151. package/src/runtime/dev-client.ts +6 -0
  152. package/src/runtime/dev-plugin.ts +64 -0
  153. package/src/runtime/dev-store.ts +19 -0
  154. package/src/runtime/live.ts +331 -0
  155. package/src/runtime/navigation.ts +225 -0
  156. package/src/runtime/page-plugin.ts +13 -0
  157. package/src/runtime/page-source.ts +22 -0
  158. package/src/runtime/query.ts +605 -0
  159. package/src/runtime/raw-path.ts +2 -0
  160. package/src/runtime/refresh-body.ts +22 -0
  161. package/src/runtime/search-loaders.ts +14 -0
  162. package/src/runtime/search-plugin.ts +6 -0
  163. package/src/runtime/search-store.ts +73 -0
  164. package/src/runtime/search.ts +126 -0
  165. package/src/runtime/sections.ts +155 -0
  166. package/src/runtime/server-store.ts +12 -0
  167. package/src/runtime/store.ts +59 -0
  168. package/src/server/door-dev-static.ts +6 -0
  169. package/src/server/door-dev.ts +7 -0
  170. package/src/server/door-static.ts +4 -0
  171. package/src/server/door.ts +6 -0
  172. package/src/server/endpoint.ts +17 -0
  173. package/src/server/graphql.ts +59 -0
  174. package/src/server/index.ts +17 -0
  175. package/src/server/install.ts +6 -0
  176. package/src/server/live.ts +51 -0
  177. package/src/server/query.ts +46 -0
  178. package/src/server/refresh.ts +19 -0
  179. package/src/server/rest.ts +157 -0
  180. package/src/server/search.ts +22 -0
  181. package/src/server-config.ts +24 -0
  182. package/src/source.ts +99 -0
  183. package/src/types.ts +282 -0
@@ -0,0 +1,10 @@
1
+ import "hamur/server-only";
2
+ export { queryCollection, queryCollectionItemSurroundings, queryCollectionNavigation, queryCollectionSearchSections, } from "./query.ts";
3
+ export { searchCollection } from "./search.ts";
4
+ export { getLiveCollection, getLiveEntry, refreshContent } from "./live.ts";
5
+ export type { LiveCollectionResult, LiveEntry, LiveEntryResult } from "../types.ts";
6
+ export { findPageBreadcrumb, findPageChildren, findPageHeadline, findPageSiblings } from "../runtime/navigation.ts";
7
+ export type { NavigationItem, SurroundingsOptions } from "../runtime/navigation.ts";
8
+ export type { SearchHit } from "../runtime/search.ts";
9
+ export type { SearchOptions } from "../runtime/search-store.ts";
10
+ export type { HeadingTag, SearchSection, SearchSectionsOptions } from "../runtime/sections.ts";
@@ -0,0 +1 @@
1
+ export declare const installStore: import("hamur/server").ServerPlugin;
@@ -0,0 +1,10 @@
1
+ import type { LiveCollectionFilter, LiveCollectionItem, LiveCollectionName, LiveEntryFilter } from "../index.ts";
2
+ import type { LiveCollectionResult, LiveEntryResult } from "../types.ts";
3
+ /** Runs the collection's `loadCollection(filter)` now, or reuses a result cached for its `cacheHint.maxAge`. */
4
+ export declare function getLiveCollection<N extends LiveCollectionName>(name: N, filter?: LiveCollectionFilter<N>): Promise<LiveCollectionResult<LiveCollectionItem<N>>>;
5
+ /** Runs the collection's `loadEntry(filter)` now, or reuses a result cached for its `cacheHint.maxAge`. */
6
+ export declare function getLiveEntry<N extends LiveCollectionName>(name: N, filter: LiveEntryFilter<N>): Promise<LiveEntryResult<LiveCollectionItem<N>>>;
7
+ /** Drops the cached live results of `collections` (default every live collection); a load running now stores nothing. */
8
+ export declare function refreshContent(options?: {
9
+ collections?: string[];
10
+ }): Promise<void>;
@@ -0,0 +1,15 @@
1
+ import type { HamurEvent } from "hamur/server";
2
+ import { type NavigationItem, type SurroundingsOptions } from "../runtime/navigation.ts";
3
+ import { type CollectionQueryBuilder } from "../runtime/query.ts";
4
+ import { type SearchSection, type SearchSectionsOptions } from "../runtime/sections.ts";
5
+ import type { CollectionField, CollectionItem, CollectionName } from "../index.ts";
6
+ import type { ContentEntry } from "../types.ts";
7
+ /** A query from a handler, over every collection, `expose: false` ones included. */
8
+ export declare function queryCollection<N extends CollectionName>(event: HamurEvent, name: N): CollectionQueryBuilder<CollectionItem<N>, never, CollectionField<N>>;
9
+ export declare function queryCollection<T = ContentEntry>(event: HamurEvent, name: CollectionName): CollectionQueryBuilder<T>;
10
+ /** The navigation tree from a handler, over any collection. */
11
+ export declare function queryCollectionNavigation(event: HamurEvent, name: CollectionName, extraFields?: string[]): Promise<NavigationItem[]>;
12
+ /** The entries around `path` from a handler. */
13
+ export declare function queryCollectionItemSurroundings<N extends CollectionName, F extends string = never>(event: HamurEvent, name: N, path: string, options?: SurroundingsOptions<F>): Promise<(import("../query.ts").QueryResult<CollectionItem<N>, "path" | F> | null)[]>;
14
+ /** The sections of a collection's pages from a handler, over any collection. */
15
+ export declare function queryCollectionSearchSections(event: HamurEvent, name: CollectionName, options?: SearchSectionsOptions): Promise<SearchSection[]>;
@@ -0,0 +1,2 @@
1
+ /** `hamur dev` only; the dev runner has re-run the build loaders of the collections before this drops the live results. */
2
+ export declare const contentRefresh: import("hamur/server").Handler<unknown, Response, unknown, Response, {}>;
@@ -0,0 +1,62 @@
1
+ import { type StandardJSONSchemaV1, type StandardSchemaV1 } from "hamur/server";
2
+ import { type CollectionQuery, type QueryCondition } from "../runtime/query.ts";
3
+ import type { ContentStore } from "../runtime/store.ts";
4
+ /** The most entries one REST answer holds, and its `limit` when none is sent. */
5
+ export declare const REST_LIMIT = 100;
6
+ type DocumentedSchema = StandardSchemaV1<unknown, unknown> & StandardJSONSchemaV1<unknown, unknown>;
7
+ /** A `where` condition from its field, operator (default `=`) and sent text or texts, read as `restQuery` reads a query string. */
8
+ export declare function condition(field: string, written: string | undefined, sent: unknown): QueryCondition;
9
+ /** The query string of `GET /api/_content/<collection>` as the engine's query; `limit` is capped at `REST_LIMIT`. */
10
+ export declare function restQuery(input: unknown): CollectionQuery;
11
+ /** Runs `query` (built by `build`, which may throw a `QueryError`) over an exposed collection: 404 for one the store does not expose, 400 for a query the engine refuses. REST and GraphQL both answer through it. */
12
+ export declare function answerExposed(store: ContentStore, name: string, build: () => CollectionQuery): Promise<unknown>;
13
+ /** The answer of `GET /api/_content/<name>`. */
14
+ export declare const answerRest: (store: ContentStore, name: string, input: unknown) => Promise<unknown>;
15
+ /** `GET /api/_content/<name>` of a name with no route: unknown, or not exposed. */
16
+ export declare function missingCollection(input: unknown): never;
17
+ /** The query parameters as OpenAPI lists them; `where[...]` keys have no fixed names, so the operation's description gives them. */
18
+ export declare const restInput: DocumentedSchema;
19
+ /** The success body: an array of the collection's entries, each `item`. */
20
+ export declare const restOutput: (item: Record<string, unknown>) => DocumentedSchema;
21
+ export declare const restResponses: {
22
+ 400: {
23
+ description: string;
24
+ content: {
25
+ "application/json": {
26
+ schema: {
27
+ type: string;
28
+ required: string[];
29
+ properties: {
30
+ status: {
31
+ type: string;
32
+ };
33
+ message: {
34
+ type: string;
35
+ };
36
+ };
37
+ };
38
+ };
39
+ };
40
+ };
41
+ 404: {
42
+ description: string;
43
+ content: {
44
+ "application/json": {
45
+ schema: {
46
+ type: string;
47
+ required: string[];
48
+ properties: {
49
+ status: {
50
+ type: string;
51
+ };
52
+ message: {
53
+ type: string;
54
+ };
55
+ };
56
+ };
57
+ };
58
+ };
59
+ };
60
+ };
61
+ export declare const REST_DESCRIPTION = "Filter with `where[field]=value` (equal) or `where[field][operator]=value`, an operator of the queryCollection table (`>=`, `IN`, `LIKE`, \u2026), URL-encoded. A value is read as JSON when it is a number, boolean, null, quoted string or array, else as text; `IN` and `BETWEEN` take a JSON array or repeated parameters. A field is a name or a dotted path.";
62
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { HamurEvent } from "hamur/server";
2
+ import { type SearchHit } from "../runtime/search.ts";
3
+ import type { SearchOptions } from "../runtime/search-store.ts";
4
+ /** Ranks `query` with the collection's search index, the file the browser loads, so a handler and `useSearchCollection` give one answer. */
5
+ export declare function searchCollection(_event: HamurEvent, name: string, query: string, { limit }?: SearchOptions): Promise<SearchHit[]>;
@@ -0,0 +1,12 @@
1
+ import type { ContentLoader } from "./types.ts";
2
+ export { defineCollection, defineContentConfig, defineLiveCollection, defineTransformer } from "./define.ts";
3
+ export { image } from "./image.ts";
4
+ export declare const glob: () => ContentLoader;
5
+ export declare const file: () => ContentLoader;
6
+ export declare const fromComponent: (path: string) => {
7
+ "~standard": {
8
+ version: number;
9
+ vendor: string;
10
+ validate(): never;
11
+ };
12
+ };
@@ -0,0 +1,24 @@
1
+ import type { Logger } from "hamur/server";
2
+ import type { CollectionSource } from "./types.ts";
3
+ export interface SourceFile {
4
+ /** The absolute directory `relative` is below. */
5
+ cwd: string;
6
+ /** Absolute path. */
7
+ file: string;
8
+ /** The path below the source's `cwd`, with `/`. */
9
+ relative: string;
10
+ stem: string;
11
+ extension: string;
12
+ /** The page path from the source's `prefix` and `relative`. */
13
+ path: string;
14
+ }
15
+ export declare function pagePath(prefix: string, relative: string): string;
16
+ /** Source order: segment by segment, a number prefix numerically and before none, then by name. */
17
+ export declare function compareSource(a: string, b: string): number;
18
+ export interface RemoteContext {
19
+ /** `<cacheDir>`; default `<rootDir>/node_modules/.cache/hamur`. */
20
+ cacheDir?: string;
21
+ logger?: Logger;
22
+ }
23
+ /** The files of one collection: each source's files in source order, the sources in the order given; a remote source's files are below its cached copy. */
24
+ export declare function setupSources(rootDir: string, source: CollectionSource, remote?: RemoteContext): Promise<SourceFile[]>;
@@ -0,0 +1,293 @@
1
+ import type { MarkdownDocument, MdHeading, MdRoot, TocLink } from "hamur/markdown";
2
+ import type { QueryCondition } from "./runtime/query.ts";
3
+ import type { Logger, StandardSchemaV1 } from "hamur/server";
4
+ /** Globs relative to `cwd`, which is relative to `<rootDir>/content`. */
5
+ export interface SourceOptions {
6
+ include: string;
7
+ repository?: never;
8
+ exclude?: string[];
9
+ /** The path prefix of a page collection; default `/`. */
10
+ prefix?: string;
11
+ cwd?: string;
12
+ }
13
+ /** Files of a GitHub or GitLab repository, downloaded at build; the globs are relative to the repository's root. */
14
+ export interface RemoteSourceOptions {
15
+ /** `https://github.com/<org>/<repo>` or `https://gitlab.com/<group>/<project>`. */
16
+ repository: string;
17
+ /** Default the repository's default branch; set `branch` or `tag`, not both. */
18
+ branch?: string;
19
+ tag?: string;
20
+ include: string;
21
+ exclude?: string[];
22
+ /** The path prefix of a page collection; default `/`. */
23
+ prefix?: string;
24
+ cwd?: never;
25
+ /** Sent as a header only (`Authorization: Bearer` on GitHub, `PRIVATE-TOKEN` on GitLab); never logged or cached. */
26
+ auth?: {
27
+ token: string;
28
+ };
29
+ }
30
+ export type CollectionSource = string | SourceOptions | RemoteSourceOptions | Array<string | SourceOptions | RemoteSourceOptions>;
31
+ /** One entry a loader puts in the store. */
32
+ export interface LoaderEntry {
33
+ id: string;
34
+ /** The entry's fields; validated through the collection's schema unless it is the output of `parseData`. */
35
+ data: Record<string, unknown>;
36
+ /** Markdown source, frontmatter included; a page collection parses it into the page fields. */
37
+ body?: string;
38
+ /** The entry's file: its extension is the entry's `extension`, and errors name it. */
39
+ file?: string;
40
+ /** The same digest as in the last build skips the entry's parse and reuses its index entry. */
41
+ digest?: string;
42
+ /** Default `id`. */
43
+ stem?: string;
44
+ /** A page's path; default `/<id>`. */
45
+ path?: string;
46
+ /** The `.navigation.yml` data of the directories above a page, by directory stem; the glob loader sets it. */
47
+ navigationDirs?: Record<string, Record<string, unknown>>;
48
+ }
49
+ export interface LoaderContext {
50
+ collection: string;
51
+ type: "page" | "data";
52
+ rootDir: string;
53
+ store: {
54
+ set(entry: LoaderEntry): void;
55
+ delete(id: string): void;
56
+ keys(): string[];
57
+ clear(): void;
58
+ };
59
+ /** Strings kept per collection between builds, in the content index. */
60
+ meta: {
61
+ get(key: string): string | undefined;
62
+ set(key: string, value: string): void;
63
+ };
64
+ /** Validates through the collection's schema and returns the output, or throws the validation message. */
65
+ parseData(entry: {
66
+ id: string;
67
+ data: unknown;
68
+ file?: string;
69
+ }): Promise<Record<string, unknown>>;
70
+ parseMarkdown(source: string, options?: {
71
+ file?: string;
72
+ }): Promise<MarkdownDocument>;
73
+ digest(value: string | Uint8Array): string;
74
+ /** `content.csv` with its defaults: how the file and glob loaders read `.csv`. */
75
+ csv: {
76
+ delimiter: string;
77
+ header: boolean;
78
+ };
79
+ logger: Logger;
80
+ /** The config's transformers; a loader reads a file whose extension one of their `parse` lists through it. */
81
+ transformers: readonly Transformer[];
82
+ /** Runs the `content:file:beforeParse` hooks, then returns the file's body, which a hook may have changed. */
83
+ beforeParse(file: ContentFile): Promise<string>;
84
+ }
85
+ /** The file a transformer's `parse` and the `content:file:*` hooks read. */
86
+ export interface ContentFile {
87
+ /** The entry id the file gives. */
88
+ id: string;
89
+ /** From the root, with `/`: `content/notes/a.txt`. */
90
+ path: string;
91
+ /** Without the dot. */
92
+ extension: string;
93
+ /** The file's text. */
94
+ body: string;
95
+ }
96
+ /** `defineTransformer`'s argument. */
97
+ export interface Transformer {
98
+ name: string;
99
+ /** With the dot: `[".adoc"]`. With `parse`, the extensions are read from every collection's sources. */
100
+ extensions: string[];
101
+ /** Reads a file of one of `extensions` into the entry's fields; a string `body` field is the Markdown a page collection parses. */
102
+ parse?(file: ContentFile): Record<string, unknown> | Promise<Record<string, unknown>>;
103
+ /** Runs on every parsed entry after the schema, in list order, and returns the entry. */
104
+ transform?(entry: ContentEntry): Record<string, unknown> | Promise<Record<string, unknown>>;
105
+ }
106
+ export interface ContentLoader {
107
+ name: string;
108
+ load(ctx: LoaderContext): Promise<void>;
109
+ }
110
+ interface CollectionBase {
111
+ type: "page" | "data";
112
+ /** Validates each entry's frontmatter or data at build; its output replaces the input. */
113
+ schema?: StandardSchemaV1;
114
+ /** `false` keeps the collection server-only; default `true`. */
115
+ expose?: boolean;
116
+ /** The collection's default order; default the source order. */
117
+ order?: [field: string, direction: "ASC" | "DESC"];
118
+ }
119
+ export type CollectionDefinition = CollectionBase & ({
120
+ source: CollectionSource;
121
+ loader?: never;
122
+ } | {
123
+ loader: ContentLoader;
124
+ source?: never;
125
+ });
126
+ /** How long a live result may be reused, and what it depends on. */
127
+ export interface CacheHint {
128
+ tags?: string[];
129
+ /** Seconds; with it, `getLiveCollection` and `getLiveEntry` keep the result in the `cache` storage mount that long. */
130
+ maxAge?: number;
131
+ lastModified?: Date;
132
+ }
133
+ /** One entry a live loader returns. */
134
+ export interface LiveLoaderEntry<D extends object = Record<string, unknown>> {
135
+ id: string;
136
+ /** Validated through the collection's schema when it has one. */
137
+ data: D;
138
+ /** Markdown source (parsed on the bun preset only) or a Markdown AST. */
139
+ body?: string | MdRoot;
140
+ cacheHint?: CacheHint;
141
+ }
142
+ /** Fetches a live collection at request time. */
143
+ export interface LiveLoader<CollectionFilter = any, EntryFilter = any, D extends object = object> {
144
+ name?: string;
145
+ loadCollection(filter: CollectionFilter): {
146
+ entries: LiveLoaderEntry<D>[];
147
+ cacheHint?: CacheHint;
148
+ } | Promise<{
149
+ entries: LiveLoaderEntry<D>[];
150
+ cacheHint?: CacheHint;
151
+ }>;
152
+ loadEntry(filter: EntryFilter): LiveLoaderEntry<D> | undefined | Promise<LiveLoaderEntry<D> | undefined>;
153
+ }
154
+ /** What `defineLiveCollection` returns; never written into the content index. */
155
+ export interface LiveCollectionDefinition<L extends LiveLoader = LiveLoader, S extends StandardSchemaV1 | undefined = StandardSchemaV1 | undefined> {
156
+ live: true;
157
+ loader: L;
158
+ schema?: S;
159
+ }
160
+ export interface ContentConfig<C extends Record<string, CollectionDefinition | LiveCollectionDefinition> = Record<string, CollectionDefinition>> {
161
+ collections: C;
162
+ /** Code that reads more file types or reshapes every entry. */
163
+ transformers?: Transformer[];
164
+ }
165
+ /** `content.config.ts` as the build reads it: the live collections apart from the others. */
166
+ export interface LoadedContentConfig extends ContentConfig {
167
+ live: Record<string, LiveCollectionDefinition>;
168
+ }
169
+ /** The `content` key of `hamur.config.ts`. */
170
+ export interface ContentOptions {
171
+ /** How `queryCollection` runs in the browser: `"api"` posts to `/_hamur/content/query`, `"local"` fetches the collection once. Default `"api"`, `"local"` on the `static` preset. */
172
+ clientQuery?: "api" | "local";
173
+ /** The page collections that get a search index at build; each must be exposed. Default `false`. */
174
+ search?: {
175
+ collections: string[];
176
+ } | false;
177
+ /** Entries per chunk of a collection in the server bundle: a positive integer. Default `1000`. */
178
+ chunkSize?: number;
179
+ /** How `.csv` files are read: `delimiter` one character, default `","`; `header` whether the first row names the columns, default `true`. */
180
+ csv?: {
181
+ delimiter?: string;
182
+ header?: boolean;
183
+ };
184
+ /** Adds the `path` of every page entry to the prerender routes. Default `true` on the `static` preset, else `false`. */
185
+ prerender?: boolean;
186
+ /** Serves each page entry's source at `<path>.md`: `true` the file on disk, `"body"` the Markdown its loader gave. Default `false`. */
187
+ raw?: boolean | "body";
188
+ /** Serves `/llms.txt` and `/llms-full.txt` from page collections. */
189
+ llms?: LlmsOptions;
190
+ /** `rest` serves `GET /api/_content/<collection>` for every exposed collection; `graphql` adds them to the app's GraphQL schema. Both default `false`. */
191
+ api?: {
192
+ rest?: boolean;
193
+ graphql?: boolean;
194
+ };
195
+ }
196
+ /** The `llms.txt` of the site. */
197
+ export interface LlmsOptions {
198
+ title: string;
199
+ description?: string;
200
+ sections: Array<{
201
+ title: string;
202
+ /** A page collection. */
203
+ collection: string;
204
+ /** A condition or conditions joined by `AND`; default every page of the collection. */
205
+ where?: QueryCondition | QueryCondition[];
206
+ }>;
207
+ }
208
+ /** The fields every entry has, without the index signature that lets an untyped entry carry any other field. */
209
+ export interface DataFields {
210
+ /** The name of the collection the entry belongs to. */
211
+ collection: string;
212
+ /** The stem, or `<stem>/<index>` for an item of an array file. */
213
+ id: string;
214
+ /** The file's path below the source's `cwd` without its extension, number prefixes kept. */
215
+ stem: string;
216
+ extension: string;
217
+ }
218
+ export interface PageFields extends DataFields {
219
+ path: string;
220
+ title: string | undefined;
221
+ description: string | undefined;
222
+ seo: {
223
+ title?: string;
224
+ description?: string;
225
+ [field: string]: unknown;
226
+ };
227
+ navigation: boolean | {
228
+ title?: string;
229
+ icon?: string;
230
+ };
231
+ draft: boolean;
232
+ navigationDirs?: Record<string, Record<string, unknown>>;
233
+ body: MdRoot;
234
+ excerpt: MdRoot | undefined;
235
+ headings: MdHeading[];
236
+ toc: TocLink[];
237
+ readingTime: number;
238
+ }
239
+ export interface DataEntry extends DataFields {
240
+ [field: string]: unknown;
241
+ }
242
+ export interface PageEntry extends DataEntry, PageFields {
243
+ }
244
+ /** A schema output as the index stores it: JSON, so a `Date` is its ISO string. */
245
+ export type Serialized<T> = T extends Date ? string : T extends (...args: never[]) => unknown ? T : T extends object ? {
246
+ [K in keyof T]: Serialized<T[K]>;
247
+ } : T;
248
+ /** The item type of a collection definition: its page or data fields and the schema's output; `Record<string, unknown>` without a schema. */
249
+ export type CollectionItemOf<D> = (D extends {
250
+ type: "page";
251
+ } ? PageFields : DataFields) & (D extends {
252
+ schema: infer S extends StandardSchemaV1;
253
+ } ? Serialized<StandardSchemaV1.InferOutput<S>> : Record<string, unknown>);
254
+ export type ContentEntry = PageEntry | DataEntry;
255
+ type LiveSchemaOf<D> = D extends {
256
+ schema?: infer S;
257
+ } ? Exclude<S, undefined> : never;
258
+ type LiveLoaderDataOf<D> = D extends {
259
+ loader: {
260
+ loadEntry(filter: any): infer R;
261
+ };
262
+ } ? NonNullable<Awaited<R>> extends {
263
+ data: infer T;
264
+ } ? T : Record<string, unknown> : Record<string, unknown>;
265
+ /** The `data` of a live collection's entry: the schema's output, else the loader's `data`, with `Date` written as `string`. */
266
+ export type LiveCollectionItemOf<D> = [LiveSchemaOf<D>] extends [never] ? Serialized<LiveLoaderDataOf<D>> : LiveSchemaOf<D> extends StandardSchemaV1 ? Serialized<StandardSchemaV1.InferOutput<LiveSchemaOf<D>>> : Serialized<LiveLoaderDataOf<D>>;
267
+ /** An entry `getLiveCollection` and `getLiveEntry` give. */
268
+ export interface LiveEntry<T = Record<string, unknown>> {
269
+ id: string;
270
+ data: T;
271
+ /** The loader's Markdown AST, or its Markdown source parsed. */
272
+ body?: MdRoot;
273
+ cacheHint?: CacheHint;
274
+ }
275
+ export type LiveCollectionResult<T = Record<string, unknown>> = {
276
+ entries: LiveEntry<T>[];
277
+ error: undefined;
278
+ cacheHint: CacheHint;
279
+ } | {
280
+ entries: undefined;
281
+ error: Error;
282
+ cacheHint: CacheHint;
283
+ };
284
+ export type LiveEntryResult<T = Record<string, unknown>> = {
285
+ entry: LiveEntry<T> | undefined;
286
+ error: undefined;
287
+ cacheHint: CacheHint;
288
+ } | {
289
+ entry: undefined;
290
+ error: Error;
291
+ cacheHint: CacheHint;
292
+ };
293
+ export {};
package/package.json CHANGED
@@ -1,6 +1,112 @@
1
1
  {
2
2
  "name": "@hamur/content",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/productdevbook/hamur.git",
9
+ "directory": "packages/content"
10
+ },
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/types/src/index.d.ts",
14
+ "default": "./dist/src/index.js"
15
+ },
16
+ "./render": {
17
+ "types": "./dist/types/src/render.d.ts",
18
+ "default": "./dist/src/render.js"
19
+ },
20
+ "./query": {
21
+ "types": "./dist/types/src/query.d.ts",
22
+ "default": "./dist/src/query.js"
23
+ },
24
+ "./server": {
25
+ "types": "./dist/types/src/server/index.d.ts",
26
+ "default": "./dist/src/server/index.js"
27
+ },
28
+ "./react": {
29
+ "types": "./dist/types/src/adapters/react.d.ts",
30
+ "default": "./dist/src/adapters/react.js"
31
+ },
32
+ "./vue": {
33
+ "types": "./dist/types/src/adapters/vue.d.ts",
34
+ "default": "./dist/src/adapters/vue.js"
35
+ },
36
+ "./preact": {
37
+ "types": "./dist/types/src/adapters/preact.d.ts",
38
+ "default": "./dist/src/adapters/preact.js"
39
+ },
40
+ "./svelte": {
41
+ "types": "./dist/types/src/adapters/svelte.d.ts",
42
+ "default": "./dist/src/adapters/svelte.js"
43
+ },
44
+ "./solid": {
45
+ "types": "./dist/types/src/adapters/solid.d.ts",
46
+ "default": "./dist/src/adapters/solid.js"
47
+ },
48
+ "./html": {
49
+ "types": "./dist/types/src/adapters/html.d.ts",
50
+ "default": "./dist/src/adapters/html.js"
51
+ },
52
+ "./package.json": "./package.json"
53
+ },
54
+ "files": [
55
+ "dist",
56
+ "src"
57
+ ],
58
+ "dependencies": {},
59
+ "peerDependencies": {
60
+ "hamur": "^0.0.1",
61
+ "@hamur/adapter-react": "^0.0.1",
62
+ "@hamur/adapter-vue": "^0.0.1",
63
+ "@hamur/adapter-preact": "^0.0.1",
64
+ "@hamur/adapter-svelte": "^0.0.1",
65
+ "@hamur/adapter-solid": "^0.0.1",
66
+ "@hamur/adapter-html": "^0.0.1",
67
+ "react": "^19.3.1",
68
+ "preact": "^11.0.2",
69
+ "vue": "^3.5.44",
70
+ "svelte": "^5.57.2",
71
+ "solid-js": "^2.0.4",
72
+ "@solidjs/web": "^2.0.4"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "@hamur/adapter-react": {
76
+ "optional": true
77
+ },
78
+ "@hamur/adapter-vue": {
79
+ "optional": true
80
+ },
81
+ "@hamur/adapter-preact": {
82
+ "optional": true
83
+ },
84
+ "@hamur/adapter-svelte": {
85
+ "optional": true
86
+ },
87
+ "@hamur/adapter-solid": {
88
+ "optional": true
89
+ },
90
+ "@hamur/adapter-html": {
91
+ "optional": true
92
+ },
93
+ "react": {
94
+ "optional": true
95
+ },
96
+ "preact": {
97
+ "optional": true
98
+ },
99
+ "vue": {
100
+ "optional": true
101
+ },
102
+ "svelte": {
103
+ "optional": true
104
+ },
105
+ "solid-js": {
106
+ "optional": true
107
+ },
108
+ "@solidjs/web": {
109
+ "optional": true
110
+ }
111
+ }
112
+ }
@@ -0,0 +1,27 @@
1
+ <script lang="ts">
2
+ import type { Component } from "svelte"
3
+ import { MarkdownRenderer } from "@hamur/adapter-svelte"
4
+ import type { MdRoot } from "hamur/markdown"
5
+ import type { PageFields } from "../types.ts"
6
+ import { prepare } from "./prose.ts"
7
+ import { DEFAULTS } from "./svelte-defaults.ts"
8
+
9
+ let {
10
+ value,
11
+ components,
12
+ tag = "div",
13
+ excerpt,
14
+ unwrap,
15
+ }: {
16
+ value: PageFields | MdRoot
17
+ components?: Record<string, Component<any>> | false
18
+ tag?: string
19
+ excerpt?: boolean
20
+ unwrap?: string
21
+ } = $props()
22
+ const prepared = $derived(prepare({ value, components, defaults: DEFAULTS, excerpt, unwrap }))
23
+ </script>
24
+
25
+ {#if prepared}<svelte:element this={tag}
26
+ ><MarkdownRenderer value={prepared.root} components={prepared.components} /></svelte:element
27
+ >{/if}
@@ -0,0 +1,11 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+ import { Link } from "@hamur/adapter-svelte"
4
+ import { isInternal } from "./prose.ts"
5
+
6
+ let { href, children, ...rest }: { href?: string; children?: Snippet; [attribute: string]: unknown } = $props()
7
+ </script>
8
+
9
+ {#if isInternal(href)}<Link {...rest} to={href}>{@render children?.()}</Link>{:else}<a {href} {...rest}
10
+ >{@render children?.()}</a
11
+ >{/if}
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <blockquote {...rest}>{@render children?.()}</blockquote>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <code {...rest}>{@render children?.()}</code>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <em {...rest}>{@render children?.()}</em>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h1 {...rest}>{@render children?.()}</h1>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h2 {...rest}>{@render children?.()}</h2>
@@ -0,0 +1,7 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte"
3
+
4
+ let { children, ...rest }: { children?: Snippet; [attribute: string]: unknown } = $props()
5
+ </script>
6
+
7
+ <h3 {...rest}>{@render children?.()}</h3>