-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkdown.ts
70 lines (64 loc) · 1.43 KB
/
markdown.ts
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
63
64
65
66
67
68
69
70
import path from 'path'
import matter from 'gray-matter'
export const getMarkdownAllData = (
files: string[],
mdPath: string,
// eslint-disable-next-line
module: any
) => {
return files.map((filename) => {
const slug = filename.replace('.md', '')
const markdownWithMeta = module.readFileSync(
path.join(mdPath, filename),
'utf-8'
)
const { data: frontmatter } = matter(markdownWithMeta)
return {
slug,
frontmatter,
}
})
}
export const getMarkDownSingleData = (
// eslint-disable-next-line
module: any,
mdPath: string,
slug?: string
) => {
if (slug) {
const markdownWithMeta = module.readFileSync(
path.join(mdPath, slug + '.md'),
'utf-8'
)
const { data: frontmatter, content } = matter(markdownWithMeta)
return {
props: {
frontmatter,
slug,
content,
},
}
} else {
const markdownWithMeta = module.readFileSync(mdPath + '.md', 'utf-8')
const { data: frontmatter, content } = matter(markdownWithMeta)
return {
props: {
frontmatter,
content,
},
}
}
}
// eslint-disable-next-line
export const getMarkdownSinglePath = (module: any, mdPath: string) => {
const files = module.readdirSync(path.join(mdPath))
const paths = files.map((filename: string) => ({
params: {
slug: filename.replace('.md', ''),
},
}))
return {
paths,
fallback: false,
}
}