Skip to content

Commit

Permalink
fix: use cache with ogimage
Browse files Browse the repository at this point in the history
  • Loading branch information
sunadoi committed Nov 30, 2024
1 parent 0f4e203 commit 655bdf3
Show file tree
Hide file tree
Showing 52 changed files with 11 additions and 2 deletions.
Binary file added app/public/ogimage/browser-rendering.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/cache-strategy-batch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/errors-as.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/eslint-flat-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/eslint-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/eslint-with-prettier.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/firebase-multiple-hosting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/firebase-react-suspense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/generate-ci.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/git-rebase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/github-merge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/go-ch-batch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/go-fmt-stringer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/go-json-tag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/go-sql-package.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/go-test-parallel-flaky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/go-text-template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/honox-blog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/js-date-tz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/next-link-legacybehavior.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/nextjs-standalone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/ogimage/node-duplex-stream.png
Binary file added app/public/ogimage/node-pdf-to-jpeg.png
Binary file added app/public/ogimage/npm-library-operation.png
Binary file added app/public/ogimage/npm-library-settings.png
Binary file added app/public/ogimage/object-difinition.png
Binary file added app/public/ogimage/operation-log.png
Binary file added app/public/ogimage/parquet_performance.png
Binary file added app/public/ogimage/react-v17-update.png
Binary file added app/public/ogimage/react18-strict-mode.png
Binary file added app/public/ogimage/renovate-settings.png
Binary file added app/public/ogimage/s3-delete-lifecycle.png
Binary file added app/public/ogimage/svelte-diff.png
Binary file added app/public/ogimage/swr-render-as-you-fetch.png
Binary file added app/public/ogimage/trap-command.png
Binary file added app/public/ogimage/ts-exclude-key.png
Binary file added app/public/ogimage/ts-function-overload.png
Binary file added app/public/ogimage/tuple-type-check.png
Binary file added app/public/ogimage/type-predicate.png
Binary file added app/public/ogimage/unix-domain-socket.png
Binary file added app/public/ogimage/virtual-dom.png
Binary file added app/public/ogimage/vitest-firebase-emulators.png
Binary file added app/public/ogimage/vitest-spyon.png
Binary file added app/public/ogimage/webpack-to-vite.png
13 changes: 11 additions & 2 deletions app/routes/ogimage/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync } from "node:fs"
import { readFileSync, writeFileSync, existsSync } from "node:fs"
import { Resvg } from "@resvg/resvg-js"
import { ssgParams } from "hono/ssg"
import { createRoute } from "honox/factory"
Expand All @@ -7,7 +7,10 @@ import { getArticle, getArticles } from "../../functions/articles"

export default createRoute(
ssgParams(() =>
getArticles().articles.map((article) => ({ slug: article.slug })),
// OGP画像が作成されてない場合のみ作成する。更新する場合は作成済みのものを削除する必要あり
getArticles().articles
.filter(article => !existsSync(getOGPPath(article.slug)))
.map((article) => ({ slug: article.slug }))
),
async (c) => {
const slug = c.req.param("slug")
Expand Down Expand Up @@ -73,12 +76,18 @@ export default createRoute(
)

const body = new Resvg(svg).render().asPng()
const ogpPath = getOGPPath(slug)
writeFileSync(ogpPath, body)

c.header("Content-Type", "image/png")
return c.body(body)
},
)

const getOGPPath = (slug: string) => {
return new URL(`../../public/ogimage/${slug}.png`, import.meta.url)
}

const loadGoogleFont = async ({
family,
weight,
Expand Down

0 comments on commit 655bdf3

Please sign in to comment.