Comments (8)
I mean I'd like if it's possible to have something like og-image.vercel.app in development mode as I want to integrate this library into my blog but would love to see how the templates look so I can create multiple dynamic ones.
Sure! The development mode HTML inspect seems reasonable, will create separate issue for it and implement it today
from next-api-og-image.
Hey! Thanks for the feedback 😊
Using Tailwind in next-api-og-image
would look like that
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>
`,
})
I've tested it and it seems to work as expected :0 Request to http://localhost:3000/api/basic-tailwind?myQueryParam=im%20using%20Tailwind!!
looks like this
I guess this should be in README and example/
Next.js project on this repository. I've added hacktoberfest
badge if you want to add this 😎
Thanks for the suggestion! 🤟🏻
from next-api-og-image.
Hmm, I doubt the separate html
templates along with fs
would work. Im thinking about 2 reasons why:
- Placement of query params in the template -
next-api-og-image
is stupid and only passes the query forward tohtml
function in configuration. The closest solution would be creating something likemy-template.html.js
withthen passed to the API Route using withOGImageexport default function myTemplate({ superCoolQueryParam }) { return `<h1>${superCoolQueryParam}</h1>` }
import { withOGImage } from 'next-api-og-image' import myTemplate from './my-template.html' export default withOGImage({ html: myTemplate })
- Most likely, there will be same issues as loading custom fonts while loading such things by
fs
module. Although it works on plain vercel serverless functions - I believe it does not in Next.js and i think its caused by invalid paths caused by bundling the source to .next directory.
from next-api-og-image.
I mean I'd like if it's possible to have something like og-image.vercel.app in development mode as I want to integrate this library into my blog but would love to see how the templates look so I can create multiple dynamic ones.
Sure! The development mode HTML inspect seems reasonable, will create separate issue for it and implement it today
Hey @deadcoder0904! This is now implemented (#4) (#5) 🎉
Let me know if there is anything that you would to suggest in this topic or eventually
feel free to close the issue if the subject got exhausted.
Cheers 🤗 Igor
from next-api-og-image.
Thanks @neg4n, great work. I'll open a new one if I have any or re-open this one if it's related.
from next-api-og-image.
Knew it could be done with link
.
I'd also probably like to add separate html
file templates which are not hardcoded, probably using fs
module. Would that work too?
from next-api-og-image.
The 1st solution is good. Is there any way to preview the HTML we'll be displaying then so we can get live feedback like React's HMR?
I mean I'd like if it's possible to have something like https://og-image.vercel.app/ in development mode as I want to integrate this library into my blog but would love to see how the templates look so I can create multiple dynamic ones.
Right now, it feels like I'd have to see the screenshot or create another project that I work on HTML & then copy-paste the template into this which is bad DX :(
from next-api-og-image.
@neg4n I had 2 problems. First JIT mode wasn't working so I had to add the following script
just below body
:
<script src="https://unpkg.com/tailwindcss-jit-cdn"></script>
Then I had an issue where I have to use custom font. The problem is I've given them custom names using tailwind.config.js
so I probably have to repeat that too using baseCSS
:
const baseCSS = `
.font-alegreya {
font-family: Alegreya;
}
.font-jetbrains {
font-family: 'JetBrains Mono';
}
`
And then put it in my HTML:
return `
<html>
<head>
<meta charset="utf-8" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="true" />
<link
href="https://fonts.googleapis.com/css2?family=Alegreya:wght@800&display=swap"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap"
rel="stylesheet"
/>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
<style>${baseCSS}</style>
</head>
<body>
${body}
</body>
<script src="https://unpkg.com/tailwindcss-jit-cdn"></script>
</html>
`
This was necessary to do since my React.js OGImage component uses JIT mode & custom fonts :)
Not sure if there is a way to improve this using tailwind.config.js
somehow but yeah this can be useful to someone in future using Tailwind :)
from next-api-og-image.
Related Issues (20)
- Contributing guidelines HOT 1
- [Bug] Could not find expected browser (chrome) locally after `next start` HOT 13
- Vercel: Exceeding size limits (50mb) for Serverless Function api/og HOT 3
- Change image resolution / page viewport HOT 3
- Updates on this library? width and height not working HOT 2
- Suggestion: move chrome-aws-lambda to peer dependency HOT 6
- Suggestion: remove patch-package from dependencies HOT 1
- Simplify source code
- using react templates outputs a string, not an image HOT 1
- Failed to launch the browser process! HOT 5
- Error: Protocol error (Page.captureScreenshot): Target closed.
- Wait for webfont load? HOT 2
- Failed to launch the browser process HOT 1
- Error: Could not find expected browser (chrome) locally. Run `npm install` to download the correct Chromium revision (901912). HOT 8
- Failed to launch browser process HOT 3
- Add option to override default chrome executable and arguments HOT 2
- New @vercel/og library HOT 1
- Replace chrome-aws-lambda with @sparticuz/chromium because of lacking node 16 support HOT 2
- Error 500 & Content Blocker Issue
- Failed to launch browser process
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next-api-og-image.