@ampless/runtime 1.0.0-beta.68 → 1.0.0-beta.69
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.ja.md +4 -1
- package/README.md +4 -1
- package/dist/middleware.d.ts +2 -0
- package/dist/middleware.js +12 -4
- package/dist/routes/index.d.ts +33 -11
- package/dist/routes/index.js +23 -0
- package/package.json +3 -3
package/README.ja.md
CHANGED
|
@@ -92,6 +92,9 @@ middleware はリクエストごとに AppSync から `post.format` /
|
|
|
92
92
|
`app/raw/[slug]/route.ts` で配信
|
|
93
93
|
- `format: 'static'` → `/static/<slug>(/<path>)`、
|
|
94
94
|
`app/static/[slug]/[[...path]]/route.ts` で配信
|
|
95
|
+
- `/<slug>.md`(フォーマット不問) → `/md/<slug>`、
|
|
96
|
+
`app/md/[slug]/route.ts` で配信 — `ampless.postToMarkdown()` による
|
|
97
|
+
Markdown 投影。`cms.config.ai.markdownRoutes: false` で無効化できます。
|
|
95
98
|
|
|
96
99
|
また、`post.metadata.cache`(auto / deep / hot)+ `post.updatedAt` +
|
|
97
100
|
`cms.config.cache.{cooldownMs, freshTtlSeconds, deepTtlSeconds}` から
|
|
@@ -102,7 +105,7 @@ middleware はリクエストごとに AppSync から `post.format` /
|
|
|
102
105
|
|
|
103
106
|
- `@ampless/runtime` — `createAmpless`、ランタイム型、`renderBody`・`renderThemeCss`・フォーマットコンバーターの再エクスポート
|
|
104
107
|
- `@ampless/runtime/middleware` — `createAmplessMiddleware`、`defaultMatcherConfig`
|
|
105
|
-
- `@ampless/runtime/routes` — `createOgRouteHandler`、`createSitemapRouteHandler`、`createFeedRouteHandler`、`createRawRouteHandler`、`createStaticRouteHandler`
|
|
108
|
+
- `@ampless/runtime/routes` — `createOgRouteHandler`、`createSitemapRouteHandler`、`createFeedRouteHandler`、`createRawRouteHandler`、`createStaticRouteHandler`、`createMarkdownRouteHandler`
|
|
106
109
|
- `@ampless/runtime/dispatchers` — `createThemeHomeDispatcher`、`createThemePostDispatcher`、`createThemeTagDispatcher`(それぞれ対応する `*Metadata` ファクトリーあり)
|
|
107
110
|
|
|
108
111
|
## テンプレートに残るもの
|
package/README.md
CHANGED
|
@@ -92,6 +92,9 @@ rewrites the request to the right internal handler:
|
|
|
92
92
|
`app/raw/[slug]/route.ts`
|
|
93
93
|
- `format: 'static'` → `/static/<slug>(/<path>)`, served by
|
|
94
94
|
`app/static/[slug]/[[...path]]/route.ts`
|
|
95
|
+
- `/<slug>.md` (any format) → `/md/<slug>`, served by
|
|
96
|
+
`app/md/[slug]/route.ts` — Markdown projection via
|
|
97
|
+
`ampless.postToMarkdown()`. Disable with `cms.config.ai.markdownRoutes: false`.
|
|
95
98
|
|
|
96
99
|
It also computes `Cache-Control` from `post.metadata.cache` (auto /
|
|
97
100
|
deep / hot) + `post.updatedAt` + `cms.config.cache.{cooldownMs,
|
|
@@ -102,7 +105,7 @@ See `docs/CONTENT.md` for the cache strategy contract.
|
|
|
102
105
|
|
|
103
106
|
- `@ampless/runtime` — `createAmpless`, runtime types, and re-exports of `renderBody`, `renderThemeCss`, format converters
|
|
104
107
|
- `@ampless/runtime/middleware` — `createAmplessMiddleware`, `defaultMatcherConfig`
|
|
105
|
-
- `@ampless/runtime/routes` — `createOgRouteHandler`, `createSitemapRouteHandler`, `createFeedRouteHandler`, `createRawRouteHandler`, `createStaticRouteHandler`
|
|
108
|
+
- `@ampless/runtime/routes` — `createOgRouteHandler`, `createSitemapRouteHandler`, `createFeedRouteHandler`, `createRawRouteHandler`, `createStaticRouteHandler`, `createMarkdownRouteHandler`
|
|
106
109
|
- `@ampless/runtime/dispatchers` — `createThemeHomeDispatcher`, `createThemePostDispatcher`, `createThemeTagDispatcher` (each with a matching `*Metadata` factory)
|
|
107
110
|
|
|
108
111
|
## What's still in the template
|
package/dist/middleware.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ declare function computeCacheControl(flags: {
|
|
|
32
32
|
* - Rewrite to `/static/<slug>(/<path>)` when the post is a static
|
|
33
33
|
* bundle (`format='static'`). Themed posts (default) get no
|
|
34
34
|
* rewrite — `app/[slug]/page.tsx` serves them directly.
|
|
35
|
+
* - Rewrite `/<slug>.md` → `/md/<slug>` (any format) unless
|
|
36
|
+
* `cms.config.ai.markdownRoutes` is explicitly `false`.
|
|
35
37
|
* - `Cache-Control` header computed from `post.metadata.cache` +
|
|
36
38
|
* `post.updatedAt` + `cms.config.cache.*` and set on the response.
|
|
37
39
|
* - `?previewTheme` / `?previewColorScheme` → `x-preview-theme` /
|
package/dist/middleware.js
CHANGED
|
@@ -135,7 +135,8 @@ var RESERVED_PREFIXES = /* @__PURE__ */ new Set([
|
|
|
135
135
|
"tag",
|
|
136
136
|
// internal rewrite targets — direct hits should not be middleware-driven
|
|
137
137
|
"raw",
|
|
138
|
-
"static"
|
|
138
|
+
"static",
|
|
139
|
+
"md"
|
|
139
140
|
]);
|
|
140
141
|
function createAmplessMiddleware(opts) {
|
|
141
142
|
return async function middleware(request) {
|
|
@@ -160,9 +161,11 @@ function createAmplessMiddleware(opts) {
|
|
|
160
161
|
return passthrough();
|
|
161
162
|
}
|
|
162
163
|
const restPath = segments.slice(1);
|
|
163
|
-
const
|
|
164
|
+
const isMdRequest = restPath.length === 0 && slug.endsWith(".md") && slug.length > 3 && opts.cmsConfig.ai?.markdownRoutes !== false;
|
|
165
|
+
const lookupSlug = isMdRequest ? slug.slice(0, -3) : slug;
|
|
166
|
+
const flags = await getCachedFlags(opts, lookupSlug);
|
|
164
167
|
if (!flags) {
|
|
165
|
-
if (restPath.length > 0) {
|
|
168
|
+
if (restPath.length > 0 || isMdRequest) {
|
|
166
169
|
return new NextResponse("Not Found", { status: 404 });
|
|
167
170
|
}
|
|
168
171
|
return passthrough();
|
|
@@ -170,7 +173,12 @@ function createAmplessMiddleware(opts) {
|
|
|
170
173
|
const cacheControl = computeCacheControl(flags, opts.cmsConfig);
|
|
171
174
|
let response;
|
|
172
175
|
if (restPath.length === 0) {
|
|
173
|
-
if (
|
|
176
|
+
if (isMdRequest) {
|
|
177
|
+
url.pathname = `/md/${lookupSlug}`;
|
|
178
|
+
response = NextResponse.rewrite(url, {
|
|
179
|
+
request: { headers: requestHeaders }
|
|
180
|
+
});
|
|
181
|
+
} else if (flags.format === "html" && flags.metadata?.no_layout === true) {
|
|
174
182
|
url.pathname = `/raw/${slug}`;
|
|
175
183
|
response = NextResponse.rewrite(url, {
|
|
176
184
|
request: { headers: requestHeaders }
|
package/dist/routes/index.d.ts
CHANGED
|
@@ -5,18 +5,18 @@ import 'react';
|
|
|
5
5
|
import 'aws-amplify/storage/server';
|
|
6
6
|
import 'next/headers';
|
|
7
7
|
|
|
8
|
-
interface Ctx$
|
|
8
|
+
interface Ctx$5 {
|
|
9
9
|
params: Promise<{
|
|
10
10
|
slug: string;
|
|
11
11
|
}>;
|
|
12
12
|
}
|
|
13
|
-
type OgRouteHandler = (req: Request, ctx: Ctx$
|
|
13
|
+
type OgRouteHandler = (req: Request, ctx: Ctx$5) => Promise<Response>;
|
|
14
14
|
declare function createOgRouteHandler(ampless: Ampless): OgRouteHandler;
|
|
15
15
|
|
|
16
|
-
interface Ctx$
|
|
16
|
+
interface Ctx$4 {
|
|
17
17
|
params: Promise<Record<string, never>>;
|
|
18
18
|
}
|
|
19
|
-
type SitemapRouteHandler = (req: Request, ctx: Ctx$
|
|
19
|
+
type SitemapRouteHandler = (req: Request, ctx: Ctx$4) => Promise<Response>;
|
|
20
20
|
/**
|
|
21
21
|
* Sitemap route delegate. Looks up the active theme and forwards to
|
|
22
22
|
* whichever `routes.sitemap` handler the theme provides. Themes
|
|
@@ -24,10 +24,10 @@ type SitemapRouteHandler = (req: Request, ctx: Ctx$3) => Promise<Response>;
|
|
|
24
24
|
*/
|
|
25
25
|
declare function createSitemapRouteHandler(ampless: Ampless): SitemapRouteHandler;
|
|
26
26
|
|
|
27
|
-
interface Ctx$
|
|
27
|
+
interface Ctx$3 {
|
|
28
28
|
params: Promise<Record<string, never>>;
|
|
29
29
|
}
|
|
30
|
-
type FeedRouteHandler = (req: Request, ctx: Ctx$
|
|
30
|
+
type FeedRouteHandler = (req: Request, ctx: Ctx$3) => Promise<Response>;
|
|
31
31
|
/**
|
|
32
32
|
* Feed route delegate. Looks up the active theme and forwards to
|
|
33
33
|
* whichever `routes.feed` handler the theme provides. Themes without
|
|
@@ -35,12 +35,12 @@ type FeedRouteHandler = (req: Request, ctx: Ctx$2) => Promise<Response>;
|
|
|
35
35
|
*/
|
|
36
36
|
declare function createFeedRouteHandler(ampless: Ampless): FeedRouteHandler;
|
|
37
37
|
|
|
38
|
-
interface Ctx$
|
|
38
|
+
interface Ctx$2 {
|
|
39
39
|
params: Promise<{
|
|
40
40
|
slug: string;
|
|
41
41
|
}>;
|
|
42
42
|
}
|
|
43
|
-
type RawRouteHandler = (req: Request, ctx: Ctx$
|
|
43
|
+
type RawRouteHandler = (req: Request, ctx: Ctx$2) => Promise<Response>;
|
|
44
44
|
/**
|
|
45
45
|
* Internal route handler for `format: 'html'` posts whose
|
|
46
46
|
* `metadata.no_layout === true` — the body is its own complete HTML
|
|
@@ -63,13 +63,13 @@ type RawRouteHandler = (req: Request, ctx: Ctx$1) => Promise<Response>;
|
|
|
63
63
|
*/
|
|
64
64
|
declare function createRawRouteHandler(ampless: Ampless): RawRouteHandler;
|
|
65
65
|
|
|
66
|
-
interface Ctx {
|
|
66
|
+
interface Ctx$1 {
|
|
67
67
|
params: Promise<{
|
|
68
68
|
slug: string;
|
|
69
69
|
path?: string[];
|
|
70
70
|
}>;
|
|
71
71
|
}
|
|
72
|
-
type StaticRouteHandler = (req: Request, ctx: Ctx) => Promise<Response>;
|
|
72
|
+
type StaticRouteHandler = (req: Request, ctx: Ctx$1) => Promise<Response>;
|
|
73
73
|
/**
|
|
74
74
|
* Internal route handler for `format: 'static'` posts — the body is a
|
|
75
75
|
* manifest describing a bundle of files in S3 at
|
|
@@ -97,4 +97,26 @@ type StaticRouteHandler = (req: Request, ctx: Ctx) => Promise<Response>;
|
|
|
97
97
|
*/
|
|
98
98
|
declare function createStaticRouteHandler(ampless: Ampless): StaticRouteHandler;
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
interface Ctx {
|
|
101
|
+
params: Promise<{
|
|
102
|
+
slug: string;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
type MarkdownRouteHandler = (req: Request, ctx: Ctx) => Promise<Response>;
|
|
106
|
+
/**
|
|
107
|
+
* Route handler serving the per-post Markdown projection
|
|
108
|
+
* (`ampless.postToMarkdown()`) for published posts of any format.
|
|
109
|
+
*
|
|
110
|
+
* Mounted at `app/md/[slug]/route.ts`; reached via middleware rewrite
|
|
111
|
+
* of `/<slug>.md` → `/md/<slug>` internally — the public/canonical URL
|
|
112
|
+
* is `/<slug>.md`. Middleware adds `md` to its reserved-prefix list so
|
|
113
|
+
* a user post with slug `md` passes through to a 404 rather than
|
|
114
|
+
* reaching this handler with the wrong content.
|
|
115
|
+
*
|
|
116
|
+
* Cache-Control: deliberately omitted from the response. Middleware
|
|
117
|
+
* computes the strategy from `post.metadata.cache` + `post.updatedAt`
|
|
118
|
+
* and sets the header on the rewritten response.
|
|
119
|
+
*/
|
|
120
|
+
declare function createMarkdownRouteHandler(ampless: Ampless): MarkdownRouteHandler;
|
|
121
|
+
|
|
122
|
+
export { type FeedRouteHandler, type MarkdownRouteHandler, type OgRouteHandler, type RawRouteHandler, type SitemapRouteHandler, type StaticRouteHandler, createFeedRouteHandler, createMarkdownRouteHandler, createOgRouteHandler, createRawRouteHandler, createSitemapRouteHandler, createStaticRouteHandler };
|
package/dist/routes/index.js
CHANGED
|
@@ -184,8 +184,31 @@ async function signStaticAsset({
|
|
|
184
184
|
return null;
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
+
|
|
188
|
+
// src/routes/md.ts
|
|
189
|
+
function createMarkdownRouteHandler(ampless) {
|
|
190
|
+
return async function GET(_request, { params }) {
|
|
191
|
+
const { slug } = await params;
|
|
192
|
+
const cleanSlug = slug.replace(/\.md$/, "");
|
|
193
|
+
if (ampless.cmsConfig.ai?.markdownRoutes === false) {
|
|
194
|
+
return new Response("Not Found", { status: 404 });
|
|
195
|
+
}
|
|
196
|
+
const post = await ampless.getPublishedPost(cleanSlug);
|
|
197
|
+
if (!post) {
|
|
198
|
+
return new Response("Not Found", { status: 404 });
|
|
199
|
+
}
|
|
200
|
+
return new Response(await ampless.postToMarkdown(post), {
|
|
201
|
+
status: 200,
|
|
202
|
+
headers: {
|
|
203
|
+
"Content-Type": "text/markdown; charset=utf-8"
|
|
204
|
+
// Cache-Control set by middleware.
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
}
|
|
187
209
|
export {
|
|
188
210
|
createFeedRouteHandler,
|
|
211
|
+
createMarkdownRouteHandler,
|
|
189
212
|
createOgRouteHandler,
|
|
190
213
|
createRawRouteHandler,
|
|
191
214
|
createSitemapRouteHandler,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ampless/runtime",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.69",
|
|
4
4
|
"description": "Public-side runtime for ampless: post fetching, theme dispatch, middleware, public route handlers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"marked": "^18.0.4",
|
|
52
52
|
"sanitize-html": "^2.17.4",
|
|
53
53
|
"tailwind-merge": "^3.6.0",
|
|
54
|
-
"@ampless/plugin-og-image": "0.2.0-beta.
|
|
55
|
-
"ampless": "1.0.0-beta.
|
|
54
|
+
"@ampless/plugin-og-image": "0.2.0-beta.56",
|
|
55
|
+
"ampless": "1.0.0-beta.56"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@aws-amplify/adapter-nextjs": "^1",
|