From b0b5060d3781a9f2c60fe55dbc95619b8ff48d88 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 10 Oct 2019 00:40:57 +0200 Subject: [PATCH] allow adding any repo to repos.yml --- content/repos.yml | 20 ++++----- gatsby-node.js | 43 ++++++++++--------- src/components/molecules/Repository.jsx | 26 +++++++---- .../molecules/Repository.module.scss | 1 + src/styles/global.scss | 1 - 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/content/repos.yml b/content/repos.yml index ba76f49..1695222 100644 --- a/content/repos.yml +++ b/content/repos.yml @@ -1,10 +1,10 @@ -- user: kremalicious - repos: - - portfolio - - blog - - blowfish - - gatsby-plugin-matomo - - gatsby-redirect-from - - hyper-mac-pro - - appstorebadges - - kbdfun +- kremalicious/portfolio +- kremalicious/blog +- kremalicious/blowfish +- kremalicious/gatsby-plugin-matomo +- kremalicious/gatsby-redirect-from +- kremalicious/hyper-mac-pro +- kremalicious/appstorebadges +- kremalicious/kbdfun +- oceanprotocol/commons +- oceanprotocol/squid-js diff --git a/gatsby-node.js b/gatsby-node.js index 625cb7f..20f573d 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -27,31 +27,32 @@ function truncate(n, useWordBoundary) { // Get GitHub repos // async function getGithubRepos(data) { - const allRepos = await axios.get( - `https://api.github.com/users/${data.user}/repos?per_page=100`, - { headers: { 'User-Agent': 'kremalicious/portfolio' } } - ) - const repos = allRepos.data - // filter by what's defined in content/repos.yml - .filter(({ name }) => data.repos.includes(name)) - // sort by pushed to, newest first - .sort((a, b) => b.pushed_at.localeCompare(a.pushed_at)) - - // reduce data output by reconstructing repo objects - const reposReduced = [] + let repos = [] let holder = {} - for (let repo of repos) { - holder.name = repo.name - holder.description = repo.description - holder.html_url = repo.html_url - holder.homepage = repo.homepage - holder.stargazers_count = repo.stargazers_count - reposReduced.push(holder) + for (let item of data) { + const user = item.split('/')[0] + const repoName = item.split('/')[1] + const repo = await axios.get( + `https://api.github.com/repos/${user}/${repoName}`, + { headers: { 'User-Agent': 'kremalicious/portfolio' } } + ) + + holder.name = repo.data.name + holder.full_name = repo.data.full_name + holder.description = repo.data.description + holder.html_url = repo.data.html_url + holder.homepage = repo.data.homepage + holder.stargazers_count = repo.data.stargazers_count + holder.pushed_at = repo.data.pushed_at + repos.push(holder) holder = {} } - return reposReduced + // sort by pushed to, newest first + repos = repos.sort((a, b) => b.pushed_at.localeCompare(a.pushed_at)) + + return repos } // @@ -63,7 +64,7 @@ exports.onPreBootstrap = async () => { const t0 = performance.now() try { - repos = await getGithubRepos(reposYaml[0]) + repos = await getGithubRepos(reposYaml) const t1 = performance.now() const ms = t1 - t0 const s = ((ms / 1000) % 60).toFixed(3) diff --git a/src/components/molecules/Repository.jsx b/src/components/molecules/Repository.jsx index f4df29d..0b5a2f0 100644 --- a/src/components/molecules/Repository.jsx +++ b/src/components/molecules/Repository.jsx @@ -3,26 +3,38 @@ import PropTypes from 'prop-types' import LinkIcon from '../atoms/LinkIcon' import styles from './Repository.module.scss' -const Repository = ({ repo }) => { - const { name, description, html_url, homepage, stargazers_count } = repo +export default function Repository({ repo }) { + const { + name, + full_name, + description, + html_url, + homepage, + stargazers_count + } = repo + + const isExternal = !full_name.includes('kremalicious') // for blog & portfolio and if there's no homepage, use github url // else use homepage field const repoLink = - name === 'blog' || name === 'portfolio' || !homepage ? html_url : homepage + name === 'blog' || name === 'portfolio' || !homepage || isExternal + ? html_url + : homepage return (

- {name} + {isExternal ? full_name : name}

{description}

{name === 'portfolio' || name === 'blog' ? null - : homepage && ( + : !isExternal && + homepage && ( - Release post + More info )} @@ -41,5 +53,3 @@ const Repository = ({ repo }) => { Repository.propTypes = { repo: PropTypes.object.isRequired } - -export default Repository diff --git a/src/components/molecules/Repository.module.scss b/src/components/molecules/Repository.module.scss index 5d335ed..1fb3941 100644 --- a/src/components/molecules/Repository.module.scss +++ b/src/components/molecules/Repository.module.scss @@ -55,5 +55,6 @@ fill: currentColor; width: $font-size-mini; height: $font-size-mini; + margin-right: $spacer / 8; } } diff --git a/src/styles/global.scss b/src/styles/global.scss index 289bcbb..da57028 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -98,7 +98,6 @@ a { &:hover, &:focus { color: lighten($brand-cyan, 10%); - transform: translate3d(0, -.1rem, 0); } }