From b3a2adb845698abbde468150e9dd03976367608a Mon Sep 17 00:00:00 2001 From: Rahul Varghese Date: Thu, 15 Oct 2026 08:36:47 +0530 Subject: [PATCH] CS1: the blog on Workers apps/web is Vercel's Blog with Sanity CMS with the Workers build around it: typegen at prebuild (offline, against the schema), next build (standalone, traced from the monorepo root, placeholders for the project id, dataset and token when unset), opennextjs-cloudflare build, populateCache into the static-assets bundle. tests/web exercises the image URL builder, the date component and the draft-mode enable route end to end with a mocked client. Departures from upstream, all recorded in the epic: the blog routes are force-dynamic with fetchCache force-no-store (ISR cannot run on the read-only static-assets cache; Sanity's API CDN is the 60 s cache) and generateStaticParams goes with it, the Studio loads client-side only so the sanity package ships as static assets and not inside the Worker (7.6 MB instead of 31 MB uploaded), VisualEditing comes from next-sanity/visual-editing, Speed Insights becomes the Cloudflare Web Analytics beacon (opt-in by token), next-sanity 13 and sanity 6 are the lines that declare Next 16, and Tailwind 4 replaces 3 because Studio v6's stylesheet uses cascade layers Tailwind 3 rejects. Orun-Task: CS-2 Co-Authored-By: Claude Fable 5.1 --- apps/web/.dev.vars.example | 7 + apps/web/.env.example | 15 + apps/web/.prettierignore | 3 + apps/web/README.md | 310 + apps/web/app/(blog)/actions.ts | 12 + apps/web/app/(blog)/alert-banner.tsx | 52 + apps/web/app/(blog)/analytics.tsx | 17 + apps/web/app/(blog)/avatar.tsx | 36 + apps/web/app/(blog)/cover-image.tsx | 31 + apps/web/app/(blog)/date.tsx | 9 + apps/web/app/(blog)/layout.tsx | 118 + apps/web/app/(blog)/more-stories.tsx | 46 + apps/web/app/(blog)/onboarding.tsx | 73 + apps/web/app/(blog)/page.tsx | 111 + apps/web/app/(blog)/portable-text.tsx | 49 + apps/web/app/(blog)/posts/[slug]/page.tsx | 103 + apps/web/app/(sanity)/apple-icon.png | Bin 0 -> 3682 bytes apps/web/app/(sanity)/icon.ico | Bin 0 -> 4286 bytes apps/web/app/(sanity)/icon.png | Bin 0 -> 10466 bytes apps/web/app/(sanity)/icon.svg | 7 + apps/web/app/(sanity)/layout.tsx | 33 + .../app/(sanity)/studio/[[...tool]]/page.tsx | 7 + .../studio/[[...tool]]/studio-client.tsx | 9 + .../(sanity)/studio/[[...tool]]/studio.tsx | 15 + apps/web/app/api/draft-mode/enable/route.ts | 8 + apps/web/app/favicon.ico | Bin 0 -> 15086 bytes apps/web/app/globals.css | 20 + apps/web/component.yaml | 70 + apps/web/eslint.config.mjs | 20 + apps/web/next.config.ts | 16 + apps/web/open-next.config.ts | 14 + apps/web/package.json | 52 + apps/web/postcss.config.js | 5 + apps/web/sanity.cli.ts | 19 + apps/web/sanity.config.ts | 89 + apps/web/sanity.types.ts | 627 + apps/web/sanity/lib/api.ts | 33 + apps/web/sanity/lib/client.ts | 22 + apps/web/sanity/lib/demo.ts | 59 + apps/web/sanity/lib/fetch.ts | 58 + apps/web/sanity/lib/queries.ts | 34 + apps/web/sanity/lib/token.ts | 7 + apps/web/sanity/lib/utils.ts | 37 + apps/web/sanity/plugins/assist.ts | 265 + apps/web/sanity/plugins/settings.tsx | 65 + apps/web/sanity/schemas/documents/author.ts | 45 + apps/web/sanity/schemas/documents/post.ts | 111 + .../sanity/schemas/singletons/settings.tsx | 129 + apps/web/schema.json | 2337 +++ apps/web/tsconfig.json | 39 + apps/web/turbo.json | 10 + apps/web/wrangler.jsonc | 12 + pnpm-lock.yaml | 16061 +++++++++++++++- tests/web/component.yaml | 22 + tests/web/eslint.config.js | 2 + tests/web/package.json | 25 + tests/web/src/date.test.ts | 15 + tests/web/src/draft-mode.test.ts | 111 + tests/web/src/sanity-utils.test.ts | 54 + tests/web/tsconfig.json | 15 + tests/web/vitest.config.ts | 21 + 61 files changed, 20834 insertions(+), 758 deletions(-) create mode 100644 apps/web/.dev.vars.example create mode 100644 apps/web/.env.example create mode 100644 apps/web/.prettierignore create mode 100644 apps/web/README.md create mode 100644 apps/web/app/(blog)/actions.ts create mode 100644 apps/web/app/(blog)/alert-banner.tsx create mode 100644 apps/web/app/(blog)/analytics.tsx create mode 100644 apps/web/app/(blog)/avatar.tsx create mode 100644 apps/web/app/(blog)/cover-image.tsx create mode 100644 apps/web/app/(blog)/date.tsx create mode 100644 apps/web/app/(blog)/layout.tsx create mode 100644 apps/web/app/(blog)/more-stories.tsx create mode 100644 apps/web/app/(blog)/onboarding.tsx create mode 100644 apps/web/app/(blog)/page.tsx create mode 100644 apps/web/app/(blog)/portable-text.tsx create mode 100644 apps/web/app/(blog)/posts/[slug]/page.tsx create mode 100644 apps/web/app/(sanity)/apple-icon.png create mode 100644 apps/web/app/(sanity)/icon.ico create mode 100644 apps/web/app/(sanity)/icon.png create mode 100644 apps/web/app/(sanity)/icon.svg create mode 100644 apps/web/app/(sanity)/layout.tsx create mode 100644 apps/web/app/(sanity)/studio/[[...tool]]/page.tsx create mode 100644 apps/web/app/(sanity)/studio/[[...tool]]/studio-client.tsx create mode 100644 apps/web/app/(sanity)/studio/[[...tool]]/studio.tsx create mode 100644 apps/web/app/api/draft-mode/enable/route.ts create mode 100644 apps/web/app/favicon.ico create mode 100644 apps/web/app/globals.css create mode 100644 apps/web/component.yaml create mode 100644 apps/web/eslint.config.mjs create mode 100644 apps/web/next.config.ts create mode 100644 apps/web/open-next.config.ts create mode 100644 apps/web/package.json create mode 100644 apps/web/postcss.config.js create mode 100644 apps/web/sanity.cli.ts create mode 100644 apps/web/sanity.config.ts create mode 100644 apps/web/sanity.types.ts create mode 100644 apps/web/sanity/lib/api.ts create mode 100644 apps/web/sanity/lib/client.ts create mode 100644 apps/web/sanity/lib/demo.ts create mode 100644 apps/web/sanity/lib/fetch.ts create mode 100644 apps/web/sanity/lib/queries.ts create mode 100644 apps/web/sanity/lib/token.ts create mode 100644 apps/web/sanity/lib/utils.ts create mode 100644 apps/web/sanity/plugins/assist.ts create mode 100644 apps/web/sanity/plugins/settings.tsx create mode 100644 apps/web/sanity/schemas/documents/author.ts create mode 100644 apps/web/sanity/schemas/documents/post.ts create mode 100644 apps/web/sanity/schemas/singletons/settings.tsx create mode 100644 apps/web/schema.json create mode 100644 apps/web/tsconfig.json create mode 100644 apps/web/turbo.json create mode 100644 apps/web/wrangler.jsonc create mode 100644 tests/web/component.yaml create mode 100644 tests/web/eslint.config.js create mode 100644 tests/web/package.json create mode 100644 tests/web/src/date.test.ts create mode 100644 tests/web/src/draft-mode.test.ts create mode 100644 tests/web/src/sanity-utils.test.ts create mode 100644 tests/web/tsconfig.json create mode 100644 tests/web/vitest.config.ts diff --git a/apps/web/.dev.vars.example b/apps/web/.dev.vars.example new file mode 100644 index 0000000..8145d0d --- /dev/null +++ b/apps/web/.dev.vars.example @@ -0,0 +1,7 @@ +# Local Worker secrets for `wrangler dev` / `opennextjs-cloudflare preview`. +# Copy to .dev.vars (git-ignored). In stage/prod this is a Worker secret, set +# once per environment with +# wrangler secret put SANITY_API_READ_TOKEN --name cms-sanity-web- +# (README → Deploying); the deploy lane does not set it. The project id and +# dataset are not here: they are inlined at build time (see .env.example). +SANITY_API_READ_TOKEN= diff --git a/apps/web/.env.example b/apps/web/.env.example new file mode 100644 index 0000000..91119bf --- /dev/null +++ b/apps/web/.env.example @@ -0,0 +1,15 @@ +# https://github.com/vercel/next.js/tree/canary/examples/cms-sanity#using-the-sanity-cli +# Copy to .env.local (git-ignored) for `next dev`. The project id and dataset +# are build-time public values: `next build` inlines them into the server and +# the Studio bundles, so the build that deploys must have them (the Orun build +# exports them from the product's secrets, apps/web/component.yaml). Unset, +# the build script substitutes `placeholder` for both so the credential-free +# build in Checks still runs — the Worker then has no project to read from. +NEXT_PUBLIC_SANITY_PROJECT_ID= +NEXT_PUBLIC_SANITY_DATASET= +# The read token (draft mode / live preview) is read at request time. Here it +# serves `next dev`; the Worker reads it as a secret — see .dev.vars.example. +SANITY_API_READ_TOKEN= +# Optional. Cloudflare Web Analytics beacon token (stands in for Vercel Speed +# Insights). Unset → no script is rendered. +NEXT_PUBLIC_CF_BEACON_TOKEN= diff --git a/apps/web/.prettierignore b/apps/web/.prettierignore new file mode 100644 index 0000000..1509c4c --- /dev/null +++ b/apps/web/.prettierignore @@ -0,0 +1,3 @@ +# Ignoring generated files +./sanity.types.ts +./schema.json diff --git a/apps/web/README.md b/apps/web/README.md new file mode 100644 index 0000000..168a293 --- /dev/null +++ b/apps/web/README.md @@ -0,0 +1,310 @@ +# A statically generated blog example using Next.js and Sanity + +![Screenshot of Sanity Studio using Presentation Tool to do Visual Editing](https://github.com/sanity-io/next.js/assets/81981/59ecd9d6-7a78-41c6-95f7-275f66fe3c9d) + +This starter is a statically generated blog that uses Next.js App Router for the frontend and [Sanity][sanity-homepage] to handle its content. It comes with a native Sanity Studio that offers features like real-time collaboration and visual editing with live updates using [Presentation][presentation]. + +The Studio connects to Sanity Content Lake, which gives you hosted content APIs with a flexible query language, on-demand image transformations, powerful patching, and more. You can use this starter to kick-start a blog or learn these technologies. + +## Features + +- A performant, static blog with editable posts, authors, and site settings +- TypeScript setup with [Sanity TypeGen](https://www.sanity.io/docs/sanity-typegen) +- A native and customizable authoring environment, accessible on `yourblog.com/studio` +- Real-time and collaborative content editing with fine-grained revision history +- Side-by-side instant content preview that works across your whole site +- Support for block content and the most advanced custom fields capability in the industry +- Incremental Static Revalidation; no need to wait for a rebuild to publish new content +- Unsplash integration setup for easy media management +- [Sanity AI Assist preconfigured for image alt text generation](https://www.sanity.io/docs/ai-assist?utm_source=github.com&utm_medium=organic_social&utm_campaign=ai-assist&utm_content=) +- Out of the box support for [Vercel Visual Editing](https://www.sanity.io/blog/visual-editing-sanity-vercel?utm_source=github.com&utm_medium=referral&utm_campaign=may-vercel-launch). + +## Demo + +### [https://next-blog.sanity.build](https://next-blog.sanity.build) + +## Deploy your own + +Use the Deploy Button below, you'll deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example) as well as connect it to your Sanity dataset using [the Sanity Vercel Integration][integration]. + +[![Deploy with Vercel](https://vercel.com/button)][vercel-deploy] + +## How to use + +Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example: + +```bash +npx create-next-app --example cms-sanity next-sanity-blog +``` + +```bash +yarn create next-app --example cms-sanity next-sanity-blog +``` + +```bash +pnpm create next-app --example cms-sanity next-sanity-blog +``` + +Whenever you edit a GROQ query you update the TypeScript types by running: + +```bash +npm run typegen +``` + +# Configuration + +- [Step 1. Set up the environment](#step-1-set-up-the-environment) + - [Reuse remote environment variables](#reuse-remote-environment-variables) + - [Using the Sanity CLI](#using-the-sanity-cli) + - [Creating a read token](#creating-a-read-token) +- [Step 2. Run Next.js locally in development mode](#step-2-run-nextjs-locally-in-development-mode) +- [Step 3. Populate content](#step-3-populate-content) +- [Step 4. Deploy to production](#step-4-deploy-to-production) +- [Next steps](#next-steps) + +## Step 1. Set up the environment + +### Reuse remote environment variables + +If you started with [deploying your own](#deploy-your-own) then you can run this to reuse the environment variables from the Vercel project and skip to the next step: + +```bash +npx vercel link +npx vercel env pull +``` + +### Using the Sanity CLI + +Copy the `.env.local.example` file to `.env.local` to get started: + +```bash +cp -i .env.local.example .env.local +``` + +Run the setup command to get setup with a Sanity project, dataset and their relevant environment variables: + +```bash +npm run setup +``` + +```bash +yarn setup +``` + +```bash +pnpm run setup +``` + +You'll be asked multiple questions, here's a sample output of what you can expect: + +```bash +Need to install the following packages: +sanity@3.30.1 +Ok to proceed? (y) y +You're setting up a new project! +We'll make sure you have an account with Sanity.io. +Press ctrl + C at any time to quit. + +Prefer web interfaces to terminals? +You can also set up best practice Sanity projects with +your favorite frontends on https://www.sanity.io/templates + +Looks like you already have a Sanity-account. Sweet! + +✔ Fetching existing projects +? Select project to use Templates [r0z1eifg] +? Select dataset to use blog-vercel +? Would you like to add configuration files for a Sanity project in this Next.js folder? No + +Detected framework Next.js, using prefix 'NEXT_PUBLIC_' +Found existing NEXT_PUBLIC_SANITY_PROJECT_ID, replacing value. +Found existing NEXT_PUBLIC_SANITY_DATASET, replacing value. +``` + +It's important that when you're asked `Would you like to add configuration files for a Sanity project in this Next.js folder?` that you answer `No` as this example is already setup with the required configuration files. + +#### Creating a read token + +This far your `.env.local` file should have values for `NEXT_PUBLIC_SANITY_PROJECT_ID` and `NEXT_PUBLIC_SANITY_DATASET`. +Before you can run the project you need to setup a read token (`SANITY_API_READ_TOKEN`), it's used for authentication when Sanity Studio is live previewing your application. + +1. Go to [manage.sanity.io](https://manage.sanity.io/) and select your project. +2. Click on the `🔌 API` tab. +3. Click on `+ Add API token`. +4. Name it "next blog live preview read token" and set `Permissions` to `Viewer` and hit `Save`. +5. Copy the token and add it to your `.env.local` file. + +```bash +SANITY_API_READ_TOKEN="" +``` + +Your `.env.local` file should look something like this: + +```bash +NEXT_PUBLIC_SANITY_PROJECT_ID="r0z1eifg" +NEXT_PUBLIC_SANITY_DATASET="blog-vercel" +SANITY_API_READ_TOKEN="sk..." +``` + +> [!CAUTION] +> Make sure to add `.env.local` to your `.gitignore` file so you don't accidentally commit it to your repository. + +## Step 2. Run Next.js locally in development mode + +```bash +npm install && npm run dev +``` + +```bash +yarn install && yarn dev +``` + +```bash +pnpm install && pnpm dev +``` + +Your blog should be up and running on [http://localhost:3000](http://localhost:3000)! If it doesn't work, post on [GitHub discussions](https://github.com/vercel/next.js/discussions). + +## Step 3. Populate content + +Open your Sanity Studio that should be running on [http://localhost:3000/studio](http://localhost:3000/studio). + +By default you're taken to the [Presentation tool][presentation], which has a preview of the blog on the left hand side, and a list of documents on the right hand side. + +
+View screenshot ✨ + +![screenshot](https://github.com/vercel/next.js/assets/81981/07cbc580-4a03-4837-9aa4-90b632c95630) + +
+ +We're all set to do some content creation! + +- Click on the **"+ Create"** button top left and select **Post** +- Type some dummy data for the **Title** +- **Generate** a **Slug** +
+ Now that you have a slug you should see the post show up in the preview on the left hand side ✨ + + ![screenshot](https://github.com/vercel/next.js/assets/81981/05b74848-6ae4-442b-8995-0b7e2180aa74) + +
+ +- Fill in **Content** with some dummy text +
+ Or generate it with AI Assist ✨ + + If you've enabled [AI Assist][enable-ai-assist] you click on the sparkles ✨ button and generate a draft based on your title and then on **Generate sample content**. + + ![screenshot](https://github.com/vercel/next.js/assets/81981/2276d8ad-5b55-447c-befe-d53249f091e1) + +
+ +- Summarize the **Content** in the **Excerpt** field +
+ Or have AI Assist summarize it for you ✨ + + If you've enabled [AI Assist][enable-ai-assist] you click on the sparkles ✨ button and then on **Generate sample content**. + + ![screenshot](https://github.com/vercel/next.js/assets/81981/d24b9b37-cd88-4519-8094-f4c956102450) + +
+ +- Select a **Cover Image** from [Unsplash]. +
+ Unsplash is available in the **Select** dropdown ✨ + + ![screenshot](https://github.com/vercel/next.js/assets/81981/204d004d-9396-434e-8795-a8b68a2ed89b) + +
+
+ Click the "Crop image" button to adjust hotspots and cropping ✨ + + ![screenshot](https://github.com/vercel/next.js/assets/81981/e905fc6e-5bab-46a7-baec-7cb08747772c) + +
+
+ You can preview the results live on the left side, and additional formats on the right side ✨ + + ![screenshot](https://github.com/vercel/next.js/assets/81981/6c59eef0-d2d9-4d77-928a-98e99df4b1df) + +
+ +- Customize the blog name, description and more. +
+ Click "Structure" at the top center, then on "Settings" on the left hand side ✨ + + ![screenshot](https://github.com/vercel/next.js/assets/81981/14f48d83-af81-4589-900e-a7a598cc608a) + +
+
+ Once you have a "Settings" document, you can customize it inside "Presentation" ✨ + + ![screenshot](https://github.com/vercel/next.js/assets/81981/e3473f7b-5e7e-46ab-8d43-cae54a4b929b) + +
+ +> [!IMPORTANT] +> For each post record, you need to click **Publish** after saving for it to be visible outside Draft Mode. In production new content is using [Time-based Revalidation](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#time-based-revalidation), which means it may take up to 1 minute before changes show up. Since a stale-while-revalidate pattern is used you may need to refresh a couple of times to see the changes. + +## Step 4. Deploy to production + +> [!NOTE] +> If you already [deployed with Vercel earlier](#deploy-your-own) you can skip this step. + +To deploy your local project to Vercel, push it to [GitHub](https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/adding-locally-hosted-code-to-github)/GitLab/Bitbucket and [import to Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example). + +> [!IMPORTANT] +> When you import your project on Vercel, make sure to click on **Environment Variables** and set them to match your `.env.local` file. + +After it's deployed link your local code to the Vercel project: + +```bash +npx vercel link +``` + +> [!TIP] +> In production you can exit Draft Mode by clicking on _"Back to published"_ at the top. On [Preview deployments](https://vercel.com/docs/deployments/preview-deployments) you can [toggle Draft Mode in the Vercel Toolbar](https://vercel.com/docs/workflow-collaboration/draft-mode#enabling-draft-mode-in-the-vercel-toolbar). + +## Next steps + +- [Join the Sanity community](https://slack.sanity.io/) + +## Related examples + +- [AgilityCMS](/examples/cms-agilitycms) +- [Builder.io](/examples/cms-builder-io) +- [ButterCMS](/examples/cms-buttercms) +- [Contentful](/examples/cms-contentful) +- [Cosmic](/examples/cms-cosmic) +- [DatoCMS](/examples/cms-datocms) +- [DotCMS](/examples/cms-dotcms) +- [Drupal](/examples/cms-drupal) +- [Enterspeed](/examples/cms-enterspeed) +- [Ghost](/examples/cms-ghost) +- [GraphCMS](/examples/cms-graphcms) +- [Kontent.ai](/examples/cms-kontent-ai) +- [MakeSwift](/examples/cms-makeswift) +- [Payload](/examples/cms-payload) +- [Plasmic](/examples/cms-plasmic) +- [Prepr](/examples/cms-prepr) +- [Prismic](/examples/cms-prismic) +- [Sanity](/examples/cms-sanity) +- [Sitecore XM Cloud](/examples/cms-sitecore-xmcloud) +- [Sitefinity](/examples/cms-sitefinity) +- [Storyblok](/examples/cms-storyblok) +- [TakeShape](/examples/cms-takeshape) +- [Tina](/examples/cms-tina) +- [Umbraco](/examples/cms-umbraco) +- [Umbraco heartcore](/examples/cms-umbraco-heartcore) +- [Webiny](/examples/cms-webiny) +- [WordPress](/examples/cms-wordpress) +- [Blog Starter](/examples/blog-starter) + +[vercel-deploy]: https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fnext.js%2Ftree%2Fcanary%2Fexamples%2Fcms-sanity&repository-name=cms-sanity&project-name=cms-sanity&demo-title=Blog%20using%20Next.js%20%26%20Sanity&demo-description=Real-time%20updates%2C%20seamless%20editing%2C%20no%20rebuild%20delays.&demo-url=https%3A%2F%2Fnext-blog.sanity.build%2F&demo-image=https%3A%2F%2Fgithub.com%2Fsanity-io%2Fnext-sanity%2Fassets%2F81981%2Fb81296a9-1f53-4eec-8948-3cb51aca1259&integration-ids=oac_hb2LITYajhRQ0i4QznmKH7gx +[integration]: https://www.sanity.io/docs/vercel-integration +[`.env.local.example`]: .env.local.example +[unsplash]: https://unsplash.com +[sanity-homepage]: https://www.sanity.io?utm_source=github.com&utm_medium=referral&utm_campaign=nextjs-v3vercelstarter +[presentation]: https://www.sanity.io/docs/presentation +[enable-ai-assist]: https://www.sanity.io/plugins/ai-assist#enabling-the-ai-assist-api diff --git a/apps/web/app/(blog)/actions.ts b/apps/web/app/(blog)/actions.ts new file mode 100644 index 0000000..b8f951f --- /dev/null +++ b/apps/web/app/(blog)/actions.ts @@ -0,0 +1,12 @@ +"use server"; + +import { draftMode } from "next/headers"; + +export async function disableDraftMode() { + "use server"; + await Promise.allSettled([ + (await draftMode()).disable(), + // Simulate a delay to show the loading state + new Promise((resolve) => setTimeout(resolve, 1000)), + ]); +} diff --git a/apps/web/app/(blog)/alert-banner.tsx b/apps/web/app/(blog)/alert-banner.tsx new file mode 100644 index 0000000..567bf34 --- /dev/null +++ b/apps/web/app/(blog)/alert-banner.tsx @@ -0,0 +1,52 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import { useSyncExternalStore, useTransition } from "react"; + +import { disableDraftMode } from "./actions"; + +const emptySubscribe = () => () => {}; + +export default function AlertBanner() { + const router = useRouter(); + const [pending, startTransition] = useTransition(); + + const shouldShow = useSyncExternalStore( + emptySubscribe, + () => window.top === window, + () => false, + ); + + if (!shouldShow) return null; + + return ( +
+
+ {pending ? ( + "Disabling draft mode..." + ) : ( + <> + {"Previewing drafts. "} + + + )} +
+
+ ); +} diff --git a/apps/web/app/(blog)/analytics.tsx b/apps/web/app/(blog)/analytics.tsx new file mode 100644 index 0000000..a1d8051 --- /dev/null +++ b/apps/web/app/(blog)/analytics.tsx @@ -0,0 +1,17 @@ +// Cloudflare Web Analytics stands in for @vercel/speed-insights: one beacon +// script, Core Web Vitals included. It renders nothing until +// NEXT_PUBLIC_CF_BEACON_TOKEN is set at build time (Cloudflare dashboard → +// Web Analytics → add a site → the JS snippet token). +export function CloudflareWebAnalytics() { + const token = process.env.NEXT_PUBLIC_CF_BEACON_TOKEN; + if (!token) { + return null; + } + return ( +