mirror of
https://github.com/kremalicious/portfolio.git
synced 2024-12-23 01:29:41 +01:00
Merge pull request #171 from kremalicious/feature/org-repos
allow adding any repo to repos.yml
This commit is contained in:
commit
05947fc76c
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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 (
|
||||
<div className={styles.repo}>
|
||||
<h1 className={styles.repoTitle}>
|
||||
<a href={repoLink}>{name}</a>
|
||||
<a href={repoLink}>{isExternal ? full_name : name}</a>
|
||||
</h1>
|
||||
<p>{description}</p>
|
||||
<p className={styles.meta}>
|
||||
{name === 'portfolio' || name === 'blog'
|
||||
? null
|
||||
: homepage && (
|
||||
: !isExternal &&
|
||||
homepage && (
|
||||
<a href={homepage}>
|
||||
<LinkIcon title="website" /> Release post
|
||||
<LinkIcon title="website" /> More info
|
||||
</a>
|
||||
)}
|
||||
|
||||
@ -41,5 +53,3 @@ const Repository = ({ repo }) => {
|
||||
Repository.propTypes = {
|
||||
repo: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
export default Repository
|
||||
|
@ -55,5 +55,6 @@
|
||||
fill: currentColor;
|
||||
width: $font-size-mini;
|
||||
height: $font-size-mini;
|
||||
margin-right: $spacer / 8;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ describe('Repository', () => {
|
||||
it('uses html_url as main link for portfolio & blog', () => {
|
||||
const repo1 = {
|
||||
name: 'portfolio',
|
||||
full_name: 'kremalicious/portfolio',
|
||||
html_url: 'html_url'
|
||||
}
|
||||
|
||||
@ -24,6 +25,7 @@ describe('Repository', () => {
|
||||
it('renders homepage link when provided', () => {
|
||||
const repo = {
|
||||
name: 'Hello',
|
||||
full_name: 'kremalicious/hello',
|
||||
homepage: 'hello'
|
||||
}
|
||||
|
||||
@ -32,7 +34,7 @@ describe('Repository', () => {
|
||||
})
|
||||
|
||||
it('renders no link without homepage', () => {
|
||||
const repo = { name: 'Hello' }
|
||||
const repo = { name: 'Hello', full_name: 'repo/hello' }
|
||||
|
||||
const { container } = render(<Repository repo={repo} />)
|
||||
expect(container.querySelectorAll('p:last-child a').length).toBe(2)
|
||||
|
@ -19,7 +19,8 @@ describe('Home', () => {
|
||||
const pageContext = {
|
||||
repos: [
|
||||
{
|
||||
name: 'Hello'
|
||||
name: 'hello',
|
||||
full_name: 'kremalicious/hello'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -98,7 +98,6 @@ a {
|
||||
&:hover,
|
||||
&:focus {
|
||||
color: lighten($brand-cyan, 10%);
|
||||
transform: translate3d(0, -.1rem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user