-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsitemap.js
38 lines (31 loc) · 953 Bytes
/
sitemap.js
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
import { join } from 'path'
import { promises as fs } from 'fs'
export default async function sitemap() {
async function getComponents() {
const componentsPath = join(process.cwd(), '/src/data/components')
const componentSlugs = await fs.readdir(componentsPath)
const componentItems = await Promise.all(
componentSlugs.map(async (componentSlug) => {
const formattedComponentSlug = componentSlug.replace('.mdx', '')
return `examples/${formattedComponentSlug}`
})
)
return componentItems
}
const siteSlugs = await Promise.all([getComponents()])
const transformedSlugs = siteSlugs.flatMap((siteSlug) => {
return siteSlug.flatMap((pageSlug) => {
return {
url: `https://js.hyperui.dev/${pageSlug}`,
lastModified: new Date(),
}
})
})
return [
{
url: 'https://js.hyperui.dev',
lastModified: new Date(),
},
...transformedSlugs,
]
}