Skip to content

Commit

Permalink
feat: support using GitHub pinned repositories (#8)
Browse files Browse the repository at this point in the history
* feat: support using GitHub pinned repository as the project

* f

* project -> projects

* project -> projects

* project -> projects

* Update saber-node.js
  • Loading branch information
sinchang authored and egoist committed May 29, 2019
1 parent deae684 commit 7a4e90a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ module.exports = {

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

### Projects

By default we fetch your top 6 starred repositories from GitHub, if set to `pinned-project`, it will use pinned repositories instead:

```js
module.exports = {
themeConfig: {
projects: 'pinned-repos'
}
}
```

### Style

By default it uses `dark` style:
Expand Down
1 change: 1 addition & 0 deletions demo/saber-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {

// Configure the theme
themeConfig: {
projects: 'pinned-repos',
style: 'dark',
github: 'egoist',
twitter: '_egoistlily',
Expand Down
42 changes: 29 additions & 13 deletions packages/saber-theme-portfolio/src/saber-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const axios = require('axios')

exports.beforePlugins = async function() {
const { github } = this.config.themeConfig
const { github, projects } = this.config.themeConfig
const usePinnedRepos = projects === 'pinned-repos'

this.log.info(`Fetching GitHub data for ${github}..`)
const [userResult, projectsResult] = await Promise.all([
axios({
Expand All @@ -10,7 +12,9 @@ exports.beforePlugins = async function() {
}),
axios({
method: 'GET',
url: `https://api.github.com/search/repositories?q=user:${github}&sort:stars&per_page=6`
url: usePinnedRepos
? `https://gh-pinned-repos.now.sh/?username=${github}`
: `https://api.github.com/search/repositories?q=user:${github}&sort:stars&per_page=6`
})
])

Expand All @@ -27,18 +31,30 @@ exports.beforePlugins = async function() {
this.config.themeConfig = Object.assign(
{
hireable: userResult.data.hireable,
profilePicture: userResult.data.avatar_url,
projects: projectsResult.data.items.map(item => {
return {
name: item.name,
url: item.html_url,
description: item.description,
language: item.language,
stars: item.stargazers_count
}
})
profilePicture: userResult.data.avatar_url
},
this.config.themeConfig
this.config.themeConfig,
{
projects: usePinnedRepos
? projectsResult.data.map(item => {
return {
name: item.repo,
url: `https://github.com/${item.owner}/${item.repo}`,
description: item.description,
language: item.language,
stars: item.stars
}
})
: projectsResult.data.items.map(item => {
return {
name: item.name,
url: item.html_url,
description: item.description,
language: item.language,
stars: item.stargazers_count
}
})
}
)
}

Expand Down

0 comments on commit 7a4e90a

Please sign in to comment.