@nuasite/llm-enhancements 0.60.0 → 0.61.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/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
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type CollectionPages, getCollectionContent } from './cms-marker'
|
|
2
|
+
import type { HtmlToMarkdownResult } from './html-to-markdown'
|
|
3
|
+
import { createCollectionOutput, createStaticOutput } from './markdown-generator'
|
|
4
|
+
import type { MarkdownSyntax } from './mdx'
|
|
5
|
+
import type { MarkdownOutput, ResolvedOptions } from './types'
|
|
6
|
+
|
|
7
|
+
/** What a page is resolved against: the pages that render an entry, and how the site parses markdown. */
|
|
8
|
+
export interface SiteContent {
|
|
9
|
+
pages: CollectionPages
|
|
10
|
+
syntax: MarkdownSyntax
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PageMarkdown {
|
|
14
|
+
output: MarkdownOutput
|
|
15
|
+
type: 'collection' | 'static'
|
|
16
|
+
/** The entry's source, for a collection page. */
|
|
17
|
+
sourcePath?: string
|
|
18
|
+
/** The entry's title, else the page's `<title>`. */
|
|
19
|
+
title?: string
|
|
20
|
+
/** The rendered page's metadata, when the page was read. */
|
|
21
|
+
metadata?: HtmlToMarkdownResult['metadata']
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolve a page to the markdown that tells it: its collection entry when it has one, else its rendered
|
|
26
|
+
* HTML when static pages are wanted. `readPage` converts the rendered page, or gives `undefined` when
|
|
27
|
+
* there is none; it is called at most once and only when the page is needed.
|
|
28
|
+
*/
|
|
29
|
+
export async function resolvePageMarkdown(
|
|
30
|
+
pagePath: string,
|
|
31
|
+
options: ResolvedOptions,
|
|
32
|
+
site: SiteContent,
|
|
33
|
+
readPage: () => Promise<HtmlToMarkdownResult | undefined>,
|
|
34
|
+
): Promise<PageMarkdown | undefined> {
|
|
35
|
+
let page: Promise<HtmlToMarkdownResult | undefined> | undefined
|
|
36
|
+
const renderedPage = () => (page ??= readPage())
|
|
37
|
+
|
|
38
|
+
const entry = await getCollectionContent(pagePath, site.pages, site.syntax)
|
|
39
|
+
if (entry) {
|
|
40
|
+
const entryTitle = entry.frontmatter.title?.value
|
|
41
|
+
// An entry that renders more than its source says is told by its page, which is still the entry's,
|
|
42
|
+
// so it is written whether or not static pages are.
|
|
43
|
+
const rendered = entry.body === undefined || entryTitle === undefined ? await renderedPage() : undefined
|
|
44
|
+
const body = entry.body ?? rendered?.body
|
|
45
|
+
if (body === undefined) return undefined
|
|
46
|
+
return {
|
|
47
|
+
output: createCollectionOutput(entry.frontmatter, body, entry.file),
|
|
48
|
+
type: 'collection',
|
|
49
|
+
sourcePath: entry.file,
|
|
50
|
+
title: entryTitle ?? rendered?.metadata.title,
|
|
51
|
+
metadata: rendered?.metadata,
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!options.includeStaticPages) return undefined
|
|
56
|
+
const rendered = await renderedPage()
|
|
57
|
+
if (!rendered) return undefined
|
|
58
|
+
return { output: createStaticOutput(rendered.metadata, rendered.body), type: 'static', title: rendered.metadata.title, metadata: rendered.metadata }
|
|
59
|
+
}
|