@uniweb/projections 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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # @uniweb/projections
2
+
3
+ Artifacts derived from a Uniweb site's **content alone** — no foundation, no
4
+ runtime, nothing rendered.
5
+
6
+ A Uniweb site is content; a foundation is code; the runtime orchestrates them.
7
+ Producing HTML needs all three. The artifacts in this package need only the
8
+ first, which is what makes them identical in every context — browser SPA,
9
+ prerender, edge SSR, desktop, `unipress` — and stable when the foundation or
10
+ the runtime changes.
11
+
12
+ ```bash
13
+ npm install @uniweb/projections
14
+ ```
15
+
16
+ > **Most projects never import this directly.** `uniweb build` and `uniweb dev`
17
+ > emit these artifacts for you. Reach for the package when you are building a
18
+ > tool that consumes a site's content outside the normal build — a custom
19
+ > publisher, an analysis pass, an alternate host.
20
+
21
+ ## What it produces
22
+
23
+ | Artifact | For | Built from |
24
+ |---|---|---|
25
+ | `llms.txt` | agents — discovery | the page graph + each page's first paragraph |
26
+ | `/{route}.md` | agents — retrieval | `section.content` via `@uniweb/content-writer` |
27
+ | search index | site search | the same page graph |
28
+
29
+ ### The index
30
+
31
+ Follows the [`llms.txt`](https://llmstxt.org) convention — an H1 title, a
32
+ blockquote summary, and `##` groups of annotated links:
33
+
34
+ ```markdown
35
+ # Uniweb
36
+
37
+ > Component content architecture — a framework where content authors and
38
+ > component developers can't break each other's work.
39
+
40
+ ## Getting Started
41
+
42
+ - [Quickstart](https://example.com/docs/getting-started/quickstart.md): Create your first Uniweb site in 5 minutes.
43
+
44
+ ## Authoring
45
+
46
+ - [Working with Collections](https://example.com/docs/authoring/collections.md): Collections let you manage repeating content — blog posts, team members, products — as a set of files.
47
+ ```
48
+
49
+ Two properties are what make this worth having over a sitemap:
50
+
51
+ - **Links point at the `.md` projection**, not the HTML page, so following an
52
+ entry is one hop rather than fetch-then-strip.
53
+ - **Descriptions never require an author to have written anything.** The chain
54
+ is `page.yml::description` → `seo.ogDescription` → the first paragraph of the
55
+ first section that has prose, as clean plain text. Grouping is taken from the
56
+ page graph: content-less container folders become the `##` headings.
57
+
58
+ ### The per-page markdown
59
+
60
+ Section bodies in page order, serialized from the stored ProseMirror document.
61
+ No frontmatter, no section `type`, no params — `type` names which component
62
+ renders a section, which is a *rendering* assignment and foundation-specific.
63
+ Emitting it would break the property this package exists for: the output is a
64
+ projection of the **site**, identical under a swapped foundation.
65
+
66
+ The output carries Uniweb dialect (`![](lu-house)` icons,
67
+ `![desc](@Component){params}` insets). That is what the author wrote, and it is
68
+ more informative to an agent working on a Uniweb site than a lossy translation
69
+ to plain CommonMark would be.
70
+
71
+ ## Configuration
72
+
73
+ Sites configure this under `agents:` in `site.yml`. Free, and on by default:
74
+
75
+ ```yaml
76
+ agents:
77
+ index: true # emit llms.txt (default true)
78
+ markdown: true # emit per-page .md (default true)
79
+ exclude: [/internal] # additional route exclusions
80
+ ```
81
+
82
+ `agents: false` turns the whole capability off in one word.
83
+
84
+ Pages are excluded when they set `seo.noindex` or `hidden`, when a route
85
+ segment starts with `_`, when the route is a dynamic template (`/blog/:slug`),
86
+ or when an `exclude` prefix covers them. `noindex`/`hidden` on a *content-less
87
+ container* hides its whole branch, since a container is pure structure and
88
+ suppressing only the heading would orphan its children.
89
+
90
+ These exclusions are load-bearing rather than tidy-up. An index is *more*
91
+ revealing than a sitemap because it describes pages rather than listing them:
92
+ an unlinked page becomes discoverable **and** summarized. Weakening them turns
93
+ the on-by-default into a leak.
94
+
95
+ ## Usage
96
+
97
+ ```js
98
+ import { renderSiteIndex, renderPageMarkdown } from '@uniweb/projections'
99
+
100
+ const index = renderSiteIndex(siteContent, { baseUrl: 'https://example.com' })
101
+ const markdown = renderPageMarkdown(siteContent.pages[0])
102
+ ```
103
+
104
+ ### API
105
+
106
+ **Rendering**
107
+
108
+ | Export | Signature |
109
+ |---|---|
110
+ | `renderSiteIndex` | `(siteContent, options?) → string` |
111
+ | `renderPageMarkdown` | `(page, { includeChildren = true }?) → string` |
112
+ | `resolvePageDescription` | `(page, { maxChars = 200 }?) → string` |
113
+
114
+ `renderSiteIndex` options: `baseUrl`, `basePath`, `locale`, `defaultLocale`,
115
+ `exclude`, `title`, `description`, `rootGroupTitle`, `maxDescriptionChars`.
116
+ Links are absolute when `baseUrl` is known and root-relative otherwise — a
117
+ root-relative link still resolves for an agent that arrived via the index.
118
+
119
+ **Page graph** — `selectIndexablePages`, `groupPagesForIndex`, `buildPageUrl`,
120
+ `applyRouteTranslation`, `isContainer`, `isDynamicTemplate`.
121
+
122
+ **Config and filenames** — `resolveAgentsConfig`, `pageMarkdownFilename`,
123
+ `INDEX_FILENAME`.
124
+
125
+ The internal vocabulary is *projections*. `llms.txt` is one emitter's filename —
126
+ a third-party convention that may not survive — so it appears exactly once, in
127
+ `config.js`, at the edge. A change of convention costs a constant.
128
+
129
+ **Search** — also available from the `@uniweb/projections/search` subpath:
130
+ `generateSearchIndex`, `extractSearchContent`, `generateCollectionIndex`,
131
+ `isSearchEnabled`, `getSearchConfig`, `getSearchIndexFilename`.
132
+
133
+ ```js
134
+ import { generateSearchIndex, isSearchEnabled } from '@uniweb/projections/search'
135
+
136
+ if (isSearchEnabled(siteContent)) {
137
+ const index = generateSearchIndex(siteContent, { locale: 'en' })
138
+ }
139
+ ```
140
+
141
+ Search extraction lives here rather than in `@uniweb/build` so that one
142
+ implementation serves every publisher. `@uniweb/build` re-exports this module,
143
+ so existing call sites are unchanged.
144
+
145
+ ## Localization
146
+
147
+ The default locale's artifacts sit at the output root; other locales go under
148
+ `/{locale}/`, mirroring the search index's established pattern. Pass `locale`
149
+ and `defaultLocale` to `renderSiteIndex` and it builds locale-correct URLs,
150
+ including translated route segments from `config.i18n.routeTranslations` — the
151
+ same rule the sitemap uses, so the two can never disagree about where a
152
+ localized page lives.
153
+
154
+ ## Environment contract
155
+
156
+ **Runs anywhere JS runs.** No `node:*`, no bundler, no DOM, no filesystem —
157
+ enforced by `tests/environment.test.js`, which walks the real import graph.
158
+
159
+ This is the package's reason to exist rather than a nicety. A Uniweb project is
160
+ dual-published: the CLI and the app are both JavaScript clients of one backend,
161
+ and either may be the publisher. An artifact derived from site content has to
162
+ come out identical whichever side published, or a deployed site's artifacts
163
+ oscillate — and an index that exists after one publish and vanishes after
164
+ another is worse than none, because agents are told to rely on it. One
165
+ implementation, imported by both publishers; the backend stores and serves
166
+ opaque bytes and generates nothing.
167
+
168
+ The same contract is why `search/generate.js` imports the leaf subpath
169
+ `@uniweb/core/locale-config` rather than the bare `@uniweb/core` entry, whose
170
+ package root pulls in heavier dependencies. The environment test forbids the
171
+ bare entry, so the trap cannot be re-entered.
172
+
173
+ ## Development
174
+
175
+ ```bash
176
+ pnpm test # vitest
177
+ ```
178
+
179
+ ## License
180
+
181
+ Apache-2.0
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@uniweb/projections",
3
+ "version": "0.1.1",
4
+ "description": "Projections of a Uniweb site's content — agent index, per-page markdown, search index. Pure JS, runs anywhere.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.js",
8
+ "./search": "./src/search/index.js"
9
+ },
10
+ "files": [
11
+ "src"
12
+ ],
13
+ "keywords": [
14
+ "uniweb",
15
+ "projections",
16
+ "llms-txt",
17
+ "markdown",
18
+ "search"
19
+ ],
20
+ "author": "Proximify",
21
+ "license": "Apache-2.0",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/uniweb/projections.git"
25
+ },
26
+ "homepage": "https://github.com/uniweb/projections#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/uniweb/projections/issues"
29
+ },
30
+ "engines": {
31
+ "node": ">=20.19"
32
+ },
33
+ "dependencies": {
34
+ "@uniweb/core": "0.7.30",
35
+ "@uniweb/content-writer": "0.2.8"
36
+ },
37
+ "devDependencies": {
38
+ "vitest": "^4.1.7",
39
+ "@uniweb/content-reader": "1.1.16"
40
+ },
41
+ "scripts": {
42
+ "test": "vitest run"
43
+ }
44
+ }
package/src/config.js ADDED
@@ -0,0 +1,77 @@
1
+ /**
2
+ * @fileoverview Config surface and output filenames.
3
+ *
4
+ * The internal vocabulary is *projections*. `llms.txt` is one emitter's
5
+ * filename — a third-party convention that may not survive — so it appears
6
+ * exactly once, here, at the edge. A change of convention costs a constant.
7
+ */
8
+
9
+ /** Filename of the agent index within a locale's output root. */
10
+ export const INDEX_FILENAME = 'llms.txt'
11
+
12
+ /** Defaults for the `agents:` block. Free capability, on by default. */
13
+ const DEFAULTS = { index: true, markdown: true, exclude: [] }
14
+
15
+ /**
16
+ * Read the site's `agents:` block.
17
+ *
18
+ * Deliberately NOT `features:` — that list is the billing-intent declaration
19
+ * paired with a server-side entitlement gate, and projections are free. A
20
+ * free capability in that list would blur what `features:` means for
21
+ * everything else in it.
22
+ *
23
+ * @param {Object} [siteConfig] - `siteContent.config`
24
+ * @returns {{index: boolean, markdown: boolean, exclude: string[]}}
25
+ */
26
+ export function resolveAgentsConfig(siteConfig = {}) {
27
+ const agents = siteConfig?.agents
28
+
29
+ // `agents: false` turns the whole capability off in one word.
30
+ if (agents === false) return { index: false, markdown: false, exclude: [] }
31
+ if (!agents || typeof agents !== 'object') return { ...DEFAULTS }
32
+
33
+ return {
34
+ index: agents.index !== false,
35
+ markdown: agents.markdown !== false,
36
+ exclude: normalizeExclude(agents.exclude),
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Normalize `exclude:` to a list of leading-slash route prefixes.
42
+ *
43
+ * Exported because exclusions arrive two ways — from `site.yml`'s `agents:`
44
+ * block and as a direct option — and both have to be normalized or one path
45
+ * silently stops excluding.
46
+ *
47
+ * @param {*} value
48
+ * @returns {string[]}
49
+ */
50
+ export function normalizeExclude(value) {
51
+ if (!value) return []
52
+ const list = Array.isArray(value) ? value : [value]
53
+ return list
54
+ .filter(v => typeof v === 'string' && v.trim())
55
+ .map(v => {
56
+ const trimmed = v.trim()
57
+ const withSlash = trimmed.startsWith('/') ? trimmed : `/${trimmed}`
58
+ // Strip a trailing slash so `/internal/` and `/internal` behave alike.
59
+ return withSlash.length > 1 ? withSlash.replace(/\/+$/, '') : withSlash
60
+ })
61
+ }
62
+
63
+ /**
64
+ * Output path of a page's markdown projection, relative to the locale root.
65
+ *
66
+ * 1:1 with the route, matching how `agents.md` names pages: the page at
67
+ * `/docs/authoring/collections` projects to `docs/authoring/collections.md`.
68
+ * The site root is `index.md` — `dist/index.html` is the page, `index.md` is
69
+ * free beside it.
70
+ *
71
+ * @param {string} route
72
+ * @returns {string}
73
+ */
74
+ export function pageMarkdownFilename(route) {
75
+ if (!route || route === '/') return 'index.md'
76
+ return `${route.replace(/^\/+/, '').replace(/\/+$/, '')}.md`
77
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @fileoverview One line describing a page, for the agent index.
3
+ *
4
+ * Discovery needs *meaning*, not just a URL — a bare list of links is what an
5
+ * agent could already get from a sitemap. The whole value of the index is
6
+ * that each entry says what the page is for.
7
+ *
8
+ * Never requires an author to have written anything: the docs corpus this was
9
+ * measured against has no frontmatter at all, so every description there comes
10
+ * from the derived path.
11
+ */
12
+
13
+ import { docSummaryText } from '@uniweb/content-writer'
14
+
15
+ /**
16
+ * Resolve a page's one-line description.
17
+ *
18
+ * Order: authored `page.yml::description` › authored SEO description ›
19
+ * the first paragraph of the page's first section.
20
+ *
21
+ * Note on the second step: the collected page carries `seo.ogDescription`
22
+ * (the Open Graph override), not a bare `seo.description` — `page.description`
23
+ * *is* the meta description, and it is already step one.
24
+ *
25
+ * @param {Object} page - A collected page
26
+ * @param {Object} [options]
27
+ * @param {number} [options.maxChars=200] - Soft bound on the derived summary
28
+ * @returns {string} A plain-text description, or '' when there is nothing
29
+ */
30
+ export function resolvePageDescription(page, { maxChars = 200 } = {}) {
31
+ const authored = page?.description?.trim()
32
+ if (authored) return authored
33
+
34
+ const seoDescription = page?.seo?.ogDescription?.trim()
35
+ if (seoDescription) return seoDescription
36
+
37
+ return deriveDescription(page, { maxChars })
38
+ }
39
+
40
+ /**
41
+ * First paragraph of the first section that has one.
42
+ *
43
+ * Walks sections rather than reading only the first, so a page opening with a
44
+ * bare Hero (a title and nothing else) still gets a description from the
45
+ * section below it.
46
+ *
47
+ * @param {Object} page
48
+ * @param {Object} options
49
+ * @returns {string}
50
+ */
51
+ function deriveDescription(page, { maxChars }) {
52
+ for (const section of page?.sections || []) {
53
+ const summary = docSummaryText(section?.content, { maxChars })
54
+ if (summary) return summary
55
+ }
56
+ return ''
57
+ }
package/src/index.js ADDED
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @uniweb/projections — everything derived from the *site* ingredient alone.
3
+ *
4
+ * A Uniweb site is content; a foundation is code; the runtime orchestrates
5
+ * them. Rendering HTML needs all three. These artifacts need only the first,
6
+ * which is what makes them identical in every context — SPA, prerender,
7
+ * JIT-SSR isolate, desktop, `unipress` — and stable across foundation and
8
+ * runtime changes.
9
+ *
10
+ * **Environment contract: runs anywhere JS runs.** No `node:*`, no Vite, no
11
+ * DOM, no filesystem. That is not incidental; it is the package's reason to
12
+ * exist. A Uniweb project is dual-published — the CLI and the app are both
13
+ * JavaScript clients of one backend, and either may be the publisher. An
14
+ * artifact derived from site content must therefore be produced *identically*
15
+ * by whichever side publishes, or a deployed site's artifacts oscillate with
16
+ * the publisher. One implementation, imported by both; the backend stores and
17
+ * serves opaque bytes and generates nothing.
18
+ *
19
+ * The contract is enforced by a test (`tests/environment.test.js`), because a
20
+ * subpath export of a Node-flavored package is one careless import away from
21
+ * breaking a consumer it never sees.
22
+ *
23
+ * @module @uniweb/projections
24
+ */
25
+
26
+ export { renderSiteIndex } from './site-index.js'
27
+ export { renderPageMarkdown } from './markdown.js'
28
+ export { resolvePageDescription } from './description.js'
29
+
30
+ export {
31
+ INDEX_FILENAME,
32
+ pageMarkdownFilename,
33
+ resolveAgentsConfig,
34
+ } from './config.js'
35
+
36
+ export {
37
+ selectIndexablePages,
38
+ groupPagesForIndex,
39
+ buildPageUrl,
40
+ applyRouteTranslation,
41
+ isContainer,
42
+ isDynamicTemplate,
43
+ } from './pages.js'
44
+
45
+ export {
46
+ extractSearchContent,
47
+ generateSearchIndex,
48
+ mergeSearchIndexes,
49
+ generateCollectionIndex,
50
+ isSearchEnabled,
51
+ getSearchConfig,
52
+ getSearchIndexFilename,
53
+ } from './search/index.js'
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @fileoverview The retrieval projection: one page as markdown.
3
+ *
4
+ * Retrieval needs *fidelity*, so this reads `section.content` — the stored
5
+ * ProseMirror document — through `content-writer`, rather than reconstructing
6
+ * prose from the semantic parser's flattened groups.
7
+ *
8
+ * What is deliberately absent: no frontmatter, no section `type`, no params.
9
+ * `type` names which component renders a section — a rendering assignment,
10
+ * and foundation-specific. Emitting it would break the property that makes
11
+ * this projection worth having: it is a projection of the *site* ingredient
12
+ * alone, identical under a swapped foundation.
13
+ *
14
+ * The output carries Uniweb dialect (`![](lu-house)` icons,
15
+ * `![desc](@Component){params}` insets). That is what the author wrote, and
16
+ * it is more informative for an agent working on a Uniweb site than a
17
+ * lossy translation to plain CommonMark would be.
18
+ */
19
+
20
+ import { proseMirrorToMarkdown } from '@uniweb/content-writer'
21
+
22
+ /**
23
+ * Render one page as markdown.
24
+ *
25
+ * @param {Object} page - A collected page (`siteContent.pages[n]`)
26
+ * @param {Object} [options]
27
+ * @param {boolean} [options.includeChildren=true] - Include nested sections
28
+ * @returns {string} Markdown, or '' when the page has no projectable content
29
+ */
30
+ export function renderPageMarkdown(page, { includeChildren = true } = {}) {
31
+ const blocks = []
32
+
33
+ for (const section of page?.sections || []) {
34
+ collectSection(section, blocks, includeChildren)
35
+ }
36
+
37
+ return blocks.join('\n\n').trim()
38
+ }
39
+
40
+ /**
41
+ * Serialize one section, then its children in declared order.
42
+ *
43
+ * Child sections (`@`-prefixed files attached via `nest:`) are real authored
44
+ * content that happens to render inside a parent. Skipping them would drop
45
+ * body text an author wrote, which is exactly what retrieval is for.
46
+ *
47
+ * @param {Object} section
48
+ * @param {string[]} blocks
49
+ * @param {boolean} includeChildren
50
+ */
51
+ function collectSection(section, blocks, includeChildren) {
52
+ const markdown = serializeSectionContent(section)
53
+ if (markdown) blocks.push(markdown)
54
+
55
+ if (!includeChildren) return
56
+ for (const child of section?.subsections || []) {
57
+ collectSection(child, blocks, includeChildren)
58
+ }
59
+ }
60
+
61
+ /**
62
+ * @param {Object} section
63
+ * @returns {string}
64
+ */
65
+ function serializeSectionContent(section) {
66
+ const content = section?.content
67
+ if (!content?.content?.length) return ''
68
+ return proseMirrorToMarkdown(content).trim()
69
+ }