From 3ef0ca3a14bba0707b469c4f5f95b0c1965381c8 Mon Sep 17 00:00:00 2001 From: Ariful Alam Date: Fri, 28 Jul 2023 21:21:13 +0600 Subject: [PATCH] Add definition for projects --- gitprofile.config.js | 1 - src/components/GitProfile.jsx | 44 +++++++++++-------- src/helpers/utils.jsx | 22 +++++++--- types/index.d.ts | 81 ++++++++++++++++++++++++----------- 4 files changed, 99 insertions(+), 49 deletions(-) diff --git a/gitprofile.config.js b/gitprofile.config.js index 9ff007a..3a1ba77 100644 --- a/gitprofile.config.js +++ b/gitprofile.config.js @@ -15,7 +15,6 @@ const config = { projects: [], // These projects will not be displayed. example: ['my-project1', 'my-project2'] }, }, - external: { header: 'External Projects', display: true, // Display external projects? diff --git a/src/components/GitProfile.jsx b/src/components/GitProfile.jsx index f00b0d6..0c9d3a8 100644 --- a/src/components/GitProfile.jsx +++ b/src/components/GitProfile.jsx @@ -77,15 +77,15 @@ const GitProfile = ({ config }) => { return; } - sanitizedConfig.github.exclude.projects.forEach((project) => { + sanitizedConfig.projects.github.exclude.projects.forEach((project) => { excludeRepo += `+-repo:${sanitizedConfig.github.username}/${project}`; }); let query = `user:${ sanitizedConfig.github.username - }+fork:${!sanitizedConfig.github.exclude.forks}${excludeRepo}`; + }+fork:${!sanitizedConfig.projects.github.exclude.forks}${excludeRepo}`; - let url = `https://api.github.com/search/repositories?q=${query}&sort=${sanitizedConfig.github.sortBy}&per_page=${sanitizedConfig.github.limit}&type=Repositories`; + let url = `https://api.github.com/search/repositories?q=${query}&sort=${sanitizedConfig.projects.github.sortBy}&per_page=${sanitizedConfig.projects.github.limit}&type=Repositories`; axios .get(url, { @@ -236,13 +236,31 @@ GitProfile.propTypes = { config: PropTypes.shape({ github: PropTypes.shape({ username: PropTypes.string.isRequired, - sortBy: PropTypes.oneOf(['stars', 'updated']), - limit: PropTypes.number, - exclude: PropTypes.shape({ - forks: PropTypes.bool, - projects: PropTypes.array, - }), }).isRequired, + projects: { + github: PropTypes.shape({ + header: PropTypes.string, + display: PropTypes.bool, + sortBy: PropTypes.oneOf(['stars', 'updated']), + limit: PropTypes.number, + exclude: PropTypes.shape({ + forks: PropTypes.bool, + projects: PropTypes.array, + }), + }), + projects: PropTypes.shape({ + header: PropTypes.string, + display: PropTypes.bool, + projects: PropTypes.arrayOf( + PropTypes.shape({ + title: PropTypes.string.isRequired, + description: PropTypes.string.isRequired, + link: PropTypes.string.isRequired, + imageUrl: PropTypes.string, + }) + ), + }), + }, social: PropTypes.shape({ linkedin: PropTypes.string, twitter: PropTypes.string, @@ -265,14 +283,6 @@ GitProfile.propTypes = { fileUrl: PropTypes.string, }), skills: PropTypes.array, - externalProjects: PropTypes.arrayOf( - PropTypes.shape({ - title: PropTypes.string.isRequired, - description: PropTypes.string.isRequired, - link: PropTypes.string.isRequired, - imageUrl: PropTypes.string, - }) - ), experiences: PropTypes.arrayOf( PropTypes.shape({ company: PropTypes.string, diff --git a/src/helpers/utils.jsx b/src/helpers/utils.jsx index a263d7c..9e2777f 100644 --- a/src/helpers/utils.jsx +++ b/src/helpers/utils.jsx @@ -137,11 +137,22 @@ export const sanitizeConfig = (config) => { return { github: { username: config?.github?.username || '', - sortBy: config?.github?.sortBy || 'stars', - limit: config?.github?.limit || 8, - exclude: { - forks: config?.github?.exclude?.forks || false, - projects: config?.github?.exclude?.projects || [], + }, + projects: { + github: { + header: config?.projects?.github?.header || 'GitHub Projects', + display: config?.projects?.github?.display || true, + sortBy: config?.projects?.github?.sortBy || 'stars', + limit: config?.projects?.github?.limit || 8, + exclude: { + forks: config?.projects?.github?.exclude?.forks || false, + projects: config?.projects?.github?.exclude?.projects || [], + }, + }, + external: { + header: config?.projects?.external?.header || 'External Projects', + display: config?.projects?.external?.display || true, + projects: config?.projects?.external?.projects || [], }, }, social: { @@ -166,7 +177,6 @@ export const sanitizeConfig = (config) => { fileUrl: config?.resume?.fileUrl || '', }, skills: config?.skills || [], - externalProjects: config?.externalProjects || [], experiences: config?.experiences || [], certifications: config?.certifications || [], education: config?.education || [], diff --git a/types/index.d.ts b/types/index.d.ts index ce24fd6..5fb1740 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -9,32 +9,63 @@ export interface Github { * GitHub org/user name */ username: string; +} - /** - * stars | updated - */ - sortBy?: string; - - /** - * How many projects to display - */ - limit?: number; - - /** - * Exclude projects option - */ - exclude?: { +export interface Projects { + github: { /** - * Forked projects will not be displayed if set to true + * Header Title */ - forks?: boolean; + header?: string; /** - * These projects will not be displayed - * - * example: ['my-project1', 'my-project2'] + * Display GitHub projects? */ - projects?: Array; + display?: boolean; + + /** + * stars | updated + */ + sortBy?: string; + + /** + * How many projects to display + */ + limit?: number; + + /** + * Exclude projects option + */ + exclude?: { + /** + * Forked projects will not be displayed if set to true + */ + forks?: boolean; + + /** + * These projects will not be displayed + * + * example: ['my-project1', 'my-project2'] + */ + projects?: Array; + }; + }; + + external: { + /** + * Header Title + */ + header?: string; + + /** + * Display external projects? + */ + display?: boolean; + + /** + * External Projects + */ + projects?: Array; }; } @@ -265,6 +296,11 @@ export interface Config { */ github: Github; + /** + * Projects + */ + projects?: Projects; + /** * Social links */ @@ -285,11 +321,6 @@ export interface Config { */ experiences?: Array; - /** - * External Projects - */ - externalProjects?: Array; - /** * Certifications list */