@soloworks/smking-next 0.20.2 → 0.20.3
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/CHANGELOG.md +11 -0
- package/package.json +1 -1
- package/src/lib/preview-route.ts +15 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @soloworks/smking-next
|
|
2
2
|
|
|
3
|
+
## 0.20.3 — 2026-06-08
|
|
4
|
+
|
|
5
|
+
**CMS draft preview URL now carries a visible `?smking_preview=1` marker.**
|
|
6
|
+
|
|
7
|
+
The `/smking-preview` route still enables Next.js Draft Mode + stashes the
|
|
8
|
+
token in an httpOnly cookie, but now redirects to `…/path?smking_preview=1`
|
|
9
|
+
instead of the bare path. This makes a preview tab's URL visibly distinct from
|
|
10
|
+
the published page so authors can tell draft from live at a glance (parity with
|
|
11
|
+
the Laravel SDK). The token stays in the cookie — never the URL. Additive, so
|
|
12
|
+
`^0.20` gets it automatically.
|
|
13
|
+
|
|
3
14
|
## 0.20.2 — 2026-06-08
|
|
4
15
|
|
|
5
16
|
**Feature (additive — shipped as a patch): CMS draft preview via Next.js Draft Mode.**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soloworks/smking-next",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.3",
|
|
4
4
|
"description": "AI-native SEO (AEO) for Next.js — auto-inject JSON-LD, FAQ, AI summary, and SEO metadata so AI crawlers (ChatGPT, Perplexity, Google AI) can cite your pages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/sillyleo/smking/tree/main/packages/smking-next",
|
package/src/lib/preview-route.ts
CHANGED
|
@@ -11,8 +11,13 @@ import { redirect } from "next/navigation";
|
|
|
11
11
|
*
|
|
12
12
|
* Flow: the dashboard 預覽鈕 opens `/smking-preview?token=…&path=/blog/x` →
|
|
13
13
|
* this enables Next.js Draft Mode + stashes the short-lived token in an
|
|
14
|
-
* httpOnly cookie → redirects to
|
|
15
|
-
* from draftBlocks (status "preview").
|
|
14
|
+
* httpOnly cookie → redirects to `/blog/x?smking_preview=1`, which
|
|
15
|
+
* `<SmkingCms>` then renders from draftBlocks (status "preview").
|
|
16
|
+
*
|
|
17
|
+
* The `?smking_preview=1` marker makes the preview tab's URL visibly distinct
|
|
18
|
+
* from the live page at a glance (parity with the Laravel SDK's
|
|
19
|
+
* `?smking_preview=` URL). The token itself stays in the httpOnly Draft Mode
|
|
20
|
+
* cookie — never the URL — so it can't leak via the address bar / referrer.
|
|
16
21
|
*
|
|
17
22
|
* Fail-safe / install-only:
|
|
18
23
|
* - No token → plain redirect to the live page (Draft Mode NOT enabled).
|
|
@@ -27,6 +32,7 @@ export async function GET(request: Request): Promise<Response> {
|
|
|
27
32
|
const path =
|
|
28
33
|
rawPath.startsWith("/") && !rawPath.startsWith("//") ? rawPath : "/";
|
|
29
34
|
|
|
35
|
+
let target = path;
|
|
30
36
|
if (token) {
|
|
31
37
|
(await draftMode()).enable();
|
|
32
38
|
(await cookies()).set("smking_preview_token", token, {
|
|
@@ -35,8 +41,14 @@ export async function GET(request: Request): Promise<Response> {
|
|
|
35
41
|
path: "/",
|
|
36
42
|
maxAge: 60 * 15,
|
|
37
43
|
});
|
|
44
|
+
// Visible marker so the preview tab's URL differs from the live page at a
|
|
45
|
+
// glance (parity with the Laravel SDK). The token rides the httpOnly
|
|
46
|
+
// cookie above — deliberately kept OUT of the URL: it'd be a dead param
|
|
47
|
+
// (<SmkingCms> reads the cookie) and would leak into address bar / referrer.
|
|
48
|
+
const sep = path.includes("?") ? "&" : "?";
|
|
49
|
+
target = `${path}${sep}smking_preview=1`;
|
|
38
50
|
}
|
|
39
51
|
|
|
40
52
|
// redirect() throws NEXT_REDIRECT — expected control flow in route handlers.
|
|
41
|
-
redirect(
|
|
53
|
+
redirect(target);
|
|
42
54
|
}
|