Skip to content
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

Og: クエリパラメータにタイトルを渡すときはエスケープする #46

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/api/og/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const font = await fs.readFile(path.join(process.cwd(), "assets", "mplus-2c-medium.ttf"));
return new ImageResponse(
<OgImage title={searchParams.get("title") ?? ""} thumbnail={searchParams.get("thumbnail") ?? undefined} />,
(
<OgImage
title={decodeURIComponent(searchParams.get("title") ?? "")}
thumbnail={searchParams.get("thumbnail") ?? undefined}
/>
),
{
fonts: [
{
Expand Down
2 changes: 1 addition & 1 deletion app/pages/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const generateMetadata = async ({ params }: Props) => {
siteName: siteName,
type: "article",
images: {
url: `${siteUrl}/api/og?title=${data.title}${data.thumbnail?.url !== undefined ? `&thumbnail=${data.thumbnail.url}` : ""}`,
url: `${siteUrl}/api/og?title=${encodeURIComponent(data.title)}${data.thumbnail?.url !== undefined ? `&thumbnail=${data.thumbnail.url}` : ""}`,
width: 1200,
height: 630
}
Expand Down
2 changes: 1 addition & 1 deletion app/preview/pages/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const generateMetadata = async ({ searchParams }: Props) => {
siteName: siteName,
type: "article",
images: {
url: `${siteUrl}/api/og?title=${data.title}${data.thumbnail?.url !== undefined ? `&thumbnail=${data.thumbnail.url}` : ""}`,
url: `${siteUrl}/api/og?title=${encodeURIComponent(data.title)}${data.thumbnail?.url !== undefined ? `&thumbnail=${data.thumbnail.url}` : ""}`,
width: 1200,
height: 630
}
Expand Down
4 changes: 2 additions & 2 deletions components/ArticleShare.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ArticleShare = ({ article, displayMessage }: Props) => {
<div className={styles.elementRoot}>
<ExternalLink
aria-label="X(旧Twitter)にポスト"
href={`https://twitter.com/intent/tweet?url=${url}&text=${title}`}
href={`https://twitter.com/intent/tweet?url=${url}&text=${encodeURIComponent(title)}`}
className={styles.element}
>
<Image src={twitterLogo} alt="X(旧Twitter)" width={24} className={styles.icon} />
Expand All @@ -38,7 +38,7 @@ export const ArticleShare = ({ article, displayMessage }: Props) => {
</ExternalLink>
<ExternalLink
aria-label="はてなブックマークに登録"
href={`https://b.hatena.ne.jp/add?mode=confirm&url=${url}&title=${title}`}
href={`https://b.hatena.ne.jp/add?mode=confirm&url=${url}&title=${encodeURIComponent(title)}`}
className={styles.element}
>
<Image src={hatenabookmarkLogo} alt="はてなブックマーク" width={24} className={styles.icon} />
Expand Down
Loading