1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-01-03 18:35:00 +01:00

allow adding any repo to repos.yml

This commit is contained in:
Matthias Kretschmann 2019-10-10 00:40:57 +02:00
parent dbc355cdd0
commit b0b5060d37
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 51 additions and 40 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -55,5 +55,6 @@
fill: currentColor;
width: $font-size-mini;
height: $font-size-mini;
margin-right: $spacer / 8;
}
}

View File

@ -98,7 +98,6 @@ a {
&:hover,
&:focus {
color: lighten($brand-cyan, 10%);
transform: translate3d(0, -.1rem, 0);
}
}