-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConfigurationTypes.ts
204 lines (193 loc) · 6.2 KB
/
ConfigurationTypes.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
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
import {IOptions as ITruncateOptions} from 'truncate-html';
export interface IExcerptsPluginConfiguration {
/**
* A collection of named Sources.
* Each Source can be used in any number of Source Sets.
*
* ## Example
* This example defines a Source called 'excerptElement' which attempts to include the contents of any elements with class "excerpt".
* It also defines a Source called 'default' will include any elements other than images or code blocks.
* Both sources strip links from the resulting excerpt.
* ```json
{
"excerptElement": {
"type": "htmlQuery",
"sourceField": "html",
"excerptSelector": ".excerpt",
"stripSelector": "a"
},
"default": {
"type": "htmlQuery",
"sourceField": "html",
"excerptSelector": "html > *",
"ignoreSelector": "img, .gatsby-highlight",
"stripSelector": "a"
}
}
```
*/
sources: {
[sourceName: string]: IExcerptSourceConfiguration
}
/**
* A collection of named Source Sets.
* Each Source Set can be assigned to one or more Node Types.
*
* ## Example
* This example defines a Source Set called 'markdownHtml' that will first attempt to use the excerptElement source. If this source does not find any valid excerpt, the 'default' source will be tried instead.
* ```json
{
"markdownHtml": [
"excerptElement",
"default"
]
}
```
*/
sourceSets: {
[sourceSetName: string]: Array<string>
}
/**
* A collection of Excerpts which will be added as GraphQL fields to relevant nodes.
*
* Note that if you are using gatsby-transformer-remark the name 'excerpt' is already taken, so you cannot use this name.
*
* ## Example
* This example defines a 'snippet' Excerpt which will use the markdownHtml Source Set on MarkdownRemark nodes.
* ```json
{
"snippet": {
"type": "html",
"nodeTypeSourceSet": {
"MarkdownRemark": "markdownHtml"
}
}
}
```
*/
excerpts: {
[excerptName: string]: IExcerptConfiguration
}
}
export interface IExcerptConfiguration {
/**
* The desired output type of this excerpt.
*
* Valid values:
* * text - Excerpt will be converted to plain text
* * html - Excerpt will be converted to HTML
*/
type: string;
/**
* A mapping of Node Types to add this excerpt to and the Source Set to use for each type.
* \* can be used to apply a Source Set to all Node Types, although this is not usually useful.
*
* ## Example
* ```json
{
"MarkdownRemark": "default"
}
```
*/
nodeTypeSourceSet: {
[nodeType: string]: string;
}
}
export type IExcerptSourceConfiguration = IExcerptSourceConfigurationHtmlQuery;
export abstract class IExcerptSourceConfigurationBase {
type: string;
sourceField: string;
}
export interface IExcerptSourceConfigurationHtmlQuery extends IExcerptSourceConfigurationBase {
type: "htmlQuery";
/**
* The name of the field to search for the excerpt within.
* For example, with gatsby-transformer-remark you probably want to use 'html'.
*/
sourceField: string;
/**
* A CSS selector that determines which content to include in the excerpt.
*
* @defaultValue `'*'`
* @see [css-select supported selectors](https://www.npmjs.com/package/css-select#supported-selectors)
*/
excerptSelector?: string;
/**
* A CSS selector representing tags that should be stripped from the excerpt while preserving their content.
*
* @defaultValue none
* @see [css-select supported selectors](https://www.npmjs.com/package/css-select#supported-selectors)
*
* ## Example
* To remove links from the excerpt, specify `'a'`
*/
stripSelector?: string;
/**
* A CSS selector representing tags that should be excluded from the excerpt, also removing their content.
*
* @defaultValue none
* @see [css-select supported selectors](https://www.npmjs.com/package/css-select#supported-selectors)
*
* ## Example
* To remove `gatsby-remark-prismjs` code snippets from the excerpt, use `'.gatsby-highlight'`
*/
ignoreSelector?: string;
/**
* Allows for swapping certain elements with other elements, preserving their attributes and content.
* Replacements will be executed in order. Be careful to think through how your replacements might affect each other.
* For example, replacing h2 with h3 and then h3 with h4 will result in h2 elements becoming h4. Replacing h3 with h4 and then h2 with h3 will result in h2 elements becoming h3, which is probably your intended behaviour.
*/
elementReplacements?: [
{
/**
* A CSS selector representing elements that you want to replace.
*
* @see [css-select supported selectors](https://www.npmjs.com/package/css-select#supported-selectors)
*/
selector: string;
/**
* The element type that you wish to replace the elements with.
*/
replaceWith: string;
}
];
/**
* Used to trim the resulting HTML down to a specific length.
*
* @see [truncate-html documentation](https://www.npmjs.com/package/truncate-html#api)
*/
truncate?: ITruncateOptions;
}
/*
const example: IExcerptsPluginConfiguration = {
sources: {
"excerptElement": {
type: "htmlQuery",
sourceField: "html",
excerptSelector: ".custom-block.excerpt .custom-block-body",
stripSelector: "a"
},
"default": {
type: "htmlQuery",
sourceField: "html",
excerptSelector: "html > *",
ignoreSelector: "img, .custom-block.iconBox, .custom-block.aside, details, .gatsby-highlight",
stripSelector: "a"
}
},
sourceSets: {
"markdownHtml": [
"excerptElement",
"default"
]
},
excerpts: {
snippet: {
type: "html",
nodeTypeSourceSet: {
"MarkdownRemark": "markdownHtml"
}
}
}
};
*/