Skip to content

Commit b13b700

Browse files
authored
fix(suspensive.org): resolve locale initialization issue (#1311)
# Overview <!-- A clear and concise description of what this pr is about. --> I address an issue where undefined locale URLs defaulted to 'en' in Nextra documentation. I've implemented Nextra's middleware to recognize locale cookies. https://github.com/user-attachments/assets/03a068df-feef-47f4-b505-532fb29da329 ### [AS-IS] - Custom middleware redirecting undefined locales to '/en' ### [TO-BE] - Use Nextra's built-in middleware - Exclude 'img' directory in matcher configuration - Prevents unnecessary middleware processing for image files, aligning with Nextra's example configuration (see [Nextra PR #3439](https://github.com/shuding/nextra/pull/3439/files#diff-e986406290c383f5b481ce7bc0136f142b96083e0807190d530561eea83bfc70R5-R7) `icon.svg`) ### Issue Nextra styles may appear broken in development. See [Issue #3357](shuding/nextra#3357). Could you please confirm if you're experiencing this as well? <img width="1797" alt="스크린샷 2024-10-13 오후 8 26 02" src="https://github.com/user-attachments/assets/88dd507a-81ab-4312-abce-feea2a714495"> ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
1 parent 920c598 commit b13b700

File tree

3 files changed

+43
-51
lines changed

3 files changed

+43
-51
lines changed

docs/suspensive.org/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"d3": "^7.9.0",
3131
"framer-motion": "^11.11.8",
3232
"next": "catalog:",
33-
"nextra": "^3.0.8",
34-
"nextra-theme-docs": "^3.0.8",
33+
"nextra": "^3.0.11",
34+
"nextra-theme-docs": "^3.0.11",
3535
"react": "catalog:react18",
3636
"react-dom": "catalog:react18",
3737
"remark-sandpack": "^0.0.5",

docs/suspensive.org/src/middleware.ts

+3-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
1-
import { type NextRequest, NextResponse } from 'next/server'
2-
3-
const PUBLIC_FILE = /\.(.*)$/
4-
5-
export function middleware(req: NextRequest) {
6-
if (
7-
req.nextUrl.pathname.startsWith('/_next') ||
8-
req.nextUrl.pathname.includes('/api/') ||
9-
PUBLIC_FILE.test(req.nextUrl.pathname)
10-
) {
11-
return
12-
}
13-
14-
if (
15-
!(
16-
req.nextUrl.pathname.startsWith('/en') ||
17-
req.nextUrl.pathname.startsWith('/ko')
18-
)
19-
) {
20-
return NextResponse.redirect(
21-
new URL(`/en${req.nextUrl.pathname}${req.nextUrl.search}`, req.url)
22-
)
23-
}
24-
}
1+
export { middleware } from 'nextra/locales'
252

263
export const config = {
274
matcher: [
@@ -31,7 +8,8 @@ export const config = {
318
* - _next/static (static files)
329
* - _next/image (image optimization files)
3310
* - favicon.ico (favicon file)
11+
* - img (image files)
3412
*/
35-
'/((?!api|_next/static|_next/image|favicon.ico).*)',
13+
'/((?!api|_next/static|_next/image|favicon.ico|img).*)',
3614
],
3715
}

pnpm-lock.yaml

+38-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)