@opentf/afw-cli 1.30.0 → 1.32.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 +78 -46
- package/package.json +12 -8
- package/src/output.js +3 -1
- package/src/prerender.js +6 -2
- package/src/shared.js +112 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Open Tech Foundation and contributors
|
|
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
CHANGED
|
@@ -1,68 +1,100 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @opentf/afw-cli
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
its historical name, but the `afw` executable and its dev/build/serve commands
|
|
5
|
-
have been retired.
|
|
5
|
+
***Static generation for AFW apps, run as an `esdev build` step***
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[Static generation guide](https://afw.opentechf.org/docs/deployment/static-generation) | [Changelog](https://github.com/Open-Tech-Foundation/afw/blob/main/packages/afw-cli/CHANGELOG.md) | [GitHub](https://github.com/Open-Tech-Foundation/afw)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
</div>
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
<div align="right">
|
|
12
|
+
|
|
13
|
+
*An [Open Tech Foundation](https://opentechf.org/) project*
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
AFW compiler/routes plugin in `esdev.json`.
|
|
15
|
+
</div>
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
> Your project owns its build. This package supplies the pieces a prerender step
|
|
18
|
+
> needs: route and loader discovery, page rendering, API and loader bundles, plus a
|
|
19
|
+
> release hook that writes search indexes, feeds and `llms.txt`.
|
|
19
20
|
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
esdev
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"plugins": [
|
|
24
|
+
{ "module": "@opentf/esdev-plugin-afw", "options": { "mode": "ssg" } },
|
|
25
|
+
{ "module": "@opentf/afw-cli/ssg", "export": "siteOutputPlugin",
|
|
26
|
+
"options": { "target": "web", "prerenderTarget": "site-ssg", "root": "." } }
|
|
27
|
+
],
|
|
28
|
+
"build": {
|
|
29
|
+
"targets": {
|
|
30
|
+
"web": { "entry": "index.html", "outdir": "dist" },
|
|
31
|
+
"site-ssg": { "entry": "ssg.js", "out": ".ssg/ssg.js", "then": "run" }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
```
|
|
25
36
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
The script checks for release staging and prerenders pages, including sitemap and
|
|
30
|
-
robots output. A release-only `siteOutputPlugin` then generates search, feeds and
|
|
31
|
-
LLM files in staging before publication:
|
|
37
|
+
`esdev build` bundles the site, then runs `ssg.js`, which prerenders every route
|
|
38
|
+
into the staged output. Only when every step succeeds does the new site replace the
|
|
39
|
+
old one.
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
> [!NOTE]
|
|
42
|
+
> **Alpha.** The package keeps its historical name; the old `afw` executable and
|
|
43
|
+
> its `dev` / `build` / `serve` commands are retired in favour of `esdev`.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
pnpm add -D @opentf/afw-cli @opentf/esdev-plugin-afw
|
|
49
|
+
pnpm add @opentf/afw
|
|
36
50
|
```
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
52
|
+
Requires esdev 0.16 or newer. `esdev create my-site --template=docs` generates a
|
|
53
|
+
project with the prerender target, `ssg.js` and the release hook already in place.
|
|
54
|
+
|
|
55
|
+
## The prerender step
|
|
56
|
+
|
|
57
|
+
`ssg.js` is a short script you own. It uses this package to:
|
|
58
|
+
|
|
59
|
+
| Step | Helpers |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| Find pages and loaders under `app/` | `discoverPages`, `discoverLoaders`, `assertNoRouteConflicts` |
|
|
62
|
+
| Read `afw.config.js` | `loadConfig` |
|
|
63
|
+
| Render each route into the shell `index.html` | `runPrerender`, `stampHydrateSentinel` |
|
|
64
|
+
| Bundle server code for a deploy adapter | `emitLoaderBundle`, `emitApiBundle` |
|
|
65
|
+
| Hand results to the release hook | `writePrerenderReport` |
|
|
66
|
+
|
|
67
|
+
Pages with dynamic segments are skipped unless they export `getStaticPaths()`.
|
|
68
|
+
The [static generation guide](https://afw.opentechf.org/docs/deployment/static-generation)
|
|
69
|
+
walks through a complete `ssg.js`.
|
|
70
|
+
|
|
71
|
+
## The release hook
|
|
43
72
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Building both targets without the report fails with a configuration error.
|
|
47
|
-
Indexing failures fail the build and leave the previous deployment intact.
|
|
73
|
+
`siteOutputPlugin` runs in the staging area after prerendering and before the
|
|
74
|
+
site is published:
|
|
48
75
|
|
|
49
|
-
|
|
76
|
+
| Output | Source |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| Search index | `afwc docs index` over the prerendered HTML |
|
|
79
|
+
| RSS / Atom feeds | The blog section, when `afw.config.js` has one |
|
|
80
|
+
| `llms.txt`, `llms-full.txt` | Page titles and descriptions, for LLM context |
|
|
50
81
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
| Option | Purpose |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| `target` | The browser build target to post-process (e.g. `"web"`) |
|
|
85
|
+
| `prerenderTarget` | The prerender target that must run first |
|
|
86
|
+
| `root` | The site's source folder, relative to the working directory |
|
|
55
87
|
|
|
56
|
-
`
|
|
57
|
-
|
|
58
|
-
use the archive shipped by `@opentf/afw-compiler`; this repository can use its
|
|
59
|
-
Cargo debug build.
|
|
88
|
+
The hook never runs under `esdev start`. If indexing fails, the build fails and the
|
|
89
|
+
previous deployment stays live.
|
|
60
90
|
|
|
61
|
-
##
|
|
91
|
+
## Environment
|
|
62
92
|
|
|
63
|
-
|
|
64
|
-
|
|
93
|
+
| Variable | Effect |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `AFWC_BIN` | Use this `afwc` executable for compilation and indexing |
|
|
96
|
+
| `EXCLUDE_ROUTES` | Comma-separated route folders the release hook skips (the starter `ssg.js` honours it too) |
|
|
65
97
|
|
|
66
98
|
## License
|
|
67
99
|
|
|
68
|
-
MIT
|
|
100
|
+
MIT — see [LICENSE](https://github.com/Open-Tech-Foundation/afw/blob/main/LICENSE).
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentf/afw-cli",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.32.0",
|
|
4
|
+
"description": "Static generation for AFW apps, run as an esdev build step.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "cp ../../LICENSE LICENSE"
|
|
8
|
+
},
|
|
6
9
|
"exports": {
|
|
7
10
|
"./ssg": "./src/ssg.js"
|
|
8
11
|
},
|
|
@@ -13,24 +16,25 @@
|
|
|
13
16
|
"esdev": ">=0.16.0"
|
|
14
17
|
},
|
|
15
18
|
"dependencies": {
|
|
16
|
-
"@opentf/esdev-plugin-afw": "0.
|
|
19
|
+
"@opentf/esdev-plugin-afw": "0.5.0"
|
|
17
20
|
},
|
|
18
21
|
"peerDependencies": {
|
|
19
|
-
"@opentf/afw": "0.
|
|
22
|
+
"@opentf/afw": "0.33.0"
|
|
20
23
|
},
|
|
21
24
|
"keywords": [
|
|
25
|
+
"afw",
|
|
22
26
|
"opentf",
|
|
23
|
-
"web",
|
|
24
27
|
"ssg",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
28
|
+
"static-site-generator",
|
|
29
|
+
"prerender",
|
|
30
|
+
"esdev"
|
|
27
31
|
],
|
|
28
32
|
"repository": {
|
|
29
33
|
"type": "git",
|
|
30
34
|
"url": "https://github.com/Open-Tech-Foundation/afw.git",
|
|
31
35
|
"directory": "packages/afw-cli"
|
|
32
36
|
},
|
|
33
|
-
"homepage": "https://
|
|
37
|
+
"homepage": "https://afw.opentechf.org/docs/deployment/static-generation",
|
|
34
38
|
"bugs": "https://github.com/Open-Tech-Foundation/afw/issues",
|
|
35
39
|
"license": "MIT",
|
|
36
40
|
"publishConfig": {
|
package/src/output.js
CHANGED
|
@@ -3,7 +3,7 @@ import { file, remove } from "runtime:fs";
|
|
|
3
3
|
import { join, resolve } from "runtime:path";
|
|
4
4
|
import { cwd, env } from "runtime:process";
|
|
5
5
|
import { exists, writeFile } from "./runtime.js";
|
|
6
|
-
import { discoverPages, loadConfig, resolveCompiler, runBlogFeed, runDocsSearchIndex, runLlmsFiles } from "./shared.js";
|
|
6
|
+
import { discoverPages, loadConfig, resolveCompiler, runBlogFeed, runDocsSearchIndex, runLlmsFiles, searchProviderWarning } from "./shared.js";
|
|
7
7
|
import { step } from "./reporter.js";
|
|
8
8
|
|
|
9
9
|
const REPORT = ".afw-prerender.json";
|
|
@@ -38,6 +38,8 @@ export function siteOutputPlugin({ root = ".", target = "web", prerenderTarget,
|
|
|
38
38
|
const appDir = join(siteRoot, "app");
|
|
39
39
|
const excluded = new Set([...exclude, ...(env.EXCLUDE_ROUTES ?? "").split(",").filter(Boolean)]);
|
|
40
40
|
const baseUrl = String(config?.site?.url ?? "").replace(/\/+$/, "");
|
|
41
|
+
const searchWarning = searchProviderWarning(config);
|
|
42
|
+
if (searchWarning) console.warn(searchWarning);
|
|
41
43
|
if (config?.docs?.search?.provider === "afw") {
|
|
42
44
|
const progress = step("Building search index");
|
|
43
45
|
const { afwc } = await resolveCompiler();
|
package/src/prerender.js
CHANGED
|
@@ -143,9 +143,13 @@ export async function runPrerender({ root, pages, afwEntry, afwc, shellHtml, out
|
|
|
143
143
|
// SEO: expose the page's last-updated time (git/frontmatter) as Open Graph's
|
|
144
144
|
// article:modified_time so crawlers see when the content actually changed,
|
|
145
145
|
// and a frontmatter `date` as article:published_time (blog posts).
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
// Article tags only on an article: `og:type` "article", or a page with a publish
|
|
147
|
+
// `date`. An index or a landing page is a website; a modified time there
|
|
148
|
+
// describes nothing.
|
|
148
149
|
const published = typeof metadata?.date === "string" ? metadata.date.trim() : "";
|
|
150
|
+
const article = metadata?.openGraph?.type === "article" || Boolean(published);
|
|
151
|
+
const iso = article ? lastUpdated[path] : null;
|
|
152
|
+
if (iso) head += `\n<meta data-afw-head="" property="article:modified_time" content="${escapeXml(iso)}">`;
|
|
149
153
|
if (published) head += `\n<meta data-afw-head="" property="article:published_time" content="${escapeXml(published)}">`;
|
|
150
154
|
// Static hosts decode requested URLs when locating files. Decode generated
|
|
151
155
|
// segments once; leave literal static folder names unchanged.
|
package/src/shared.js
CHANGED
|
@@ -15,7 +15,7 @@ import { exists, findUp, mkdirp, readEntries, readText, resolveFrom, rmrf, write
|
|
|
15
15
|
// The afwc compiler service and the `runtime:build` transform plugin live in
|
|
16
16
|
// `@opentf/esdev-plugin-afw`. Imported here for the server render bundle and
|
|
17
17
|
// re-exported so the SSG entry keeps a single import site.
|
|
18
|
-
import { closeCompilers, afwPlugin, resolveCompiler } from "@opentf/esdev-plugin-afw";
|
|
18
|
+
import { closeCompilers, afwPlugin, isUnpublishedPage, resolveCompiler } from "@opentf/esdev-plugin-afw";
|
|
19
19
|
|
|
20
20
|
export { closeCompilers, resolveCompiler };
|
|
21
21
|
|
|
@@ -96,12 +96,45 @@ export function stampRenderedPath(shellHtml, path) {
|
|
|
96
96
|
*/
|
|
97
97
|
export function injectHead(shellHtml, headHtml) {
|
|
98
98
|
if (!headHtml) return shellHtml;
|
|
99
|
-
let out = shellHtml;
|
|
99
|
+
let out = stripRouteHead(shellHtml);
|
|
100
100
|
if (/<title[\s>]/i.test(headHtml)) out = out.replace(/<title>[\s\S]*?<\/title>\s*/i, "");
|
|
101
101
|
// Function replacer so `$` in `headHtml` (e.g. a price in a meta description) is literal.
|
|
102
102
|
return out.replace(/<\/head>/i, () => `${headHtml}\n</head>`);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
const ROUTE_HEAD_TAG = /<(meta|link)\b[^>]*>\s*|<script\b([^>]*)>[\s\S]*?<\/script>\s*/gi;
|
|
106
|
+
|
|
107
|
+
/** The attribute `name`'s value in an opening tag, lower-cased; "" if absent. */
|
|
108
|
+
function attrOf(tag, name) {
|
|
109
|
+
const m = tag.match(new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"));
|
|
110
|
+
return (m ? (m[1] ?? m[2] ?? m[3]) : "").toLowerCase();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Remove the shell's route-owned SEO tags (description, robots, `og:`/`twitter:`/`article:`,
|
|
115
|
+
* canonical, JSON-LD, anything marked `data-afw-head`) so the page's own head replaces them.
|
|
116
|
+
* This is the set the client's `updateRouteHead` (runtime/head.js) removes on navigation,
|
|
117
|
+
* so a prerendered page and a client-navigated one end up with the same head.
|
|
118
|
+
*/
|
|
119
|
+
function stripRouteHead(shellHtml) {
|
|
120
|
+
const head = shellHtml.match(/<head\b[^>]*>([\s\S]*?)<\/head>/i);
|
|
121
|
+
if (!head) return shellHtml;
|
|
122
|
+
const inner = head[1].replace(ROUTE_HEAD_TAG, (tag, el) => {
|
|
123
|
+
if (/\sdata-afw-head\b/i.test(tag)) return "";
|
|
124
|
+
if (el?.toLowerCase() === "meta") {
|
|
125
|
+
const name = attrOf(tag, "name");
|
|
126
|
+
const property = attrOf(tag, "property");
|
|
127
|
+
if (name === "description" || name === "robots" || name.startsWith("twitter:")) return "";
|
|
128
|
+
if (property.startsWith("og:") || property.startsWith("article:")) return "";
|
|
129
|
+
} else if (el?.toLowerCase() === "link") {
|
|
130
|
+
if (attrOf(tag, "rel") === "canonical") return "";
|
|
131
|
+
} else if (attrOf(tag, "type") === "application/ld+json") return "";
|
|
132
|
+
return tag;
|
|
133
|
+
});
|
|
134
|
+
const start = head.index + head[0].indexOf(">") + 1;
|
|
135
|
+
return shellHtml.slice(0, start) + inner + shellHtml.slice(start + head[1].length);
|
|
136
|
+
}
|
|
137
|
+
|
|
105
138
|
/** Set/replace the shell's `<html lang>` for a localized page (i18n; docs/I18N.md §6). */
|
|
106
139
|
export function withHtmlLang(shellHtml, locale) {
|
|
107
140
|
if (!locale) return shellHtml;
|
|
@@ -161,7 +194,7 @@ export async function loadDocsPlugins(root, appDir, config, exclude = new Set())
|
|
|
161
194
|
if (blog) plugins.push(blogPostsPlugin({ appDir, contentDir: blog.dir ?? "blog", exclude }));
|
|
162
195
|
// Resolves `@opentf/afw-docs/updated` to the per-page last-updated map (every route),
|
|
163
196
|
// when last-updated is turned on anywhere.
|
|
164
|
-
if (wantsLastUpdated(config)) plugins.push(lastUpdatedPlugin({ appDir, exclude }));
|
|
197
|
+
if (wantsLastUpdated(config)) plugins.push(lastUpdatedPlugin({ appDir, exclude, blogDir: blog ? blog.dir ?? "blog" : undefined }));
|
|
165
198
|
return plugins;
|
|
166
199
|
} catch (e) {
|
|
167
200
|
console.warn(
|
|
@@ -187,13 +220,25 @@ export async function runLastUpdated(root, appDir, config, exclude = new Set())
|
|
|
187
220
|
try {
|
|
188
221
|
const entry = await resolveFrom("@opentf/afw-docs/build", root);
|
|
189
222
|
const { loadLastUpdated } = await import(toFileURL(entry).href);
|
|
190
|
-
|
|
223
|
+
const blogDir = config?.blog ? config.blog.dir ?? "blog" : undefined;
|
|
224
|
+
return await loadLastUpdated({ appDir, exclude, blogDir });
|
|
191
225
|
} catch (e) {
|
|
192
226
|
console.warn(`⚠ last-updated map skipped: ${e?.message ?? e}`);
|
|
193
227
|
return {};
|
|
194
228
|
}
|
|
195
229
|
}
|
|
196
230
|
|
|
231
|
+
/**
|
|
232
|
+
* The warning for a `docs.search.provider` other than `"afw"`, or null. A retired value
|
|
233
|
+
* (e.g. `"pagefind"`) would otherwise turn search off without a word.
|
|
234
|
+
*/
|
|
235
|
+
export function searchProviderWarning(config) {
|
|
236
|
+
const provider = config?.docs?.search?.provider;
|
|
237
|
+
if (provider == null || provider === "afw") return null;
|
|
238
|
+
return `⚠ docs.search.provider ${JSON.stringify(provider)} is not supported; ` +
|
|
239
|
+
`use "afw" or remove it. Search is disabled for this build.`;
|
|
240
|
+
}
|
|
241
|
+
|
|
197
242
|
/** Index the completed SSG output when static search is enabled. Errors fail the build. */
|
|
198
243
|
export async function runDocsSearchIndex(root, config, siteDir, afwc) {
|
|
199
244
|
if (config?.docs?.search?.provider !== "afw") return null;
|
|
@@ -220,13 +265,19 @@ export async function runBlogFeed(root, appDir, config, siteDir, baseUrl, exclud
|
|
|
220
265
|
const contentDir = blog.dir ?? "blog";
|
|
221
266
|
try {
|
|
222
267
|
const entry = await resolveFrom("@opentf/afw-docs/build", root);
|
|
223
|
-
const { loadPosts, renderAtomFeed, renderBlogFeed } = await import(toFileURL(entry).href);
|
|
268
|
+
const { loadPosts, postContentHtml, renderAtomFeed, renderBlogFeed } = await import(toFileURL(entry).href);
|
|
224
269
|
const posts = await loadPosts({ appDir, contentDir, exclude });
|
|
270
|
+
// Full post bodies, read back from the prerendered pages this hook runs after.
|
|
271
|
+
for (const post of posts) {
|
|
272
|
+
const page = join(siteDir, post.path.replace(/^\/+/, ""), "index.html");
|
|
273
|
+
if (await exists(page)) post.content = postContentHtml(await readText(page), baseUrl, post.cover);
|
|
274
|
+
}
|
|
225
275
|
const title = blog.title || (config?.docs?.title ? `${config.docs.title} Blog` : "Blog");
|
|
226
276
|
const channel = {
|
|
227
277
|
title,
|
|
228
278
|
description: blog.description || title,
|
|
229
279
|
link: `/${contentDir}`,
|
|
280
|
+
language: blog.language || config?.i18n?.defaultLocale || "en",
|
|
230
281
|
};
|
|
231
282
|
const feeds = [
|
|
232
283
|
{
|
|
@@ -248,6 +299,7 @@ export async function runBlogFeed(root, appDir, config, siteDir, baseUrl, exclud
|
|
|
248
299
|
written.push(feed.path);
|
|
249
300
|
}
|
|
250
301
|
if (!written.length) return null;
|
|
302
|
+
await injectFeedLinks(siteDir, title, contentDir);
|
|
251
303
|
const origin = baseUrl.replace(/\/+$/, "");
|
|
252
304
|
return { paths: written, urls: written.map((path) => origin + path), count: posts.length };
|
|
253
305
|
} catch (e) {
|
|
@@ -256,6 +308,30 @@ export async function runBlogFeed(root, appDir, config, siteDir, baseUrl, exclud
|
|
|
256
308
|
}
|
|
257
309
|
}
|
|
258
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Advertise the blog feeds from every prerendered page: a `<link rel="alternate">` for
|
|
313
|
+
* RSS and Atom in each `<head>`, so a reader finds them from any URL of the site. A page
|
|
314
|
+
* that already declares a feed (a hand-written link in the shell) is left alone.
|
|
315
|
+
*/
|
|
316
|
+
async function injectFeedLinks(siteDir, title, contentDir) {
|
|
317
|
+
const t = String(title).replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
318
|
+
const links =
|
|
319
|
+
`<link rel="alternate" type="application/rss+xml" title="${t}" href="/${contentDir}/rss.xml">\n` +
|
|
320
|
+
`<link rel="alternate" type="application/atom+xml" title="${t}" href="/${contentDir}/atom.xml">\n`;
|
|
321
|
+
const walk = async (dir) => {
|
|
322
|
+
for (const entry of await readEntries(dir)) {
|
|
323
|
+
const full = join(dir, entry.name);
|
|
324
|
+
if (entry.isDir) await walk(full);
|
|
325
|
+
else if (entry.name.endsWith(".html")) {
|
|
326
|
+
const html = await readText(full);
|
|
327
|
+
if (/type="application\/(rss|atom)\+xml"/.test(html) || !/<\/head>/i.test(html)) continue;
|
|
328
|
+
await writeFile(full, html.replace(/<\/head>/i, () => `${links}</head>`));
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
await walk(siteDir);
|
|
333
|
+
}
|
|
334
|
+
|
|
259
335
|
/**
|
|
260
336
|
* Generate `/llms.txt` and `/llms-full.txt` for docs/blog sites from the same
|
|
261
337
|
* filesystem route list used by the app build. Project-supplied public files override
|
|
@@ -292,7 +368,31 @@ export async function runLlmsFiles(root, appDir, pages, config, siteDir, baseUrl
|
|
|
292
368
|
}
|
|
293
369
|
}
|
|
294
370
|
|
|
295
|
-
/**
|
|
371
|
+
/**
|
|
372
|
+
* Resolve-aliases pinning every `@opentf/afw` import of a server bundle to the package
|
|
373
|
+
* beside `afwEntry` (its `index.js`), one entry per subpath in the package's `exports`.
|
|
374
|
+
* An alias also covers the subpaths under its key, so a lone `"@opentf/afw": index.js`
|
|
375
|
+
* turned the compiler's `@opentf/afw/signals` import into `index.js/signals`. Longer keys
|
|
376
|
+
* come first; types-only exports (`./jsx-runtime`) have no runtime file to alias.
|
|
377
|
+
*/
|
|
378
|
+
export async function afwAliases(afwEntry) {
|
|
379
|
+
const dir = dirname(afwEntry);
|
|
380
|
+
const { exports = {} } = JSON.parse(await readText(join(dir, "package.json")));
|
|
381
|
+
const aliases = {};
|
|
382
|
+
for (const [key, target] of Object.entries(exports).sort((a, b) => b[0].length - a[0].length)) {
|
|
383
|
+
if (key === "." || !key.startsWith("./")) continue;
|
|
384
|
+
const file = typeof target === "string" ? target : target?.default ?? target?.import;
|
|
385
|
+
if (typeof file === "string" && !file.endsWith(".d.ts")) aliases[`@opentf/afw/${key.slice(2)}`] = join(dir, file);
|
|
386
|
+
}
|
|
387
|
+
aliases["@opentf/afw"] = afwEntry;
|
|
388
|
+
return aliases;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Discover file-based routes under `app/`: every page/layout and the 404. This list is
|
|
393
|
+
* what gets prerendered, so drafts and scheduled Markdown pages (`isUnpublishedPage`)
|
|
394
|
+
* are left out: no HTML, no sitemap entry, no `llms.txt` line.
|
|
395
|
+
*/
|
|
296
396
|
export async function discoverPages(dir, exclude) {
|
|
297
397
|
const out = [];
|
|
298
398
|
for (const entry of await readEntries(dir)) {
|
|
@@ -302,7 +402,9 @@ export async function discoverPages(dir, exclude) {
|
|
|
302
402
|
else if (/^404\.(mdx|md)$/.test(entry.name)) {
|
|
303
403
|
throw new Error(`Unsupported Markdown 404 route: ${full}. Use 404.jsx or 404.tsx instead.`);
|
|
304
404
|
}
|
|
305
|
-
else if (/^(page|layout|404)\.(mdx|md|[jt]sx)$/.test(entry.name))
|
|
405
|
+
else if (/^(page|layout|404)\.(mdx|md|[jt]sx)$/.test(entry.name)) {
|
|
406
|
+
if (!(await isUnpublishedPage(full))) out.push(full);
|
|
407
|
+
}
|
|
306
408
|
}
|
|
307
409
|
return out;
|
|
308
410
|
}
|
|
@@ -502,12 +604,11 @@ export async function emitApiBundle({ root, appDir, afwEntry, exclude, i18n, out
|
|
|
502
604
|
const entry = join(tmp, "api-entry.js");
|
|
503
605
|
await writeFile(entry, apiEntrySource(discovered, appDir, i18n));
|
|
504
606
|
|
|
505
|
-
const serverApi = join(dirname(afwEntry), "server", "index.js");
|
|
506
607
|
await mkdirp(outDir);
|
|
507
608
|
const bundle = await build({
|
|
508
609
|
input: entry,
|
|
509
610
|
platform: "node",
|
|
510
|
-
resolve: { alias:
|
|
611
|
+
resolve: { alias: await afwAliases(afwEntry), extensions: EXTENSIONS },
|
|
511
612
|
external: (id) => !id.startsWith(".") && !id.startsWith("/") && !id.startsWith("@opentf/afw"),
|
|
512
613
|
});
|
|
513
614
|
try {
|
|
@@ -554,12 +655,11 @@ export async function emitLoaderBundle({ root, appDir, afwEntry, exclude, i18n,
|
|
|
554
655
|
const entry = join(tmp, "loaders-entry.js");
|
|
555
656
|
await writeFile(entry, loaderEntrySource(files, appDir, i18n));
|
|
556
657
|
|
|
557
|
-
const serverApi = join(dirname(afwEntry), "server", "index.js");
|
|
558
658
|
await mkdirp(outDir);
|
|
559
659
|
const bundle = await build({
|
|
560
660
|
input: entry,
|
|
561
661
|
platform: "node",
|
|
562
|
-
resolve: { alias:
|
|
662
|
+
resolve: { alias: await afwAliases(afwEntry), extensions: EXTENSIONS },
|
|
563
663
|
external: (id) => !id.startsWith(".") && !id.startsWith("/") && !id.startsWith("@opentf/afw"),
|
|
564
664
|
});
|
|
565
665
|
try {
|
|
@@ -645,11 +745,10 @@ export async function buildServerBundle({
|
|
|
645
745
|
const entry = join(tmp, "ssg-entry.js");
|
|
646
746
|
await writeFile(entry, serverEntrySource(pages, i18n));
|
|
647
747
|
|
|
648
|
-
const serverApi = join(dirname(afwEntry), "server", "index.js");
|
|
649
748
|
const bundle = await build({
|
|
650
749
|
input: entry,
|
|
651
750
|
resolve: {
|
|
652
|
-
alias:
|
|
751
|
+
alias: await afwAliases(afwEntry),
|
|
653
752
|
extensions: EXTENSIONS,
|
|
654
753
|
},
|
|
655
754
|
// The runtime guards its dev diagnostics on `process.env.NODE_ENV`, and there is
|