Repository navigation
feat(site): add public Compute template directory #8128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1054200
feat(site): add public Compute template directory
AmanVarshney01 863f996
fix(site): harden template directory
AmanVarshney01 efdae9f
fix(site): distinguish templates navigation item
AmanVarshney01 e7825e8
fix(site): center templates badge label
AmanVarshney01 e07f5d3
fix(site): simplify templates directory
AmanVarshney01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| import { createPageMetadata } from "@/lib/page-metadata"; | ||
| import { Button, Card } from "@prisma/eclipse"; | ||
| import { z } from "zod"; | ||
|
|
||
| const TEMPLATE_MANIFEST_URL = | ||
| "https://raw.githubusercontent.com/prisma/prisma-examples/latest/compute/templates.json"; | ||
|
|
||
| const templateManifestSchema = z.object({ | ||
| version: z.literal(1), | ||
| templates: z.array( | ||
| z.object({ | ||
| id: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/), | ||
| name: z.string().trim().min(1), | ||
| description: z.string().trim().min(1), | ||
| path: z.string().regex(/^compute\/[a-z0-9]+(?:[/-][a-z0-9]+)*$/), | ||
| }), | ||
| ), | ||
| }); | ||
|
|
||
| export const metadata = createPageMetadata({ | ||
| title: "Prisma Compute templates", | ||
| description: | ||
| "Browse open-source TypeScript starters and deploy one with Prisma Postgres and Prisma Compute.", | ||
| path: "/templates", | ||
| }); | ||
|
|
||
| async function getTemplates() { | ||
| try { | ||
| const response = await fetch(TEMPLATE_MANIFEST_URL, { | ||
| next: { revalidate: 300 }, | ||
| signal: AbortSignal.timeout(10_000), | ||
| }); | ||
| if (!response.ok) return []; | ||
|
|
||
| const result = templateManifestSchema.safeParse(await response.json()); | ||
| return result.success ? result.data.templates : []; | ||
| } catch { | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| export default async function TemplatesPage() { | ||
| const templates = await getTemplates(); | ||
|
|
||
| return ( | ||
| <main className="relative -mt-24 flex-1 overflow-hidden bg-background-default text-foreground-neutral"> | ||
| <div | ||
| className="pointer-events-none absolute inset-x-0 top-0 h-[720px] bg-[radial-gradient(circle_at_50%_0%,var(--color-background-ppg-strong),transparent_65%)] opacity-50" | ||
| aria-hidden | ||
| /> | ||
|
|
||
| <section className="relative px-4 pb-12 pt-48 md:pb-16 md:pt-56"> | ||
| <div className="mx-auto flex w-full max-w-[800px] flex-col items-center gap-4 text-center"> | ||
| <h1 className="m-0 max-w-[760px] text-pretty font-sans-display text-4xl font-bold stretch-display sm:text-5xl md:text-6xl"> | ||
| Start from a template. | ||
| </h1> | ||
| <p className="m-0 max-w-[660px] text-pretty text-lg leading-8 text-foreground-neutral-weak md:text-xl"> | ||
| Review the code, then deploy it with Prisma Postgres and Prisma Compute. | ||
| </p> | ||
| </div> | ||
| </section> | ||
|
|
||
| <section className="relative px-4 pb-20 md:pb-28"> | ||
| <div className="mx-auto w-full max-w-[1184px]"> | ||
| {templates.length > 0 ? ( | ||
| <div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"> | ||
| {templates.map((template) => { | ||
| const deployUrl = new URL(`/templates/${template.id}`, "https://console.prisma.io"); | ||
| deployUrl.searchParams.set("utm_source", "website"); | ||
| deployUrl.searchParams.set("utm_medium", "templates"); | ||
|
|
||
| return ( | ||
| <Card | ||
| key={template.id} | ||
| className="min-h-[280px] justify-between gap-8 overflow-hidden border-stroke-ppg/30 bg-[linear-gradient(180deg,var(--color-background-default)_0%,var(--color-background-ppg)_180%)] p-6" | ||
| > | ||
| <div className="flex flex-col gap-3"> | ||
| <h2 className="m-0 font-sans-display text-2xl font-bold stretch-display"> | ||
| {template.name} | ||
| </h2> | ||
| <p className="m-0 text-sm leading-6 text-foreground-neutral-weak"> | ||
| {template.description} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div className="flex flex-col gap-3 sm:flex-row lg:flex-col xl:flex-row"> | ||
| <Button | ||
| asChild | ||
| variant="ppg" | ||
| size="xl" | ||
| className="w-full sm:flex-1 lg:flex-none xl:flex-1" | ||
| > | ||
| <a | ||
| href={deployUrl.toString()} | ||
| aria-label={`Use the ${template.name} template`} | ||
| > | ||
| Use template | ||
| <i className="fa-regular fa-arrow-right" aria-hidden /> | ||
| </a> | ||
| </Button> | ||
| <Button asChild variant="default" size="xl"> | ||
| <a | ||
| href={`https://github.com/prisma/prisma-examples/tree/latest/${template.path}`} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| aria-label={`View the ${template.name} source`} | ||
| > | ||
| View source | ||
| <i className="fa-regular fa-arrow-up-right" aria-hidden /> | ||
| </a> | ||
| </Button> | ||
| </div> | ||
| </Card> | ||
| ); | ||
| })} | ||
| </div> | ||
| ) : ( | ||
| <Card className="items-center gap-4 border-dashed px-6 py-12 text-center"> | ||
| <span className="flex size-element-3xl items-center justify-center rounded-square bg-background-neutral text-foreground-neutral-weak"> | ||
| <i className="fa-regular fa-grid-2" aria-hidden /> | ||
| </span> | ||
| <h3 className="m-0 font-sans-display text-xl font-bold">Templates are unavailable</h3> | ||
| <p className="m-0 max-w-[480px] text-sm text-foreground-neutral-weak"> | ||
| We could not load the template directory. Please try again in a few minutes. | ||
| </p> | ||
| </Card> | ||
| )} | ||
| </div> | ||
| </section> | ||
| </main> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.