Skip to content
This repository has been archived by the owner on May 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #41 from abekoh/ogp
Browse files Browse the repository at this point in the history
OGP画像生成できなくなった問題修正
  • Loading branch information
abekoh authored Nov 20, 2021
2 parents f14aed7 + 1991771 commit 3eedc7a
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 81 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ module.exports = {
},
];
},
outputFileTracing: true,
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"canvas": "^2.7.0",
"jsonld": "^5.2.0",
"moment": "^2.29.1",
"next": "11.1.1",
"next": "12.0.4",
"prismjs": "^1.23.0",
"react": "17.0.1",
"react-dom": "17.0.1",
Expand Down
6 changes: 4 additions & 2 deletions src/pages/api/ogp-images/[postid]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const generateOgpImage = async (
// setup
const canvas = createCanvas(width, height);
const ctx = canvas.getContext('2d');
registerFont(path.resolve('./fonts/NotoSansJP-Medium.otf'), {
registerFont(path.resolve(process.cwd(), 'assets', 'NotoSansJP-Medium.otf'), {
family: 'Noto Sans JP',
});
const fontFamilyName = "'Noto Sans JP'";
Expand All @@ -51,7 +51,9 @@ const generateOgpImage = async (
);

// logo
const logoImage = await loadImage(path.resolve('./public/logo.png'));
const logoImage = await loadImage(
path.resolve(process.cwd(), 'assets', 'logo.png'),
);
ctx.drawImage(
logoImage,
width - padding - margin - 380,
Expand Down
7 changes: 7 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"functions": {
"pages/api/ogp-images/[postid]/index.ts": {
"includeFiles": "assets/**"
}
}
}
212 changes: 134 additions & 78 deletions yarn.lock

Large diffs are not rendered by default.

1 comment on commit 3eedc7a

@vercel
Copy link

@vercel vercel bot commented on 3eedc7a Nov 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.