forked from LangbaseInc/langui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.jsx
62 lines (50 loc) · 1.94 KB
/
page.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import matter from 'gray-matter'
import { join } from 'path'
import { promises as fs } from 'fs'
import HeroBanner from '@component/HeroBanner'
async function getComponents() {
const componentsPath = join(process.cwd(), '/src/data/components')
const categoriesPath = join(process.cwd(), '/src/data/categories')
const categorySlugs = ['components']
const componentSlugs = await fs.readdir(componentsPath)
const componentsByCategory = await Promise.all(
categorySlugs.map(async (categorySlug) => {
const categoryPath = join(categoriesPath, `${categorySlug}.mdx`)
const categoryItem = await fs.readFile(categoryPath, 'utf-8')
const { data: categoryData } = matter(categoryItem)
const componentItems = await Promise.all(
componentSlugs
.filter((componentSlug) => componentSlug.includes(categorySlug))
.map(async (componentSlug) => {
const componentPath = join(componentsPath, componentSlug)
const componentItem = await fs.readFile(componentPath, 'utf-8')
const { data: componentData } = matter(componentItem)
const componentSlugFormatted = componentSlug.replace('.mdx', '')
const componentSlugTrue = componentSlugFormatted.replace(
`${componentData.category}-`,
''
)
const componentCount = Object.values(
componentData.components
).length
return {
title: componentData.title,
slug: componentSlugTrue,
category: componentData.category,
count: componentCount,
}
})
)
return {
categoryTitle: categoryData.title,
componentItems,
}
})
)
return componentsByCategory
}
export default async function Page() {
// TODO: If we have more than one categories in the future
// const componentsByCategory = await getComponents()
return <HeroBanner />
}