Skip to content

Commit 3ecc123

Browse files
committed
refactor: types
1 parent c8e8d08 commit 3ecc123

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

app/[locale]/[...slug]/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
setRequestLocale,
77
} from "next-intl/server"
88

9+
import { SlugPageParams } from "@/lib/types"
10+
911
import I18nProvider from "@/components/I18nProvider"
1012
import mdComponents from "@/components/MdComponents"
1113

@@ -27,7 +29,7 @@ const loadData = dataLoader([["gfissues", fetchGFIs]])
2729
export default async function Page({
2830
params,
2931
}: {
30-
params: Promise<{ locale: string; slug: string[] }>
32+
params: Promise<SlugPageParams>
3133
}) {
3234
const { locale, slug: slugArray } = await params
3335

@@ -109,7 +111,7 @@ export async function generateStaticParams() {
109111
export async function generateMetadata({
110112
params,
111113
}: {
112-
params: Promise<{ locale: string; slug: string[] }>
114+
params: Promise<SlugPageParams>
113115
}) {
114116
const { locale, slug } = await params
115117

src/lib/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,3 +1028,11 @@ export interface ITutorial {
10281028
lang: string
10291029
isExternal: boolean
10301030
}
1031+
1032+
export type PageParams = {
1033+
locale: string
1034+
}
1035+
1036+
export type SlugPageParams = PageParams & {
1037+
slug: string[]
1038+
}

src/lib/utils/md.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { extname, join } from "path"
55
import matter from "gray-matter"
66
import readingTime from "reading-time"
77

8-
import type { Frontmatter, ITutorial, Skill } from "@/lib/types"
8+
import type { Frontmatter, ITutorial, Skill, SlugPageParams } from "@/lib/types"
99

1010
import { dateToString } from "@/lib/utils/date"
1111

@@ -100,3 +100,12 @@ export const getTutorialsData = (locale: string): ITutorial[] => {
100100

101101
return tutorialData
102102
}
103+
104+
export const checkPathValidity = (
105+
validPaths: SlugPageParams[],
106+
{ locale, slug: slugArray }: SlugPageParams
107+
): boolean =>
108+
validPaths.some(
109+
(path) =>
110+
path.locale === locale && path.slug.join("/") === slugArray.join("/")
111+
)

0 commit comments

Comments
 (0)