/
types.ts
107 lines (89 loc) · 2.48 KB
/
types.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { NextConfig } from 'next'
import { Heading as MDASTHeading } from 'mdast'
import { ProcessorOptions } from '@mdx-js/mdx'
import { Options as RehypePrettyCodeOptions } from 'rehype-pretty-code'
import { GrayMatterFile } from 'gray-matter'
import { PageMapCache } from './plugin'
import { MARKDOWN_EXTENSIONS, META_FILENAME } from './constants'
type MetaFilename = typeof META_FILENAME
type MarkdownExtension = typeof MARKDOWN_EXTENSIONS[number]
export interface LoaderOptions extends NextraConfig {
pageImport?: boolean
locales: string[]
defaultLocale: string
pageMapCache: PageMapCache
newNextLinkBehavior?: boolean
}
export interface Folder<FileType = PageMapItem> {
kind: 'Folder'
name: string
route: string
children: FileType[]
}
export type MetaJsonFile = {
kind: 'Meta'
locale?: string
data: {
[fileName: string]: Meta
}
}
export type FrontMatter = GrayMatterFile<string>['data']
export type Meta = string | Record<string, any>
export type MdxFile = {
kind: 'MdxPage'
name: string
route: string
locale?: string
frontMatter?: FrontMatter
}
export type MetaJsonPath = `${string}/${MetaFilename}`
export type MdxPath = `${string}.${MarkdownExtension}`
export type FileMap = {
[jsonPath: MetaJsonPath]: MetaJsonFile
[mdxPath: MdxPath]: MdxFile
}
export type PageMapItem = Folder | MdxFile | MetaJsonFile
// PageMapItem without MetaJsonFile and with its meta from _meta.json
export type Page = (MdxFile | Folder<Page>) & {
meta?: Exclude<Meta, string>
}
export type Heading = MDASTHeading & {
value: string
}
export type PageOpts = {
filePath: string
route: string
frontMatter: FrontMatter
pageMap: PageMapItem[]
title: string
headings: Heading[]
hasJsxInH1?: boolean
timestamp?: number
flexsearch?: Flexsearch
newNextLinkBehavior?: boolean
readingTime?: ReadingTime
}
export type ReadingTime = {
text: string
minutes: number
time: number
words: number
}
type Theme = string
type Flexsearch = boolean | { codeblocks: boolean }
export type NextraConfig = {
theme: Theme
themeConfig?: string
defaultShowCopyCode?: boolean
flexsearch?: Flexsearch
staticImage?: boolean
readingTime?: boolean
mdxOptions?: Pick<ProcessorOptions, 'rehypePlugins' | 'remarkPlugins'> & {
rehypePrettyCodeOptions?: Partial<RehypePrettyCodeOptions>
}
}
export type Nextra = (
...args: [NextraConfig] | [theme: Theme, themeConfig: string]
) => (nextConfig: NextConfig) => NextConfig
const nextra: Nextra = () => () => ({})
export default nextra