forked from eduardoboucas/staticman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
siteConfig.js
216 lines (209 loc) · 7.52 KB
/
siteConfig.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
'use strict'
const convict = require('convict')
const schema = {
allowedFields: {
doc: 'An array with the names of the allowed fields. If any of the fields sent is not part of this list, the entry will be discarded and an error will be thrown.',
docExample: 'allowedFields: ["name", "email", "message"]',
format: Array,
default: []
},
allowedOrigins: {
doc: 'When allowedOrigins is defined, only requests sent from one of the domains listed will be accepted.',
docExample: 'allowedOrigins: ["localhost", "eduardoboucas.com"]',
default: [],
format: Array
},
akismet: {
enabled: {
doc: 'Whether to use Akismet to check entries for spam. This requires an Akismet account to be configured in the Staticman API instance being used.',
format: Boolean,
default: false
},
author: {
doc: 'Name of the field to be used as the entry\'s author in Akistmet',
format: String,
default: ''
},
authorEmail: {
doc: 'Name of the field to be used as the entry\'s author\'s email in Akistmet',
format: String,
default: ''
},
authorUrl: {
doc: 'Name of the field to be used as the entry\'s author\'s URL in Akistmet',
format: String,
default: ''
},
content: {
doc: 'Name of the field to be used as the entry\'s body in Akistmet',
format: String,
default: ''
},
type: {
doc: 'Type of entry to be sent to Akismet',
format: String,
default: 'comment'
}
},
auth: {
required: {
doc: 'Whether authentication is required for an entry to be accepted.',
format: Boolean,
default: false
}
},
branch: {
doc: 'Name of the branch being used within the GitHub repository.',
format: String,
default: 'master'
},
commitMessage: {
doc: 'Text to be used as the commit message when pushing entries to the GitHub repository.',
format: String,
default: 'Add Staticman data'
},
extension: {
doc: 'The extension to be used in the generated data files (defaults to the extension associated with the `format` field)',
format: String,
default: ''
},
filename: {
doc: 'Name for the data files being uploaded to the repository. You can use placeholders (denoted by curly braces), which will be dynamically replaced with the content of a field (e.g. `{fields.name}`), the content of an option (e.g. `{options.slug}`) or other dynamic placeholders such as the entry\'s unique id (`{@id}`).',
format: String,
default: ''
},
format: {
doc: 'Format of the data files being uploaded to the repository.',
format: ['yaml', 'yml', 'json', 'frontmatter'],
default: 'yml'
},
generatedFields: {
doc: 'List of fields to be appended to entries automatically. It consists of an object where keys correspond to the names of the fields being created and values being of mixed type. If values are objects, Staticman will look for a `type` and `options` keys inside and perform different operations based on their type; otherwise, the value will be used directly as the content of the generated field.',
docExample: 'generatedFields:\n someField: "some string" # Simple field (string)\n date: # Extended field (date)\n type: date\n options:\n format: "timestamp-seconds"',
format: Object,
default: {}
},
githubAuth: {
clientId: {
doc: 'The client ID to the GitHub Application used for GitHub OAuth.',
format: 'EncryptedString',
default: null
},
clientSecret: {
doc: 'The client secret to the GitHub Application used for GitHub OAuth.',
format: 'EncryptedString',
default: null
},
redirectUri: {
doc: 'The URL to redirect to after authenticating with GitHub.',
format: String,
default: ''
},
required: {
doc: 'Whether GitHub Auth is required for an entry to be accepted. This is only included for backwards compatibility with the v2 API. For the v3 API, please use the `auth.required` option instead.',
format: Boolean,
default: false
}
},
gitlabAuth: {
clientId: {
doc: 'The client ID to the GitLab Application used for GitLab OAuth.',
format: 'EncryptedString',
default: null
},
clientSecret: {
doc: 'The client secret to the GitLab Application used for GitLab OAuth.',
format: 'EncryptedString',
default: null
},
redirectUri: {
doc: 'The URL to redirect to after authenticating with GitLab.',
format: String,
default: ''
}
},
moderation: {
doc: 'When set to `true`, a pull request with the data files will be created to allow site administrators to approve or reject an entry. Otherwise, entries will be pushed to `branch` immediately.',
format: Boolean,
default: true
},
name: {
doc: 'Human-friendly name of the property/website. This is used in notification emails.',
docExample: 'name: "My awesome blog"',
format: String,
default: ''
},
notifications: {
enabled: {
doc: 'Whether email notifications are enabled. This allows users to subscribe to future comments on a thread. A [Mailgun](http://mailgun.com) account is required.',
format: Boolean,
default: false
},
apiKey: {
doc: 'Mailgun API key',
format: 'EncryptedString',
default: null
},
domain: {
doc: 'Mailgun domain',
format: 'EncryptedString',
default: null
}
},
path: {
doc: 'Path to the directory where entry files are stored. You can use placeholders (denoted by curly braces), which will be dynamically replaced with the content of a field (e.g. `{fields.name}`), the content of an option (e.g. `{options.slug}`) or other dynamic placeholders such as the entry\'s unique id (`{@id}`).',
format: String,
default: '_data/results/{@timestamp}'
},
pullRequestBody: {
doc: 'Text to be used as the pull request body when pushing moderated entries.',
format: String,
default: 'Dear human,\n\nHere\'s a new entry for your approval. :tada:\n\nMerge the pull request to accept it, or close it to send it away.\n\n:heart: Your friend [Staticman](https://staticman.net) :muscle:\n\n---\n'
},
requiredFields: {
doc: 'An array with the names of the fields that must be supplies as part of an entry. If any of these is not present, the entry will be discarded and an error will be thrown.',
format: Array,
default: []
},
transforms: {
doc: 'List of transformations to be applied to any of the fields supplied. It consists of an object where keys correspond to the names of the fields being transformed. The value determines the type of transformation being applied.',
docExample: 'transforms:\n email: "md5" # The email field will be MD5-hashed',
format: Object,
default: {}
},
reCaptcha: {
enabled: {
doc: 'Set to `true` to force reCAPTCHA validation, set to `false` to accept comments without reCAPTCHA.',
format: Boolean,
default: false
},
siteKey: {
doc: 'Site Key for your reCAPTCHA site registration',
format: String,
default: ''
},
secret: {
doc: 'Encrypted Secret for your reCAPTCHA site registration',
format: 'EncryptedString',
default: ''
}
}
}
module.exports = (data, rsa) => {
convict.addFormat({
name: 'EncryptedString',
validate: val => true,
coerce: val => {
return rsa.decrypt(val, 'utf8')
}
})
const config = convict(schema)
try {
config.load(data)
config.validate()
return config
} catch (e) {
throw e
}
}
module.exports.schema = schema