forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options-validation.js
105 lines (102 loc) 路 3.53 KB
/
options-validation.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
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
import { parse as parseGraphql } from "gatsby/graphql"
import { stripIndent, oneLine } from "common-tags"
import {
resolveSiteUrl,
resolvePagePath,
resolvePages,
serialize,
defaultFilterPages,
} from "./internals"
export const pluginOptionsSchema = ({ Joi }) =>
Joi.object({
plugins: Joi.array().strip(),
output: Joi.string()
.default(`/sitemap`)
.description(`Folder path where sitemaps are stored in \`public\`.`),
createLinkInHead: Joi.boolean()
.default(true)
.description(
`Whether to populate the \`<head>\` of your site with a link to the sitemap.`
),
entryLimit: Joi.number()
.default(45000) // default based on upstream "sitemap" plugin default, may need optimization
.description(
`Number of entries per sitemap file, a sitemap index and multiple sitemaps are created if you have more entries.`
),
query: Joi.string()
.default(
oneLine`{
site {
siteMetadata {
siteUrl
}
}
allSitePage {
nodes {
path
}
}
}`
)
.external(pluginOptions => {
const query = pluginOptions?.query
if (query) {
try {
parseGraphql(query)
} catch (e) {
throw new Error(
stripIndent`
Invalid plugin options for "gatsby-plugin-sitemap":
"query" must be a valid GraphQL query. Received the error "${e.message}"`
)
}
}
})
.description(
stripIndent`
(GraphQL Query) The query for the data you need to generate the sitemap.
It's required to get the site's URL, if you are not fetching it from \`site.siteMetadata.siteUrl\`,
you will need to set a custom \`resolveSiteUrl\` function.
If you override the query, you may need to pass in a custom \`resolvePagePath\` or
\`resolvePages\` to keep everything working.
If you fetch pages without using \`allSitePage.nodes\` query structure
you will definately need to customize the \`resolvePages\` function.`
),
excludes: Joi.array()
.items(Joi.any())
.default([])
.description(
stripIndent`
An array of paths to exclude from the sitemap.
While this is usually an array of strings it is possible to
enter other data types into this array for custom filtering.
Doing so will require customization of the \`filterPages\` function.`
),
resolveSiteUrl: Joi.function()
.default(() => resolveSiteUrl)
.description(
`Takes the output of the data query and lets you return the site URL.`
),
resolvePagePath: Joi.function()
.default(() => resolvePagePath)
.description(
`Takes a page object and returns the uri of the page (no domain or protocol).`
),
resolvePages: Joi.function()
.default(() => resolvePages)
.description(
`Takes the output of the data query and expects an array of page objects to be returned.`
),
filterPages: Joi.function()
.default(() => defaultFilterPages)
.description(
stripIndent`Takes the current page a string (or other object)
from the \`exclude\` array and expects a boolean to be returned.
\`true\` excludes the path, \`false\` keeps it.`
),
serialize: Joi.function()
.default(() => serialize)
.description(
`Takes the output of \`filterPages\` and lets you return a sitemap entry.`
),
})