-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from neg4n/react-template
Create ability to provide React template
- Loading branch information
Showing
9 changed files
with
237 additions
and
34 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { withOGImage } from 'next-api-og-image' | ||
import { interRegular } from '../../fonts/inter' | ||
|
||
const style = ` | ||
@font-face { | ||
font-family: 'Inter'; | ||
font-style: normal; | ||
font-weight: normal; | ||
src: url(data:font/woff2;charset=utf-8;base64,${interRegular}) format('woff2'); | ||
} | ||
body { | ||
font-family: 'Inter', sans-serif; | ||
} | ||
.container { | ||
width: 100vw; | ||
height: 100vh; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
` | ||
|
||
export default withOGImage<'testQueryParam'>({ | ||
template: { | ||
react: async ({ testQueryParam }) => { | ||
const value = await someLongRunningValueGetter() | ||
return ( | ||
<html> | ||
<head> | ||
<style dangerouslySetInnerHTML={{ __html: style }} /> | ||
</head> | ||
<body> | ||
<div className="container"> | ||
<h1>{testQueryParam}</h1> | ||
<h2>{value}</h2> | ||
</div> | ||
</body> | ||
</html> | ||
) | ||
}, | ||
}, | ||
dev: { | ||
inspectHtml: false, | ||
}, | ||
}) | ||
|
||
function someLongRunningValueGetter() { | ||
return new Promise((resolve: (value: string) => void) => { | ||
setTimeout(() => { | ||
resolve("Value in setTimeout's (500ms) callback") | ||
}, 500) | ||
}) | ||
} |
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,7 @@ | ||
import { withOGImage } from 'next-api-og-image' | ||
|
||
export default withOGImage({ | ||
template: { | ||
react: ({ myQueryParam }) => <div>🔥 {myQueryParam}</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { withOGImage } from 'next-api-og-image' | ||
|
||
export default withOGImage({ | ||
html: ({ myQueryParam }) => ` | ||
<html> | ||
<head> | ||
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<h1 class="flex flex-row text-6xl text-blue-300">${myQueryParam}<span>💻</span></h1> | ||
</body> | ||
</html> | ||
`, | ||
template: { | ||
html: ({ myQueryParam }) => ` | ||
<html> | ||
<head> | ||
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<h1 class="flex flex-row text-6xl text-blue-300">${myQueryParam}<span>💻</span></h1> | ||
</body> | ||
</html> | ||
`, | ||
}, | ||
}) |
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 |
---|---|---|
@@ -1,13 +1,15 @@ | ||
import { withOGImage } from 'next-api-og-image' | ||
|
||
export default withOGImage<'testQueryParam'>({ | ||
html: async ({ testQueryParam }) => { | ||
return ` | ||
<html> | ||
<body> | ||
<h1>${testQueryParam}</h1> | ||
</body> | ||
</html> | ||
` | ||
template: { | ||
html: async ({ testQueryParam }) => { | ||
return ` | ||
<html> | ||
<body> | ||
<h1>${testQueryParam}</h1> | ||
</body> | ||
</html> | ||
` | ||
}, | ||
}, | ||
}) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { withOGImage } from 'next-api-og-image' | ||
|
||
export default withOGImage({ | ||
html: ({ myQueryParam }) => `<h1>${myQueryParam}</h1>`, | ||
template: { | ||
react: ({ myQueryParam }) => <div>🔥 {myQueryParam}</div>, | ||
}, | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.