Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 16 additions & 48 deletions src/components/landing/BuildFromScratch.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Icon from "@cloudflare/nimbus-docs/components/Icon.astro";
import CommandBlock from "./CommandBlock.astro";
import CornerMarks from "@/components/CornerMarks.astro";
import { LinkButton } from "@/components/ui/link-button";
import CliPreferenceSelector from "@/components/ui/cli-preference/CliPreferenceSelector.astro";
import SectionHeading from "./SectionHeading.astro";
import TabBar from "./TabBar.astro";

Expand All @@ -21,10 +20,10 @@ const primitives = [
heading: "Deploy with one command",
description:
"Build and deploy serverless functions and full-stack apps on Cloudflare's global network. No servers to manage. No cold starts or region complexity.",
command: "npm create cloudflare@latest my-app",
command: "npx cf init my-app",
cta: {
label: "Create your first Worker",
href: "/workers/get-started/guide/",
href: "/cf/get-started/first-worker/",
},
tags: [
{ label: "Workers", href: "/workers/" },
Expand All @@ -44,8 +43,8 @@ const primitives = [
heading: "The AI inference platform",
description:
"Run AI inference globally with one API call, build agents, and search across your data — no GPUs to manage, no capacity planning.",
command: "npx wrangler ai models",
cfCommand: "cf ai run @cf/meta/llama-3.1-8b-instruct --help",
command:
'cf ai run @cf/meta/llama-4-scout-17b-16e-instruct --prompt "Write a haiku about lava lamps"',
cta: { label: "Browse available models", href: "/workers-ai/models/" },
tags: [
{ label: "Workers AI", href: "/workers-ai/" },
Expand All @@ -66,8 +65,7 @@ const primitives = [
heading: "Make your database feel instant, everywhere",
description:
"Serverless SQL, globally distributed key-value, and global database acceleration — query directly from Workers with no connection management.",
command: "npx wrangler d1 create my-database",
cfCommand: "cf d1 --help",
command: "cf d1 create --name my-database",
cta: { label: "Get started with D1", href: "/d1/get-started/" },
tags: [
{ label: "R2", href: "/r2/" },
Expand All @@ -88,8 +86,7 @@ const primitives = [
heading: "Build media pipelines without infrastructure headaches",
description:
"Cloudflare Images helps teams build scalable, reliable media pipelines to store, optimize, and deliver images.",
command:
"curl --request POST https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/images/v1",
command: "cf images create --file ./image.png",
cta: {
label: "Get started with Images",
href: "/images/get-started/introduction/",
Expand All @@ -103,18 +100,10 @@ const primitives = [
];
---

<section
class="pt-10 pb-6 lg:pt-14"
aria-labelledby={headingId}
id={sectionId}
data-nb-cli-preference-scope
>
<div class="mb-2 flex flex-wrap items-center justify-between gap-x-4 gap-y-6 lg:mb-8">
<SectionHeading id={headingId}>
Powerful primitives, seamlessly integrated
</SectionHeading>
<CliPreferenceSelector class="max-lg:w-full max-lg:justify-between lg:pr-4" />
</div>
<section class="pt-10 pb-6 lg:pt-14" aria-labelledby={headingId} id={sectionId}>
<SectionHeading id={headingId} class="mb-8">
Powerful primitives, seamlessly integrated
</SectionHeading>

<div class="border-border relative overflow-visible border">
<CornerMarks />
Expand Down Expand Up @@ -152,33 +141,12 @@ const primitives = [
{p.description}
</p>

{p.cfCommand ? (
<>
<div data-nb-cli-variant="cf">
<CommandBlock
id={`${sectionId}-cmd-${p.id}-cf`}
command={p.cfCommand}
rounded
class="mb-6 max-w-[680px]"
/>
</div>
<div data-nb-cli-variant="wrangler">
<CommandBlock
id={`${sectionId}-cmd-${p.id}-wrangler`}
command={p.command}
rounded
class="mb-6 max-w-[680px]"
/>
</div>
</>
) : (
<CommandBlock
id={`${sectionId}-cmd-${p.id}`}
command={p.command}
rounded
class="mb-6 max-w-[680px]"
/>
)}
<CommandBlock
id={`${sectionId}-cmd-${p.id}`}
command={p.command}
rounded
class="mb-6 max-w-[840px]"
/>

<div class="flex w-full flex-col items-start gap-4 sm:flex-row sm:items-center sm:gap-6">
<LinkButton href={p.cta.href} variant="secondary" size="base">
Expand Down
54 changes: 32 additions & 22 deletions src/components/landing/BuildFromScratch.astro.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,48 @@ import { expect, test } from "vitest";

import BuildFromScratch from "./BuildFromScratch.astro";

test("renders copyable commands for both CLI preferences", async () => {
test("renders copyable cf onboarding commands directly without a Wrangler/CF switcher", async () => {
const container = await AstroContainer.create();
const root = parse(await container.renderToString(BuildFromScratch));
const section = root.querySelector("#build[data-nb-cli-preference-scope]");
const section = root.querySelector("#build");

expect(section).not.toBeNull();
expect(
section?.querySelector('[data-nb-cli-toggle="wrangler"]'),
).not.toBeNull();
expect(section?.querySelector('[data-nb-cli-toggle="cf"]')).not.toBeNull();
expect(section?.hasAttribute("data-nb-cli-preference-scope")).toBe(false);
expect(section?.querySelector("[data-nb-cli-toggle]")).toBeNull();
expect(section?.querySelector("[data-nb-cli-variant]")).toBeNull();

for (const [panelId, commands] of Object.entries({
for (const [panelId, expected] of Object.entries({
compute: {
command: "npx cf init my-app",
ctaHref: "/cf/get-started/first-worker/",
},
ai: {
wrangler: "npx wrangler ai models",
cf: "cf ai run @cf/meta/llama-3.1-8b-instruct --help",
command:
'cf ai run @cf/meta/llama-4-scout-17b-16e-instruct --prompt "Write a haiku about lava lamps"',
ctaHref: "/workers-ai/models/",
},
storage: {
wrangler: "npx wrangler d1 create my-database",
cf: "cf d1 --help",
command: "cf d1 create --name my-database",
ctaHref: "/d1/get-started/",
},
media: {
command: "cf images create --file ./image.png",
ctaHref: "/images/get-started/introduction/",
},
})) {
const panel = section?.querySelector(`#build-panel-${panelId}`);
for (const [cli, command] of Object.entries(commands)) {
const variant = panel?.querySelector(`[data-nb-cli-variant="${cli}"]`);
const codeId = `build-cmd-${panelId}-${cli}`;
expect(variant?.querySelector("code")?.id).toBe(codeId);
expect(variant?.querySelector("code")?.textContent).toBe(command);
expect(
variant
?.querySelector("button[data-copy-target]")
?.getAttribute("data-copy-target"),
).toBe(codeId);
}
const codeId = `build-cmd-${panelId}`;
expect(panel?.querySelector("code")?.id).toBe(codeId);
expect(panel?.querySelector("code")?.textContent?.trim()).toBe(
expected.command,
);
expect(
panel
?.querySelector("button[data-copy-target]")
?.getAttribute("data-copy-target"),
).toBe(codeId);
expect(
panel?.querySelector("a[data-nb-button]")?.getAttribute("href"),
).toBe(expected.ctaHref);
}
});
15 changes: 15 additions & 0 deletions src/components/landing/Hero.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
import Icon from "@cloudflare/nimbus-docs/components/Icon.astro";
import { LinkButton } from "@/components/ui/link-button";
import CopyPromptButton from "@/components/CopyPromptButton.astro";
import CommandBlock from "./CommandBlock.astro";
---

<section id="hero" class="pb-12 md:pt-6 lg:pb-16">
Expand All @@ -17,6 +19,19 @@ import CopyPromptButton from "@/components/CopyPromptButton.astro";
Get started
</LinkButton>

<LinkButton href="/cf/get-started/" variant="secondary" size="lg">
<Icon name="cf" class="size-4 shrink-0" aria-hidden="true" />
Get started with cf
</LinkButton>

<CopyPromptButton tooltip="Sets up your AI agent for Cloudflare" />
</div>

<CommandBlock
id="hero-cmd-install-cf"
command="npm install -g cf"
showPrompt
rounded
class="mt-5 max-w-[320px]"
/>
</section>
31 changes: 31 additions & 0 deletions src/components/landing/Hero.astro.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { experimental_AstroContainer as AstroContainer } from "astro/container";
import { parse } from "node-html-parser";
import { expect, test } from "vitest";

import Hero from "./Hero.astro";

test("renders cf onboarding CTA and copyable install command without a CLI switcher", async () => {
const container = await AstroContainer.create();
const root = parse(await container.renderToString(Hero));
const section = root.querySelector("#hero");

expect(section).not.toBeNull();
expect(section?.querySelector("[data-nb-cli-toggle]")).toBeNull();
expect(section?.querySelector("[data-nb-cli-variant]")).toBeNull();

const links = section
?.querySelectorAll("a[data-nb-button]")
.map((link) => link.getAttribute("href"));
expect(links).toEqual(["/fundamentals/get-started/", "/cf/get-started/"]);

const codeId = "hero-cmd-install-cf";
expect(section?.querySelector("code")?.id).toBe(codeId);
expect(section?.querySelector("code")?.textContent?.trim()).toBe(
"npm install -g cf",
);
expect(
section
?.querySelector("button[data-copy-target]")
?.getAttribute("data-copy-target"),
).toBe(codeId);
});