Skip to content

Commit 7a4e90a

Browse files
sinchangegoist
authored andcommitted
feat: support using GitHub pinned repositories (#8)
* feat: support using GitHub pinned repository as the project * f * project -> projects * project -> projects * project -> projects * Update saber-node.js
1 parent deae684 commit 7a4e90a

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ module.exports = {
9191

9292
Use `themeConfig` option in `saber-config.js` for theme configuration.
9393

94+
### Projects
95+
96+
By default we fetch your top 6 starred repositories from GitHub, if set to `pinned-project`, it will use pinned repositories instead:
97+
98+
```js
99+
module.exports = {
100+
themeConfig: {
101+
projects: 'pinned-repos'
102+
}
103+
}
104+
```
105+
94106
### Style
95107

96108
By default it uses `dark` style:

demo/saber-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212

1313
// Configure the theme
1414
themeConfig: {
15+
projects: 'pinned-repos',
1516
style: 'dark',
1617
github: 'egoist',
1718
twitter: '_egoistlily',

packages/saber-theme-portfolio/src/saber-node.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const axios = require('axios')
22

33
exports.beforePlugins = async function() {
4-
const { github } = this.config.themeConfig
4+
const { github, projects } = this.config.themeConfig
5+
const usePinnedRepos = projects === 'pinned-repos'
6+
57
this.log.info(`Fetching GitHub data for ${github}..`)
68
const [userResult, projectsResult] = await Promise.all([
79
axios({
@@ -10,7 +12,9 @@ exports.beforePlugins = async function() {
1012
}),
1113
axios({
1214
method: 'GET',
13-
url: `https://api.github.com/search/repositories?q=user:${github}&sort:stars&per_page=6`
15+
url: usePinnedRepos
16+
? `https://gh-pinned-repos.now.sh/?username=${github}`
17+
: `https://api.github.com/search/repositories?q=user:${github}&sort:stars&per_page=6`
1418
})
1519
])
1620

@@ -27,18 +31,30 @@ exports.beforePlugins = async function() {
2731
this.config.themeConfig = Object.assign(
2832
{
2933
hireable: userResult.data.hireable,
30-
profilePicture: userResult.data.avatar_url,
31-
projects: projectsResult.data.items.map(item => {
32-
return {
33-
name: item.name,
34-
url: item.html_url,
35-
description: item.description,
36-
language: item.language,
37-
stars: item.stargazers_count
38-
}
39-
})
34+
profilePicture: userResult.data.avatar_url
4035
},
41-
this.config.themeConfig
36+
this.config.themeConfig,
37+
{
38+
projects: usePinnedRepos
39+
? projectsResult.data.map(item => {
40+
return {
41+
name: item.repo,
42+
url: `https://github.com/${item.owner}/${item.repo}`,
43+
description: item.description,
44+
language: item.language,
45+
stars: item.stars
46+
}
47+
})
48+
: projectsResult.data.items.map(item => {
49+
return {
50+
name: item.name,
51+
url: item.html_url,
52+
description: item.description,
53+
language: item.language,
54+
stars: item.stargazers_count
55+
}
56+
})
57+
}
4258
)
4359
}
4460

0 commit comments

Comments
 (0)