Skip to content

Commit

Permalink
fix(suspensive.org): resolve locale initialization issue (#1311)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
kangju2000 authored Oct 13, 2024
1 parent 920c598 commit b13b700
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 51 deletions.
4 changes: 2 additions & 2 deletions docs/suspensive.org/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"d3": "^7.9.0",
"framer-motion": "^11.11.8",
"next": "catalog:",
"nextra": "^3.0.8",
"nextra-theme-docs": "^3.0.8",
"nextra": "^3.0.11",
"nextra-theme-docs": "^3.0.11",
"react": "catalog:react18",
"react-dom": "catalog:react18",
"remark-sandpack": "^0.0.5",
Expand Down
28 changes: 3 additions & 25 deletions docs/suspensive.org/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
import { type NextRequest, NextResponse } from 'next/server'

const PUBLIC_FILE = /\.(.*)$/

export function middleware(req: NextRequest) {
if (
req.nextUrl.pathname.startsWith('/_next') ||
req.nextUrl.pathname.includes('/api/') ||
PUBLIC_FILE.test(req.nextUrl.pathname)
) {
return
}

if (
!(
req.nextUrl.pathname.startsWith('/en') ||
req.nextUrl.pathname.startsWith('/ko')
)
) {
return NextResponse.redirect(
new URL(`/en${req.nextUrl.pathname}${req.nextUrl.search}`, req.url)
)
}
}
export { middleware } from 'nextra/locales'

export const config = {
matcher: [
Expand All @@ -31,7 +8,8 @@ export const config = {
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - img (image files)
*/
'/((?!api|_next/static|_next/image|favicon.ico).*)',
'/((?!api|_next/static|_next/image|favicon.ico|img).*)',
],
}
62 changes: 38 additions & 24 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b13b700

Please sign in to comment.