File tree Expand file tree Collapse file tree 3 files changed +33
-21
lines changed Expand file tree Collapse file tree 3 files changed +33
-21
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,14 @@ module.exports = {
24
24
// Search queary (optional)
25
25
// See :y https://docs.esa.io/posts/104
26
26
// Example : 'in:public' or 'wip:false in:public'
27
- q: ` `
27
+ q: ' ' ,
28
+ // Relative Category (optional)
29
+ // Example: 'public'
30
+ // {
31
+ // category: 'public/gatsby',
32
+ // relative_category: 'gatsby',
33
+ // }
34
+ baseCategory: ' '
28
35
}
29
36
}
30
37
]
@@ -41,6 +48,10 @@ module.exports = {
41
48
number
42
49
name
43
50
body_md
51
+ body_html
52
+ category
53
+ relative_category
54
+ tags
44
55
}
45
56
}
46
57
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " gatsby-source-esa" ,
3
- "version" : " 1.0.7 " ,
3
+ "version" : " 1.1.0 " ,
4
4
"description" : " Gatsby source plugin for building websites using esa.io as a data source." ,
5
5
"main" : " gatsby-node.js" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change @@ -7,26 +7,9 @@ exports.sourceNodes = async ({
7
7
} , {
8
8
accessToken,
9
9
teamName,
10
+ baseCategory = '' ,
10
11
q = ''
11
12
} ) => {
12
- const createNodeFromPost = post => {
13
- const contentDigest = crypto
14
- . createHash ( `md5` )
15
- . update ( JSON . stringify ( post ) )
16
- . digest ( 'hex' )
17
- const baseNode = {
18
- id : createNodeId ( `EsaPost${ post . number } ` ) ,
19
- children : [ ] ,
20
- parent : `__SOURCE__` ,
21
- internal : {
22
- type : 'EsaPost' ,
23
- contentDigest,
24
- }
25
- }
26
-
27
- boundActionCreators . createNode ( Object . assign ( { } , baseNode , post ) )
28
- }
29
-
30
13
if ( ! accessToken ) {
31
14
throw 'You need to set an accessToken.'
32
15
}
@@ -50,7 +33,25 @@ exports.sourceNodes = async ({
50
33
}
51
34
} )
52
35
53
- body . posts . forEach ( post => createNodeFromPost ( post ) )
36
+ body . posts . forEach ( post => {
37
+ const contentDigest = crypto
38
+ . createHash ( `md5` )
39
+ . update ( JSON . stringify ( post ) )
40
+ . digest ( 'hex' )
41
+
42
+ boundActionCreators . createNode ( {
43
+ ...post ,
44
+ relative_category : post . category . replace ( new RegExp ( `${ baseCategory } /?` ) , '' ) ,
45
+ id : createNodeId ( `EsaPost${ post . number } ` ) ,
46
+ children : [ ] ,
47
+ parent : `__SOURCE__` ,
48
+ internal : {
49
+ type : 'EsaPost' ,
50
+ contentDigest,
51
+ }
52
+ } )
53
+ } )
54
+
54
55
next_page = body . next_page
55
56
}
56
57
You can’t perform that action at this time.
0 commit comments