-
Notifications
You must be signed in to change notification settings - Fork 100
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
Chore/docs and example fonts #232
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createFrames } from "frames.js/next"; | ||
|
||
export const frames = createFrames({ | ||
basePath: "/examples/new-api-custom-font/frames", | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-disable react/jsx-key */ | ||
import { frames } from "./frames"; | ||
|
||
// without this line, this type of importing fonts doesn't work for some reason | ||
export const runtime = "edge"; | ||
|
||
const regularFont = fetch( | ||
new URL("/public/Inter-Regular.ttf", import.meta.url) | ||
).then((res) => res.arrayBuffer()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It took me several attempts to figure this out, but for the nodejs runtime deployed to Vercel, it seems like the most reliable way was to use a combination of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dang thats tricky - thanks for following up. Will incorporate |
||
|
||
const boldFont = fetch(new URL("/public/Inter-Bold.ttf", import.meta.url)).then( | ||
(res) => res.arrayBuffer() | ||
); | ||
|
||
const handleRequest = frames(async (ctx) => { | ||
const [regularFontData, boldFontData] = await Promise.all([ | ||
regularFont, | ||
boldFont, | ||
]); | ||
|
||
return { | ||
image: ( | ||
<span> | ||
<div style={{ marginTop: 40, fontWeight: 400 }}>Regular Inter Font</div> | ||
<div style={{ marginTop: 40, fontWeight: 700 }}>Bold Inter Font</div> | ||
</span> | ||
), | ||
textInput: "Type something!", | ||
imageOptions: { | ||
fonts: [ | ||
{ | ||
name: "Inter", | ||
data: regularFontData, | ||
weight: 400, | ||
}, | ||
{ | ||
name: "Inter", | ||
data: boldFontData, | ||
weight: 700, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typos: should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they also need to be awaited There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. think you're missing line 16 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops missed that sorry |
||
}, | ||
], | ||
}, | ||
}; | ||
}); | ||
|
||
export const GET = handleRequest; | ||
export const POST = handleRequest; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Link from "next/link"; | ||
import { currentURL, vercelURL } from "../../utils"; | ||
import { createDebugUrl } from "../../debug"; | ||
import type { Metadata } from "next"; | ||
import { fetchMetadata } from "frames.js/next"; | ||
|
||
export async function generateMetadata(): Promise<Metadata> { | ||
return { | ||
title: "New api example", | ||
description: "This is a new api example", | ||
other: { | ||
...(await fetchMetadata( | ||
new URL( | ||
"/examples/new-api-custom-font/frames", | ||
vercelURL() || "http://localhost:3000" | ||
) | ||
)), | ||
}, | ||
}; | ||
} | ||
|
||
export default async function Home() { | ||
const url = currentURL("/examples/new-api-custom-font"); | ||
|
||
return ( | ||
<div> | ||
New api example.{" "} | ||
<Link href={createDebugUrl(url)} className="underline"> | ||
Debug | ||
</Link> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createFrames } from "frames.js/next"; | ||
|
||
export const frames = createFrames({ | ||
basePath: "/examples/new-api-custom-middleware/frames", | ||
middleware: [ | ||
async (ctx, next) => { | ||
const body = await ctx.request.clone().json(); | ||
|
||
return next({ body }); | ||
}, | ||
// the request body will now be available via ctx.body in your handler | ||
], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* eslint-disable react/jsx-key */ | ||
import { Button } from "frames.js/next"; | ||
import { frames } from "../frames"; | ||
|
||
const handleRequest = frames(async (ctx) => { | ||
return { | ||
image: ( | ||
<span> | ||
This is next frame and you clicked button:{" "} | ||
{ctx.pressedButton ? "✅" : "❌"} | ||
</span> | ||
), | ||
buttons: [ | ||
<Button action="post" target="/"> | ||
Previous frame | ||
</Button>, | ||
], | ||
}; | ||
}); | ||
|
||
export const POST = handleRequest; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* eslint-disable react/jsx-key */ | ||
import { Button } from "frames.js/next"; | ||
import { frames } from "./frames"; | ||
|
||
const handleRequest = frames(async (ctx) => { | ||
return { | ||
image: ( | ||
<span> | ||
Hello there: {ctx.pressedButton ? "✅" : "❌"} | ||
{ctx.message?.inputText ? `, Typed: ${ctx.message?.inputText}` : ""} | ||
</span> | ||
), | ||
buttons: [ | ||
<Button action="post">Click me</Button>, | ||
<Button action="post" target="/next"> | ||
Next frame | ||
</Button>, | ||
], | ||
textInput: "Type something!", | ||
}; | ||
}); | ||
|
||
export const GET = handleRequest; | ||
export const POST = handleRequest; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Link from "next/link"; | ||
import { currentURL, vercelURL } from "../../utils"; | ||
import { createDebugUrl } from "../../debug"; | ||
import type { Metadata } from "next"; | ||
import { fetchMetadata } from "frames.js/next"; | ||
|
||
export async function generateMetadata(): Promise<Metadata> { | ||
return { | ||
title: "New api example", | ||
description: "This is a new api example", | ||
other: { | ||
...(await fetchMetadata( | ||
new URL( | ||
"/examples/new-api-custom-middleware/frames", | ||
vercelURL() || "http://localhost:3000" | ||
) | ||
)), | ||
}, | ||
}; | ||
} | ||
|
||
export default async function Home() { | ||
const url = currentURL("/examples/new-api-custom-middleware"); | ||
|
||
return ( | ||
<div> | ||
New api example.{" "} | ||
<Link href={createDebugUrl(url)} className="underline"> | ||
Debug | ||
</Link> | ||
</div> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we not just pass a clone of the request to each middleware?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was thinking the same - not sure what the overhead is or if there's any downside