MCPcopy Create free account
hub / github.com/chokcoco/iCSS / GET

Function GET

website/app/api/categories/route.ts:4–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { GitHubAPI } from '@/app/lib/github';
3
4export async function GET() {
5 try {
6 // 获取所有文章
7 const allArticles = await GitHubAPI.getAllArticles();
8
9 // 确保 allArticles 是数组
10 if (!Array.isArray(allArticles)) {
11 console.error('GitHub API returned non-array data:', allArticles);
12 return NextResponse.json(['全部'], { status: 200 });
13 }
14
15 // 提取所有分类
16 const categories = new Set<string>();
17 allArticles.forEach(article => {
18 if (article.category) {
19 categories.add(article.category);
20 }
21 });
22
23 // 转换为数组并排序
24 const categoryList = Array.from(categories).sort();
25
26 // 添加"全部"选项
27 categoryList.unshift('全部');
28
29 return NextResponse.json(categoryList);
30 } catch (error) {
31 console.error('Error fetching categories:', error);
32 // 返回默认分类列表,避免前端报错
33 return NextResponse.json(['全部'], { status: 200 });
34 }
35}

Callers

nothing calls this directly

Calls 1

getAllArticlesMethod · 0.80

Tested by

no test coverage detected