Skip to content

Commit 57bc3b1

Browse files
feat: auto lint with husky (#8)
* test * asdf * prettier
1 parent 06ff8e9 commit 57bc3b1

File tree

9 files changed

+675
-28
lines changed

9 files changed

+675
-28
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,6 @@ yarn-error.log*
3434
# typescript
3535
*.tsbuildinfo
3636
next-env.d.ts
37+
38+
# husky
39+
.husky/_

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npx lint-staged

.prettierrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

app/[lang]/guide/[group]/[slug]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default async function Page({ params }: GuidePageProps) {
6464
lang,
6565
group,
6666
slug,
67-
allDocuments
67+
allDocuments,
6868
);
6969

7070
return (

app/[lang]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import MouseImageEffect from "@/components/effects/mouse-image-effect";
22

3-
export const runtime = 'edge';
3+
export const runtime = "edge";
44

55
export default function Home({
66
params: { lang },

lib/mdx.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function getDocumentBySlug(
6565
lang: string,
6666
group: string,
6767
slug: string,
68-
allDocuments: Document[]
68+
allDocuments: Document[],
6969
): DocumentData {
7070
const notFoundDocument: DocumentData = {
7171
slug: "",
@@ -90,7 +90,8 @@ export function getDocumentBySlug(
9090
}
9191

9292
const document = documentsInGroup[currentIndex];
93-
const prevDocument = currentIndex > 0 ? documentsInGroup[currentIndex - 1] : null;
93+
const prevDocument =
94+
currentIndex > 0 ? documentsInGroup[currentIndex - 1] : null;
9495
const nextDocument =
9596
currentIndex < documentsInGroup.length - 1
9697
? documentsInGroup[currentIndex + 1]

middleware.ts

+25-23
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
import { NextResponse } from 'next/server'
2-
import type { NextRequest } from 'next/server'
1+
import { NextResponse } from "next/server";
2+
import type { NextRequest } from "next/server";
33

4-
const supportedLanguages = ['en', 'ko']
4+
const supportedLanguages = ["en", "ko"];
55

66
function getPreferredLanguage(request: NextRequest): string {
7-
const acceptLanguage = request.headers.get('accept-language')
8-
if (!acceptLanguage) return 'en'
9-
10-
const langs = acceptLanguage.split(',').map(lang => lang.split(';')[0])
7+
const acceptLanguage = request.headers.get("accept-language");
8+
if (!acceptLanguage) return "en";
9+
10+
const langs = acceptLanguage.split(",").map((lang) => lang.split(";")[0]);
1111
for (const lang of langs) {
12-
const shortLang = lang.slice(0, 2).toLowerCase()
12+
const shortLang = lang.slice(0, 2).toLowerCase();
1313
if (supportedLanguages.includes(shortLang)) {
14-
return shortLang
14+
return shortLang;
1515
}
1616
}
17-
return 'en'
17+
return "en";
1818
}
1919

2020
export function middleware(request: NextRequest) {
21-
const { pathname } = request.nextUrl
21+
const { pathname } = request.nextUrl;
2222

2323
if (pathname.match(/\.(svg|png|jpg|jpeg|gif|ico)$/)) {
24-
return NextResponse.next()
24+
return NextResponse.next();
2525
}
26-
27-
if (supportedLanguages.some(lang => pathname.startsWith(`/${lang}/`) || pathname === `/${lang}`)) {
28-
return NextResponse.next()
26+
27+
if (
28+
supportedLanguages.some(
29+
(lang) => pathname.startsWith(`/${lang}/`) || pathname === `/${lang}`,
30+
)
31+
) {
32+
return NextResponse.next();
2933
}
3034

31-
const lang = getPreferredLanguage(request)
35+
const lang = getPreferredLanguage(request);
36+
37+
const newUrl = new URL(`/${lang}${pathname}`, request.url);
3238

33-
const newUrl = new URL(`/${lang}${pathname}`, request.url)
34-
35-
return NextResponse.redirect(newUrl)
39+
return NextResponse.redirect(newUrl);
3640
}
3741

3842
export const config = {
39-
matcher: [
40-
'/((?!api|_next/static|_next/image|favicon.ico).*)',
41-
],
42-
}
43+
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
44+
};

0 commit comments

Comments
 (0)