Skip to content

Commit 7d0cc16

Browse files
kickbelldevclaude
andcommitted
refactor: 카테고리 유효성 검증 로직 제거
- extractCategoryFromPath에서 하드코딩된 카테고리 제한 제거 - 모든 서브디렉토리를 유효한 카테고리로 인식하도록 변경 - 파일 경로 구조 검증 로직 개선 (contents/category/file.mdx 구조 필수) - 관련 테스트 케이스 업데이트 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 8e53ba8 commit 7d0cc16

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/entities/posts/logic.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ export function extractCategoryFromPath(filePath: string): string | undefined {
4141
(segment) => segment === 'contents'
4242
)
4343

44-
if (contentsIndex === -1 || contentsIndex >= pathSegments.length - 1) {
44+
if (contentsIndex === -1 || contentsIndex >= pathSegments.length - 2) {
4545
return undefined
4646
}
4747

4848
const categorySegment = pathSegments[contentsIndex + 1]
4949

50-
// 카테고리가 유효한지 확인 (dev, life만 허용)
51-
if (categorySegment === 'dev' || categorySegment === 'life') {
50+
// 파일명이 아닌 디렉토리인지 확인 (최소 2단계 deeper: contents/category/file.mdx)
51+
if (contentsIndex + 2 < pathSegments.length) {
5252
return categorySegment
5353
}
5454

src/entities/posts/posts.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,10 @@ describe('Posts Logic - Business Logic Tests', () => {
346346
expect(result).toBeUndefined()
347347
})
348348

349-
it('should return undefined for invalid category', () => {
350-
const path = '/home/user/project/src/contents/invalid/post.mdx'
349+
it('should extract any category from path', () => {
350+
const path = '/home/user/project/src/contents/custom/post.mdx'
351351
const result = extractCategoryFromPath(path)
352-
expect(result).toBeUndefined()
352+
expect(result).toBe('custom')
353353
})
354354

355355
it('should return undefined for path without contents directory', () => {

0 commit comments

Comments
 (0)