Skip to content

Commit

Permalink
Prettified Code!
Browse files Browse the repository at this point in the history
  • Loading branch information
diogotcorreia authored and actions-user committed Jan 10, 2024
1 parent 3ec5e22 commit bf3effb
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 56 deletions.
4 changes: 2 additions & 2 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ module.exports = {
{ key: 'archive', name: '📥 Arquivo' },
],
github: {
owner: "leic-pt",
repository: "resumos-leic",
owner: 'leic-pt',
repository: 'resumos-leic',
},
navbar: {
siteTitle: 'Resumos LEIC-A',
Expand Down
42 changes: 22 additions & 20 deletions plugins/gatsby-source-github-contributors/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
const { graphql } = require("@octokit/graphql");
const { graphql } = require('@octokit/graphql');

// mutates `contributors`
function mergeContributors(contributors, pullRequests) {
pullRequests.filter(({author}) => !!author.login).forEach(({author, labels}) => {
const { name, login } = author;
const contributor = contributors[login] || (contributors[login] = {});
const labelSet = contributor.labels || (contributor.labels = new Set());
pullRequests
.filter(({ author }) => !!author.login)
.forEach(({ author, labels }) => {
const { name, login } = author;
const contributor = contributors[login] || (contributors[login] = {});
const labelSet = contributor.labels || (contributor.labels = new Set());

labels.nodes.filter(label => !!label.name).forEach(label => labelSet.add(label.name));
labels.nodes.filter((label) => !!label.name).forEach((label) => labelSet.add(label.name));

if (!contributor.name) {
contributor.name = name;
}
})
if (!contributor.name) {
contributor.name = name;
}
});
}

exports.sourceNodes = async ({
Expand All @@ -22,18 +24,18 @@ exports.sourceNodes = async ({
createNodeId,
getNodesByType,
}) => {
const { createNode, touchNode } = actions
const { createNode, touchNode } = actions;

const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) {
console.info("No GitHub token found (GITHUB_TOKEN env var), skipping contributors list");
console.info('No GitHub token found (GITHUB_TOKEN env var), skipping contributors list');
return;
}

const graphqlGh = graphql.defaults({
headers: {
authorization: `bearer ${githubToken}`,
}
},
});

const contributors = {};
Expand All @@ -42,8 +44,8 @@ exports.sourceNodes = async ({
// const lastUpdated = await cache.get("lastUpdated")
// // 30 days cache
// if (lastUpdated > Date.now() - 1000 * 60 * 60 * 24 * 30) {
// getNodesByType("Space").forEach(node => touchNode(node))
// return
// getNodesByType("Space").forEach(node => touchNode(node))
// return
// }

// await cache.set("lastUpdated", Date.now())
Expand Down Expand Up @@ -75,8 +77,8 @@ exports.sourceNodes = async ({
}
}`);

return repository?.pullRequests
}
return repository?.pullRequests;
};

mergeContributors(contributors, (await getPullRequests(null)).nodes);

Expand All @@ -92,10 +94,10 @@ exports.sourceNodes = async ({
...data,
id: createNodeId(data.username),
internal: {
type: "Contributor",
type: 'Contributor',
content: JSON.stringify(data),
contentDigest: createContentDigest(data),
},
})
});
});
}
};
59 changes: 34 additions & 25 deletions src/components/Contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,48 @@ const Contributors = ({ getLabelName, contributors }) => {
}
`);

const {owner, repository} = data.site.siteMetadata.github;
const { owner, repository } = data.site.siteMetadata.github;

const sortedContributors = useMemo(() => {
return contributors.map(contributor => {
const labels = contributor.labels
return contributors
.map((contributor) => {
const labels = contributor.labels
.map(getLabelName)
.filter(Boolean)
.map(label => ({ label, bold: false }));
return {
username: contributor.username,
name: contributor.name,
labels,
boldCount: labels.filter(({bold}) => bold).length,
}
})
.sort((a,b) => a.name.localeCompare(b.name))
.sort((a,b) => b.boldCount - a.boldCount)
.sort((a,b) => b.labels.length - a.labels.length)
}, [contributors, getLabelName])
.map((label) => ({ label, bold: false }));
return {
username: contributor.username,
name: contributor.name,
labels,
boldCount: labels.filter(({ bold }) => bold).length,
};
})
.sort((a, b) => a.name.localeCompare(b.name))
.sort((a, b) => b.boldCount - a.boldCount)
.sort((a, b) => b.labels.length - a.labels.length);
}, [contributors, getLabelName]);

return (
<ul>
{sortedContributors.map(contributor => (
{sortedContributors.map((contributor) => (
<li key={contributor.username}>
<a href={`https://github.com/${owner}/${repository}/commits?author=${encodeURIComponent(contributor.username)}`}
target="_blank" rel="nofollow noopener noreferrer">
{contributor.name}</a>
{' ('}{contributor.labels.map(({label, bold}, index) => (
<>
{index > 0 && ', '}
{bold ? (<strong>{label}</strong>) : label}
</>
))})
<a
href={`https://github.com/${owner}/${repository}/commits?author=${encodeURIComponent(
contributor.username
)}`}
target='_blank'
rel='nofollow noopener noreferrer'
>
{contributor.name}
</a>
{' ('}
{contributor.labels.map(({ label, bold }, index) => (
<>
{index > 0 && ', '}
{bold ? <strong>{label}</strong> : label}
</>
))}
)
</li>
))}
</ul>
Expand Down
21 changes: 12 additions & 9 deletions src/components/HomePageLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ import Contributors from './Contributors';
const HomePageLayout = ({ data }) => {
const { markdownRemark: page, allContributor: contributors } = data;

const getLabelName = useCallback((label) => {
const { years } = page.frontmatter;
const getLabelName = useCallback(
(label) => {
const { years } = page.frontmatter;

for (const year of years) {
for (const semester of year.semesters) {
for (const course of semester.courses) {
if (course.link === `/${label}`) {
return course.name;
for (const year of years) {
for (const semester of year.semesters) {
for (const course of semester.courses) {
if (course.link === `/${label}`) {
return course.name;
}
}
}
}
}
}, [page.frontmatter.years]);
},
[page.frontmatter.years]
);

return (
<div className='home-page-container'>
Expand Down

0 comments on commit bf3effb

Please sign in to comment.