-
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 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
5 changes: 5 additions & 0 deletions
5
examples/framesjs-starter/app/examples/new-api-custom-font/frames-alt/frames.ts
This file contains 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,5 @@ | ||
import { createFrames } from "frames.js/next"; | ||
|
||
export const frames = createFrames({ | ||
basePath: "/examples/new-api-custom-font", | ||
}); |
75 changes: 75 additions & 0 deletions
75
examples/framesjs-starter/app/examples/new-api-custom-font/frames-alt/route.tsx
This file contains 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,75 @@ | ||
/* eslint-disable react/jsx-key */ | ||
import { Button } from "frames.js/next"; | ||
import { frames } from "./frames"; | ||
import * as fs from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
|
||
export const runtime = "nodejs"; | ||
|
||
const interRegularFont = fs.readFile( | ||
path.join(path.resolve(process.cwd(), "public"), "Inter-Regular.ttf") | ||
); | ||
|
||
const interBoldFont = fs.readFile( | ||
path.join(path.resolve(process.cwd(), "public"), "Inter-Bold.ttf") | ||
); | ||
|
||
const firaScriptFont = fs.readFile( | ||
path.join( | ||
path.resolve(process.cwd(), "public"), | ||
"FiraCodeiScript-Regular.ttf" | ||
) | ||
); | ||
|
||
const handleRequest = frames(async (ctx) => { | ||
const [interRegularFontData, interBoldFontData, firaScriptData] = | ||
await Promise.all([interRegularFont, interBoldFont, firaScriptFont]); | ||
|
||
return { | ||
buttons: [ | ||
<Button target={"/frames"} action="post"> | ||
Edge Fn | ||
</Button>, | ||
<Button action="post" target={"/frames-alt"}> | ||
Node.js | ||
</Button>, | ||
], | ||
image: ( | ||
<span tw="flex flex-col"> | ||
<div>Node.js example custom fonts</div> | ||
<div style={{ marginTop: 40, fontWeight: 400 }}>Regular Inter Font</div> | ||
<div style={{ marginTop: 40, fontWeight: 700 }}>Bold Inter Font</div> | ||
<div | ||
style={{ | ||
fontFamily: "'Fira Code', monospace", | ||
marginTop: 40, | ||
}} | ||
> | ||
Fira | ||
</div> | ||
</span> | ||
), | ||
imageOptions: { | ||
fonts: [ | ||
{ | ||
name: "Inter", | ||
data: interRegularFontData, | ||
weight: 400, | ||
}, | ||
{ | ||
name: "Inter", | ||
data: interBoldFontData, | ||
weight: 700, | ||
}, | ||
{ | ||
name: "Fira Code", | ||
data: firaScriptData, | ||
weight: 700, | ||
}, | ||
], | ||
}, | ||
}; | ||
}); | ||
|
||
export const GET = handleRequest; | ||
export const POST = handleRequest; |
5 changes: 5 additions & 0 deletions
5
examples/framesjs-starter/app/examples/new-api-custom-font/frames/frames.ts
This file contains 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,5 @@ | ||
import { createFrames } from "frames.js/next"; | ||
|
||
export const frames = createFrames({ | ||
basePath: "/examples/new-api-custom-font", | ||
}); |
70 changes: 70 additions & 0 deletions
70
examples/framesjs-starter/app/examples/new-api-custom-font/frames/route.tsx
This file contains 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,70 @@ | ||
/* eslint-disable react/jsx-key */ | ||
import { Button } from "frames.js/next"; | ||
import { frames } from "./frames"; | ||
|
||
// without this line, this type of importing fonts doesn't work for some reason | ||
export const runtime = "edge"; | ||
|
||
const interRegularFont = fetch( | ||
new URL("/public/Inter-Regular.ttf", import.meta.url) | ||
).then((res) => res.arrayBuffer()); | ||
const interBoldFont = fetch( | ||
new URL("/public/Inter-Bold.ttf", import.meta.url) | ||
).then((res) => res.arrayBuffer()); | ||
const firaScriptFont = fetch( | ||
new URL("/public/FiraCodeiScript-Regular.ttf", import.meta.url) | ||
).then((res) => res.arrayBuffer()); | ||
|
||
const handleRequest = frames(async (ctx) => { | ||
const [interRegularFontData, interBoldFontData, firaScriptFontData] = | ||
await Promise.all([interRegularFont, interBoldFont, firaScriptFont]); | ||
|
||
return { | ||
image: ( | ||
<span tw="flex flex-col"> | ||
<div>Edge functions example custom fonts</div> | ||
<div style={{ marginTop: 40, fontWeight: 400 }}>Regular Inter Font</div> | ||
<div style={{ marginTop: 40, fontWeight: 700 }}>Bold Inter Font</div> | ||
<div | ||
style={{ | ||
fontFamily: "'Fira Code', monospace", | ||
marginTop: 40, | ||
}} | ||
> | ||
Fira | ||
</div> | ||
</span> | ||
), | ||
buttons: [ | ||
<Button target={"/frames"} action="post"> | ||
Edge Fn | ||
</Button>, | ||
<Button action="post" target={"/frames-alt"}> | ||
Node.js | ||
</Button>, | ||
], | ||
textInput: "Type something!", | ||
imageOptions: { | ||
fonts: [ | ||
{ | ||
name: "Inter", | ||
data: interRegularFontData, | ||
weight: 400, | ||
}, | ||
{ | ||
name: "Inter", | ||
data: interBoldFontData, | ||
weight: 700, | ||
}, | ||
{ | ||
name: "Fira Code", | ||
data: firaScriptFontData, | ||
weight: 700, | ||
}, | ||
], | ||
}, | ||
}; | ||
}); | ||
|
||
export const GET = handleRequest; | ||
export const POST = handleRequest; |
33 changes: 33 additions & 0 deletions
33
examples/framesjs-starter/app/examples/new-api-custom-font/page.tsx
This file contains 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,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/frames"); | ||
|
||
return ( | ||
<div> | ||
New api example.{" "} | ||
<Link href={createDebugUrl(url)} className="underline"> | ||
Debug | ||
</Link> | ||
</div> | ||
); | ||
} |
13 changes: 13 additions & 0 deletions
13
examples/framesjs-starter/app/examples/new-api-custom-middleware/frames/frames.ts
This file contains 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,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 | ||
], | ||
}); |
21 changes: 21 additions & 0 deletions
21
examples/framesjs-starter/app/examples/new-api-custom-middleware/frames/next/route.tsx
This file contains 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,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; |
24 changes: 24 additions & 0 deletions
24
examples/framesjs-starter/app/examples/new-api-custom-middleware/frames/route.tsx
This file contains 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,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; |
33 changes: 33 additions & 0 deletions
33
examples/framesjs-starter/app/examples/new-api-custom-middleware/page.tsx
This file contains 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,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> | ||
); | ||
} |
This file contains 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
Binary file not shown.
Binary file not shown.
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.
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