@nuasite/llm-enhancements 0.60.0 → 0.61.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 +5 -14
- package/dist/types/build-processor.d.ts +2 -1
- package/dist/types/build-processor.d.ts.map +1 -1
- package/dist/types/cms-marker.d.ts +21 -17
- package/dist/types/cms-marker.d.ts.map +1 -1
- package/dist/types/cms.d.ts +11 -0
- package/dist/types/cms.d.ts.map +1 -0
- package/dist/types/dev-middleware.d.ts.map +1 -1
- package/dist/types/mdx.d.ts +26 -0
- package/dist/types/mdx.d.ts.map +1 -0
- package/dist/types/page-markdown.d.ts +26 -0
- package/dist/types/page-markdown.d.ts.map +1 -0
- package/dist/types/tests/cases/build-processor.test.d.ts +2 -0
- package/dist/types/tests/cases/build-processor.test.d.ts.map +1 -0
- package/dist/types/tests/cases/dev-middleware.test.d.ts +2 -0
- package/dist/types/tests/cases/dev-middleware.test.d.ts.map +1 -0
- package/dist/types/tests/cases/mdx.test.d.ts +2 -0
- package/dist/types/tests/cases/mdx.test.d.ts.map +1 -0
- package/dist/types/tests/tsconfig.tsbuildinfo +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -3
- package/src/build-processor.ts +54 -72
- package/src/cms-marker.ts +64 -41
- package/src/cms.ts +23 -0
- package/src/dev-middleware.ts +69 -68
- package/src/mdx.ts +103 -0
- package/src/page-markdown.ts +59 -0
- package/src/tsconfig.json +2 -1
package/README.md
CHANGED
|
@@ -210,7 +210,7 @@ LLMs and crawlers are welcome to access markdown endpoints.
|
|
|
210
210
|
|
|
211
211
|
- **Type**: `string`
|
|
212
212
|
- **Default**: `'src/content'`
|
|
213
|
-
- Directory containing Astro content collections.
|
|
213
|
+
- Directory containing Astro content collections, inside the project root. The CMS reads nothing outside it, so a `contentDir` there is reported once and every page is converted from its HTML.
|
|
214
214
|
|
|
215
215
|
### `includeStaticPages`
|
|
216
216
|
|
|
@@ -325,22 +325,13 @@ When converting static pages, the integration:
|
|
|
325
325
|
| `<blockquote>` | `> quote` |
|
|
326
326
|
| `<table>` | Markdown tables |
|
|
327
327
|
|
|
328
|
-
##
|
|
328
|
+
## Collection pages
|
|
329
329
|
|
|
330
|
-
|
|
330
|
+
A page that renders a content collection entry is written from the entry's own markdown, with its source path in the frontmatter. Pages that are not backed by an entry are converted from their rendered HTML instead. The entry lookup comes from `@nuasite/cms`, an optional peer dependency (`@nuasite/nua` installs it); without it every page is converted from its HTML. The collections are scanned once per build.
|
|
331
331
|
|
|
332
|
-
|
|
333
|
-
import cmsMarker from '@nuasite/cms-marker'
|
|
334
|
-
import pageMarkdown from '@nuasite/llm-enhancements'
|
|
335
|
-
import { defineConfig } from 'astro/config'
|
|
332
|
+
A page is an entry's when it is at the URL the CMS editor shows for that entry: from the collection's `cms.pathname` rule, else a URL the entry declares in its frontmatter (`urlPath`, `permalink`, …), else the route that renders the collection plus the entry's slug. So `src/pages/aktuality/[slug].astro` rendering `news` makes `/aktuality/x` the page of `news/x.md`, while a static `/team/jana` beside `blog/jana.md` stays a static page. A route under a dynamic folder (`[lang]/blog/[slug].astro`) gives no URL, so its entries need a `cms.pathname` rule or a declared URL. Only markdown entries (`.md`, `.mdx`) are written from source; a data entry (`.json`, `.yaml`) is still a collection page, written from its rendered HTML like an `.mdx` entry that renders components. Entries are read from Astro's `root`, so `astro build --root site` works from any directory.
|
|
336
333
|
|
|
337
|
-
export
|
|
338
|
-
integrations: [
|
|
339
|
-
cmsMarker(),
|
|
340
|
-
pageMarkdown(),
|
|
341
|
-
],
|
|
342
|
-
})
|
|
343
|
-
```
|
|
334
|
+
An `.mdx` entry is written without its `import`/`export` blocks. It is parsed with the site's markdown syntax (directives when a remark-directive plugin is configured, as `@nuasite/nua` does). One whose body still uses a component (`<Tip>`, `<Card />`) or an expression (`{year}`) is converted from its rendered HTML instead, since those render text the source only names. It is still a collection page, so it is written even with `includeStaticPages: false`.
|
|
344
335
|
|
|
345
336
|
## Output Structure
|
|
346
337
|
|
|
@@ -4,7 +4,8 @@ interface PageInfo {
|
|
|
4
4
|
pathname: string;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* Process build output and generate .md files for all pages
|
|
7
|
+
* Process build output and generate .md files for all pages. Entries are read from Astro's project
|
|
8
|
+
* root, which need not be the working directory (`astro build --root site`).
|
|
8
9
|
*/
|
|
9
10
|
export declare function processBuildOutput(dir: URL, pages: PageInfo[], options: ResolvedOptions, logger: AstroIntegrationLogger, config: AstroConfig): Promise<void>;
|
|
10
11
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-processor.d.ts","sourceRoot":"","sources":["../../src/build-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"build-processor.d.ts","sourceRoot":"","sources":["../../src/build-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAA;AAahE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,UAAU,QAAQ;IACjB,QAAQ,EAAE,MAAM,CAAA;CAChB;AAWD;;;GAGG;AACH,wBAAgB,kBAAkB,CACjC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,QAAQ,EAAE,EACjB,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,sBAAsB,EAC9B,MAAM,EAAE,WAAW,GACjB,OAAO,CAAC,IAAI,CAAC,CAGf"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
body: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import type { CollectionInfo, MarkdownContent } from '@nuasite/cms';
|
|
2
|
+
import { type MarkdownSyntax } from './mdx';
|
|
3
|
+
/** The pages that render a collection entry, by normalized pathname. */
|
|
4
|
+
export type CollectionPages = Map<string, CollectionInfo>;
|
|
5
|
+
/**
|
|
6
|
+
* A page's collection entry. `body` is `undefined` when the entry cannot be told as markdown (an `.mdx`
|
|
7
|
+
* body that renders components or expressions): the page is still the entry's, but its text comes
|
|
8
|
+
* from the rendered HTML.
|
|
9
|
+
*/
|
|
10
|
+
export type CollectionPage = Omit<MarkdownContent, 'body'> & {
|
|
11
|
+
body: string | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare function getCollectionContent(pagePath: string, pages: CollectionPages, syntax: MarkdownSyntax): Promise<CollectionPage | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Find the pages that render a collection entry, once, for a caller about to resolve many pages: the URL
|
|
16
|
+
* the CMS editor shows for each entry (see `collectionPagesByPathname` in `@nuasite/cms`). Runs in the
|
|
17
|
+
* current project context. Empty without `@nuasite/cms`, when `contentDir` lies outside the project root
|
|
18
|
+
* (the CMS reads nothing there), or when the scan fails; `warn` reports the last two. Every page is then
|
|
19
|
+
* told by its rendered HTML.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findCollectionPages(contentDir: string, warn: (message: string) => void): Promise<CollectionPages>;
|
|
18
22
|
//# sourceMappingURL=cms-marker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cms-marker.d.ts","sourceRoot":"","sources":["../../src/cms-marker.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"cms-marker.d.ts","sourceRoot":"","sources":["../../src/cms-marker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAGnE,OAAO,EAAE,KAAK,cAAc,EAAqB,MAAM,OAAO,CAAA;AAG9D,wEAAwE;AACxE,MAAM,MAAM,eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAEzD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAA;AAQzF,wBAAsB,oBAAoB,CACzC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,eAAe,EACtB,MAAM,EAAE,cAAc,GACpB,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAmBrC;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAoBvH"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as Cms from '@nuasite/cms';
|
|
2
|
+
/**
|
|
3
|
+
* `@nuasite/cms`, an optional peer: without it every page is converted from its rendered HTML.
|
|
4
|
+
*
|
|
5
|
+
* Imported here, at the top level, and nowhere later. Astro evaluates an integration through a Vite
|
|
6
|
+
* module runner that it closes once the config is loaded, so an import made in a hook fails in any Astro
|
|
7
|
+
* build, Node or Bun ("Vite module runner has been closed"). A top-level await finishes while the config
|
|
8
|
+
* is still loading.
|
|
9
|
+
*/
|
|
10
|
+
export declare const cms: typeof Cms | undefined;
|
|
11
|
+
//# sourceMappingURL=cms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms.d.ts","sourceRoot":"","sources":["../../src/cms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,MAAM,cAAc,CAAA;AAExC;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,EAAE,OAAO,GAAG,GAAG,SAG7B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev-middleware.d.ts","sourceRoot":"","sources":["../../src/dev-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"dev-middleware.d.ts","sourceRoot":"","sources":["../../src/dev-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAUzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AA2E9C;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,WAAW,QAsKvG"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AstroConfig } from 'astro';
|
|
2
|
+
export interface MarkdownSyntax {
|
|
3
|
+
/**
|
|
4
|
+
* The site's markdown pipeline parses directives (`:::list{.dots}`). MDX then reads a `{…}` after a
|
|
5
|
+
* directive as its attributes; without them it is an expression.
|
|
6
|
+
*/
|
|
7
|
+
directives: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The syntax of the site's markdown pipeline, which `@astrojs/mdx` extends by default: directives when a
|
|
11
|
+
* remark-directive plugin is in it (`@nuasite/nua` adds the CMS's). Plugins given to `mdx()` alone are not
|
|
12
|
+
* visible here.
|
|
13
|
+
*/
|
|
14
|
+
export declare function markdownSyntaxOf(config: AstroConfig): MarkdownSyntax;
|
|
15
|
+
/**
|
|
16
|
+
* Make an `.mdx` entry body readable as plain markdown, or say it cannot be.
|
|
17
|
+
*
|
|
18
|
+
* The body is parsed as MDX, so fences, multi-line ESM and code spans follow the same rules MDX itself
|
|
19
|
+
* uses. ESM (`import`/`export`) is cut out of the source: none of it is content. A body that still renders
|
|
20
|
+
* something the source only names returns `undefined`, so the page's rendered HTML is used instead:
|
|
21
|
+
* a component (`<Card title="…" />`), an expression (`{new Date().getFullYear()}`, `{/* note *\/}`) or a
|
|
22
|
+
* plain HTML tag whose attributes are expressions. A body MDX cannot parse returns `undefined` too.
|
|
23
|
+
* `syntax` says which extensions the site parses MDX with, so the body reads as the site renders it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mdxBodyAsMarkdown(body: string, syntax: MarkdownSyntax): string | undefined;
|
|
26
|
+
//# sourceMappingURL=mdx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdx.d.ts","sourceRoot":"","sources":["../../src/mdx.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AASxC,MAAM,WAAW,cAAc;IAC9B;;;OAGG;IACH,UAAU,EAAE,OAAO,CAAA;CACnB;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,cAAc,CAOpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAmC1F"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type CollectionPages } from './cms-marker';
|
|
2
|
+
import type { HtmlToMarkdownResult } from './html-to-markdown';
|
|
3
|
+
import type { MarkdownSyntax } from './mdx';
|
|
4
|
+
import type { MarkdownOutput, ResolvedOptions } from './types';
|
|
5
|
+
/** What a page is resolved against: the pages that render an entry, and how the site parses markdown. */
|
|
6
|
+
export interface SiteContent {
|
|
7
|
+
pages: CollectionPages;
|
|
8
|
+
syntax: MarkdownSyntax;
|
|
9
|
+
}
|
|
10
|
+
export interface PageMarkdown {
|
|
11
|
+
output: MarkdownOutput;
|
|
12
|
+
type: 'collection' | 'static';
|
|
13
|
+
/** The entry's source, for a collection page. */
|
|
14
|
+
sourcePath?: string;
|
|
15
|
+
/** The entry's title, else the page's `<title>`. */
|
|
16
|
+
title?: string;
|
|
17
|
+
/** The rendered page's metadata, when the page was read. */
|
|
18
|
+
metadata?: HtmlToMarkdownResult['metadata'];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve a page to the markdown that tells it: its collection entry when it has one, else its rendered
|
|
22
|
+
* HTML when static pages are wanted. `readPage` converts the rendered page, or gives `undefined` when
|
|
23
|
+
* there is none; it is called at most once and only when the page is needed.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolvePageMarkdown(pagePath: string, options: ResolvedOptions, site: SiteContent, readPage: () => Promise<HtmlToMarkdownResult | undefined>): Promise<PageMarkdown | undefined>;
|
|
26
|
+
//# sourceMappingURL=page-markdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-markdown.d.ts","sourceRoot":"","sources":["../../src/page-markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAwB,MAAM,cAAc,CAAA;AACzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9D,yGAAyG;AACzG,MAAM,WAAW,WAAW;IAC3B,KAAK,EAAE,eAAe,CAAA;IACtB,MAAM,EAAE,cAAc,CAAA;CACtB;AAED,MAAM,WAAW,YAAY;IAC5B,MAAM,EAAE,cAAc,CAAA;IACtB,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAA;IAC7B,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAA;CAC3C;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACxC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,oBAAoB,GAAG,SAAS,CAAC,GACvD,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAyBnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-processor.test.d.ts","sourceRoot":"","sources":["../../../../tests/cases/build-processor.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-middleware.test.d.ts","sourceRoot":"","sources":["../../../../tests/cases/dev-middleware.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdx.test.d.ts","sourceRoot":"","sources":["../../../../tests/cases/mdx.test.ts"],"names":[],"mappings":""}
|