feat(website): the admin, with drafts, preview, publish and restore
Admin API and screens: dashboard and setup checklist, template and style, pages and blocks, ministries, leadership, media library with the storage limit, publish and history. Pending changes with who and when, discard one, one Publish, restore any version (each version keeps the working copy's rows, never sent to visitors). Preview on the site's own addresses with a bar (widths, back, publish); shared preview links for 7 days or until revoked. Roles checked, same-origin changes only. Publish refreshes the public pages at once (WEBSITE_CONTENT_CACHE_SECONDS). E2E on a production build: the admin's flows and axe on every screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
/**
|
||||
* A shared preview link (§4): keeps its token in a cookie for the rest of the visit, so every page
|
||||
* shows the working copy. The backend checks the token (7 days, until revoked) on every page.
|
||||
*/
|
||||
export async function GET(request: NextRequest, { params }: { params: Promise<{ token: string }> }) {
|
||||
const { token } = await params;
|
||||
const res = NextResponse.redirect(new URL("/", request.url), 303);
|
||||
if (/^[A-Za-z0-9_-]{20,100}$/.test(token)) {
|
||||
res.cookies.set("ccw_preview", token, { httpOnly: true, sameSite: "lax", secure: process.env.NODE_ENV === "production", path: "/", maxAge: 7 * 86400 });
|
||||
}
|
||||
res.headers.set("X-Robots-Tag", "noindex, nofollow");
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
/** Leaves the preview: an admin goes back to editing, someone with a shared link to the live site. */
|
||||
export function GET(request: NextRequest) {
|
||||
const admin = request.cookies.get("ccw_preview")?.value === "admin";
|
||||
const to = admin ? (request.nextUrl.searchParams.get("published") ? "/admin/publish" : "/admin") : "/";
|
||||
const res = NextResponse.redirect(new URL(to, request.url), 303);
|
||||
res.cookies.delete("ccw_preview");
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { Metadata } from "next";
|
||||
import { PreviewBar } from "@/site/PreviewBar";
|
||||
import { loadContent } from "@/site/load";
|
||||
|
||||
export const metadata: Metadata = { title: "Preview", robots: { index: false, follow: false } };
|
||||
|
||||
const WIDTHS: Record<string, number> = { phone: 390, tablet: 820 };
|
||||
|
||||
/**
|
||||
* The preview at phone or tablet width (§4): the site in a frame of that width, so its layout is
|
||||
* exactly what a phone shows. The bar stays outside the frame.
|
||||
*/
|
||||
export default async function Frame({ searchParams }: { searchParams: Promise<Record<string, string | undefined>> }) {
|
||||
const q = await searchParams;
|
||||
const size = q.size === "tablet" ? "tablet" : "phone";
|
||||
const c = await loadContent();
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-200">
|
||||
{c.mode === "published" && c.preview && <PreviewBar preview={c.preview} size={size} />}
|
||||
<div className="flex justify-center py-6">
|
||||
<iframe src="/" title={`The site at ${size} width`} style={{ width: WIDTHS[size], height: "calc(100vh - 7rem)" }} className="rounded-lg border border-gray-300 bg-white shadow-xl" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { NextResponse, type NextRequest } from "next/server";
|
||||
|
||||
/**
|
||||
* Preview (WEBSITE-1.0-PLAN §4): a signed-in admin sees the working copy on the site's own
|
||||
* addresses, fully clickable. The cookie only asks for it; the backend checks the admin's session
|
||||
* on every page (site/preview), so it shows nothing to anyone else.
|
||||
*/
|
||||
export function GET(request: NextRequest) {
|
||||
const res = NextResponse.redirect(new URL("/", request.url), 303);
|
||||
res.cookies.set("ccw_preview", "admin", { httpOnly: true, sameSite: "lax", secure: process.env.NODE_ENV === "production", path: "/" });
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user