Skip to content

Commit

Permalink
og api & component
Browse files Browse the repository at this point in the history
  • Loading branch information
brklntmhwk committed Mar 7, 2024
1 parent 5fbc993 commit 215f033
Show file tree
Hide file tree
Showing 4 changed files with 468 additions and 6 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"preview": "astro preview",
"sync": "astro sync",
"astro": "npx astro",
"format": "prettier --write './src/**/*.{js,ts,json,astro}'",
"format": "prettier --write './src/**/*.{js,ts,mjs,json,astro}'",
"prepare": "husky"
},
"dependencies": {
Expand Down Expand Up @@ -51,7 +51,10 @@
"rehype-pretty-code": "0.13.0",
"rehype-slug": "6.0.0",
"remark-gfm": "4.0.0",
"remark-math": "6.0.0"
"remark-math": "6.0.0",
"satori": "^0.10.13",
"satori-html": "^0.3.2",
"sharp": "^0.33.2"
},
"packageManager": "yarn@1.22.15",
"engines": {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Svg/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type Props = {
const svgGetter = (iconName: string) => {
const filepath = `./icons/${iconName}.svg`
const files = import.meta.glob<string>('./icons/**/*.svg', {
as: 'raw',
query: '?raw',
import: 'default',
eager: true,
})
Expand Down
31 changes: 31 additions & 0 deletions src/pages/og/[type]/[slug].png.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { APIRoute, APIContext } from 'astro'
import { getCollection } from 'astro:content'
// import { readFileSync } from 'fs'
// import satori from 'satori'
// import { html } from 'satori-html'

const entries = await getCollection('blog')
const pages = await getCollection('page')
const articles = [...entries, ...pages]

export const GET: APIRoute = async ({ params }: APIContext) => {
const res = new Response('OG Image Not found', { status: 404 })
const { type, slug } = params
if (type === 'article') {
const article = articles.find((a) => `${a.collection}/${a.slug}` === slug)
if (article) {
// const isArticle = article.collection === "blog"
// const img =
}
}

return res
}

export const getStaticPaths = async () => {
const ogs = articles.map((a) => ({
params: { type: 'article', slug: `${a.collection}/${a.slug}` },
}))

return ogs
}
Loading

0 comments on commit 215f033

Please sign in to comment.