Skip to content

Commit 95f54c2

Browse files
committed
fix: og title
Signed-off-by: Innei <[email protected]>
1 parent 00a7551 commit 95f54c2

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/app/(app)/og/route.tsx

+16-13
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const HomeOGImage: FC<AggregateRoot> = ({ seo, user: { avatar } }) => {
110110
</div>
111111
)
112112
}
113+
113114
export const GET = async (req: NextRequest) => {
114115
try {
115116
const { searchParams } = req.nextUrl
@@ -167,7 +168,7 @@ export const GET = async (req: NextRequest) => {
167168
break
168169
}
169170
}
170-
const { title, subtitle } = document
171+
const { subtitle, title } = document
171172

172173
const {
173174
user: { avatar },
@@ -196,21 +197,22 @@ export const GET = async (req: NextRequest) => {
196197
}).color
197198

198199
let canShownTitle = ''
199-
let leftContainerWidth = 1200
200+
201+
let leftContainerWidth = 1100
200202
for (let i = 0; i < title.length; i++) {
201203
if (leftContainerWidth < 0) break
202-
// cjk 字符算 67.2 px
204+
// cjk 字符算 64 px
203205
const char = title[i]
204206
// char 不能是 emoji
205207
if ((char >= '\u4e00' && char <= '\u9fa5') || char === ' ') {
206-
leftContainerWidth -= 67.2
208+
leftContainerWidth -= 64
207209
canShownTitle += char
208210
} else if (char >= '\u0000' && char <= '\u00ff') {
209-
// latin 字符算 33.6 px
210-
leftContainerWidth -= 33.6
211+
// latin 字符算 40px
212+
leftContainerWidth -= 40
211213
canShownTitle += char
212214
} else {
213-
leftContainerWidth -= 67.2
215+
leftContainerWidth -= 64
214216
canShownTitle += char
215217
}
216218
}
@@ -226,9 +228,9 @@ export const GET = async (req: NextRequest) => {
226228
background: `linear-gradient(37deg, ${bgAccent} 27.82%, ${bgAccentLight} 79.68%, ${bgAccentUltraLight} 100%)`,
227229

228230
// fontFamily: 'LXGWWenKai',
229-
fontFamily: 'Noto Sans, Inter, "Material Icons"',
231+
fontFamily: 'Inter, Noto Sans, Inter, "Material Icons"',
230232

231-
padding: '5rem',
233+
padding: '50px',
232234
alignItems: 'flex-end',
233235
justifyContent: 'flex-end',
234236
}}
@@ -276,19 +278,20 @@ export const GET = async (req: NextRequest) => {
276278
style={{
277279
color: 'rgba(255, 255, 255, 0.92)',
278280

279-
fontSize: '4.2rem',
281+
fontSize: `${(canShownTitle.length / title.length) * 64}px`,
280282
whiteSpace: 'nowrap',
281283
textOverflow: 'ellipsis',
282284
WebkitLineClamp: 1,
283285
lineClamp: 1,
284286
}}
285287
>
286-
{canShownTitle}
288+
{title}
287289
</h1>
288290
<h2
289291
style={{
290-
color: 'rgba(230, 230, 230, 0.85)',
291-
fontSize: '3rem',
292+
color: 'rgba(255, 255, 255, 0.85)',
293+
fontSize: '38px',
294+
fontWeight: 300,
292295
}}
293296
>
294297
{subtitle}

0 commit comments

Comments
 (0)