Skip to content

Commit 9ecf745

Browse files
authored
Merge pull request #3 from mottox2/relative_category
相対カテゴリを指定可能にした
2 parents c4b35d1 + a47755d commit 9ecf745

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ module.exports = {
2424
// Search queary (optional)
2525
// See :y https://docs.esa.io/posts/104
2626
// 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: ''
2835
}
2936
}
3037
]
@@ -41,6 +48,10 @@ module.exports = {
4148
number
4249
name
4350
body_md
51+
body_html
52+
category
53+
relative_category
54+
tags
4455
}
4556
}
4657
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gatsby-source-esa",
3-
"version": "1.0.7",
3+
"version": "1.1.0",
44
"description": "Gatsby source plugin for building websites using esa.io as a data source.",
55
"main": "gatsby-node.js",
66
"scripts": {

src/gatsby-node.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,9 @@ exports.sourceNodes = async ({
77
}, {
88
accessToken,
99
teamName,
10+
baseCategory = '',
1011
q = ''
1112
}) => {
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-
3013
if (!accessToken) {
3114
throw 'You need to set an accessToken.'
3215
}
@@ -50,7 +33,25 @@ exports.sourceNodes = async ({
5033
}
5134
})
5235

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+
5455
next_page = body.next_page
5556
}
5657

0 commit comments

Comments
 (0)