Skip to content

Commit b84e86c

Browse files
committed
ogp画像のデザイン変更等
1 parent 1e4d672 commit b84e86c

File tree

8 files changed

+26
-17
lines changed

8 files changed

+26
-17
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# nedew.dev
4-
/tmp_doc
4+
/img
55

66
# dependencies
77
/node_modules

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "node script/generate-json.mjs && node script/generate-ogp.mjs && next dev",
7-
"build": "node script/generate-json.mjs && node script/generate-ogp.mjs && next build",
8-
"start": "next start"
6+
"dev": "node script/generate-json.mjs && next dev",
7+
"build": "node script/generate-json.mjs && next build",
8+
"start": "next start",
9+
"buildogp": "node script/generate-ogp.mjs"
910
},
1011
"dependencies": {
1112
"@mapbox/rehype-prism": "^0.5.0",

public/ogp/13857.png

4.97 KB
Loading

public/ogp/62426.png

4.75 KB
Loading

public/ogp/89546.png

8.76 KB
Loading

script/generate-ogp.mjs

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import canvas from 'canvas'
22
import fs from 'fs'
33
import path from 'path'
4-
// import articles from '../gen/articles.json'
4+
5+
const logColors = {
6+
white: '\u001b[37m',
7+
cyan: '\u001b[36m',
8+
reset: '\u001b[0m',
9+
}
510

611
function getLines(title, maxWidth, ctx) {
712
let lines = []
@@ -24,24 +29,24 @@ function getLines(title, maxWidth, ctx) {
2429
return lines
2530
}
2631

27-
function generateOgpImg(slug, title) {
32+
async function generateOgpImg(slug, title) {
2833
const WIDTH = 1200
2934
const HEIGHT = 630
30-
const FONT_SIZE = 55
35+
const FONT_SIZE = 60
3136
const FONT_FAMILY = '"Noto Sans CJK JP"'
3237
const FONT_TYPE = 'bold'
33-
const TEXT_WIDTH = 900
34-
const FONT_COLOR = '#474747'
35-
const TEXT_MARGIN = 15
38+
const TEXT_WIDTH = 950
39+
const FONT_COLOR = '#262626'
40+
const TEXT_MARGIN = 20
3641
const MAX_LINE = 4
37-
const BACKGROUND_COLOR = 'white'
42+
const BACKGROUND_IMG_PATH = path.join(process.cwd(), 'img/ogp_bg/ogp_bg_4.png')
3843

3944
const canv = canvas.createCanvas(WIDTH, HEIGHT)
4045
const ctx = canv.getContext('2d')
4146

42-
// Background color
43-
ctx.fillStyle = BACKGROUND_COLOR
44-
ctx.fillRect(0, 0, WIDTH, HEIGHT)
47+
// Background image
48+
const bgImage = await canvas.loadImage(BACKGROUND_IMG_PATH)
49+
ctx.drawImage(bgImage, 0, 0, WIDTH, HEIGHT)
4550

4651
ctx.font = FONT_TYPE + ' ' + FONT_SIZE + 'px ' + FONT_FAMILY
4752
ctx.fillStyle = FONT_COLOR
@@ -57,7 +62,9 @@ function generateOgpImg(slug, title) {
5762
// console.log(i + ' - ' + titleLines[i])
5863
const text = titleLines[i].join('')
5964
const lineX = (WIDTH - ctx.measureText(text).width)/2
60-
const lineY = HEIGHT / 2 - FONT_SIZE * (titleLines.length + 1) / 2 + (FONT_SIZE + TEXT_MARGIN) * i
65+
// const lineY = HEIGHT / 2 - FONT_SIZE * (titleLines.length + 1) / 2 + (FONT_SIZE + TEXT_MARGIN) * i
66+
// const lineY = (HEIGHT + 150) / 2 - FONT_SIZE * (titleLines.length + 1) / 2 + (FONT_SIZE + TEXT_MARGIN) * i
67+
const lineY = (HEIGHT + 50) / 2 - FONT_SIZE * (titleLines.length + 1) / 2 + (FONT_SIZE + TEXT_MARGIN) * i
6168
ctx.fillText(text, lineX, lineY)
6269
}
6370

@@ -76,6 +83,7 @@ function main() {
7683
}
7784
generateOgpImg(slug, title)
7885
}
86+
console.log(logColors.cyan + '[script:ogpbuild]' + logColors.white + ' Successful!' + logColors.reset)
7987
}
8088

8189
// run

script/main.mjs

Whitespace-only changes.

styles/_config.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ $wideMarginButtom: .5rem;
88
$widePaddingTop: 2.5rem;
99
// $widePaddingRight: 40px;
1010
// $widePaddingLeft: 40px;
11-
$widePaddingRight: 30px;
12-
$widePaddingLeft: 30px;
11+
$widePaddingRight: 25px;
12+
$widePaddingLeft: 25px;
1313
$widePaddingBottom: 3rem;
1414

1515
$narrowPaddingTop: 1.8rem;

0 commit comments

Comments
 (0)