-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.ts
99 lines (84 loc) · 2.75 KB
/
options.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
import { FileCache } from "./file-cache";
export interface Options {
/**
* The default layout component to use if no `layout` is specified in frontmatter.
*
* Defaults to "docs" which, combined with the default `layoutsDir` option, will
* use the component at "./layouts/docs".
*/
defaultLayout: string;
/**
* The path of the directory containing layout components.
*
* Defaults to "./layouts"
*/
layoutsDir: string;
/**
* The path of the Next.js "pages" directory.
*
* Defaults to "./pages"
*/
pagesDir: string;
/**
* The name of the prop to pass to JSX components to indicate that they originally came from
* Markdown syntax. This allows you to distinguish between `**bold**` and `<b>bold</b>`,
* which can be used to apply different styling, or even render completely different JSX.
*
* Defaults to "markdown"
*/
markdownPropName: string;
/**
* The value of the prop that's passed to JSX components to indicate that they originally
* came from Markdown syntax.
*
* Defaults to `true`
*/
markdownPropValue: unknown;
/**
* Next-MDX caches files to reduce disk IO, which reduces build times.
* This is the number of milliseconds to cache each file before re-reading it.
*
* Defaults to `60000` (one minute)
*/
fileCacheTimeout: number;
/**
* The path at which to generate a Sitemap of all pages. Can be set to `false` to disable
* sitemap generation.
*
* Defaults to "./public/sitemap.xml"
*/
sitemap: string | false;
/**
* The root URL of the website. This is used to resolve any relative URLs
*/
siteURL: string | URL;
}
export interface NormalizedOptions extends Omit<Options, "fileCacheTimeout"> {
siteURL: URL;
/**
* A cache of whether file information, to save redundant disk I/O
*/
fileCache: FileCache;
}
/**
* Normalizes user-specified options, and applies defaults for any options that
* aren't specified.
*/
export function normalizeOptions(options: Partial<Options>): NormalizedOptions {
const fileCacheTimeout = options.fileCacheTimeout || 60000;
if (!options.siteURL) {
// We can only generate a sitemap if a siteURL is provided
options.sitemap = false;
options.siteURL = "http://localhost:3000";
}
return {
defaultLayout: options.defaultLayout || "docs",
layoutsDir: options.layoutsDir || "./layouts",
pagesDir: options.pagesDir || "./pages",
markdownPropName: options.markdownPropName || "markdown",
markdownPropValue: options.markdownPropValue || true,
sitemap: options.sitemap === false ? false : (options.sitemap || "./public/sitemap.xml"),
siteURL: options.siteURL instanceof URL ? options.siteURL : new URL(options.siteURL),
fileCache: new FileCache(fileCacheTimeout),
};
}