From e5cfa31a2d804892c5384bbdfd87fa9db3c47267 Mon Sep 17 00:00:00 2001 From: Yuuki Takahashi <20282867+yktakaha4@users.noreply.github.com> Date: Tue, 20 Feb 2024 23:46:29 +0900 Subject: [PATCH] add tags --- src/components/OSSContributions.spec.tsx | 1 + src/components/OSSContributions.tsx | 17 +- .../OSSContributions.spec.tsx.snap | 406 +++++++++++++++++- src/components/data/ossContributions.json | 78 +++- src/components/data/techArticles.json | 2 +- src/components/ui/Tag.tsx | 13 +- src/constants.ts | 30 ++ src/css/custom.css | 1 + src/services/ossContributions.spec.ts | 16 +- src/services/ossContributions.ts | 8 +- src/services/sns/data/gitHubPullRequests.json | 12 +- src/services/sns/data/zennArticles.json | 2 +- 12 files changed, 551 insertions(+), 35 deletions(-) diff --git a/src/components/OSSContributions.spec.tsx b/src/components/OSSContributions.spec.tsx index 62cd3bd8..b80f7a2f 100644 --- a/src/components/OSSContributions.spec.tsx +++ b/src/components/OSSContributions.spec.tsx @@ -17,6 +17,7 @@ jest.mock('@/components/data/ossContributions.json', () => { url: `https://example.com/user${i}/repo${i}/pull/${i}`, kind: kinds[i % kinds.length], mergedAt: date.toISOString(), + changedLines: 8 * i, repository: { owner: `user${i}`, name: `user${i}/repo${i}`, diff --git a/src/components/OSSContributions.tsx b/src/components/OSSContributions.tsx index 419ce3ce..edcbd3a6 100644 --- a/src/components/OSSContributions.tsx +++ b/src/components/OSSContributions.tsx @@ -5,6 +5,7 @@ import { TableHeaders, TableRow } from '@/components/ui/Table'; import { getOssContributionIcon, getOSSContributionKindName, + getOSSContributionSizeKindName, } from '@/constants'; import { SearchableTable } from '@/components/ui/SearchableTable'; @@ -18,17 +19,17 @@ export const OSSContributions: FC = () => { { label: 'タイトル', align: 'left', - width: '40%', + width: '35%', }, { label: 'リポジトリ', align: 'left', - width: '40%', + width: '35%', }, { label: 'タグ', align: 'left', - width: '10%', + width: '20%', }, ]; @@ -75,6 +76,16 @@ export const OSSContributions: FC = () => { value: getOSSContributionKindName(item.kind), color: 'primary', }, + { + icon: 'prChanges', + value: getOSSContributionSizeKindName(item.changedLines), + color: 'secondary', + }, + { + icon: 'star', + value: item.repository.stars.toLocaleString(), + color: 'warning', + }, ], }, ]; diff --git a/src/components/__snapshots__/OSSContributions.spec.tsx.snap b/src/components/__snapshots__/OSSContributions.spec.tsx.snap index ba60ca4e..b409da10 100644 --- a/src/components/__snapshots__/OSSContributions.spec.tsx.snap +++ b/src/components/__snapshots__/OSSContributions.spec.tsx.snap @@ -120,17 +120,17 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 日付 タイトル リポジトリ タグ @@ -187,6 +187,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + XS +
+
+ + + + 0 +
@@ -240,6 +280,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + XS +
+
+ + + + 123 +
@@ -293,6 +373,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 246 +
@@ -346,6 +466,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 369 +
@@ -399,6 +559,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 492 +
@@ -452,6 +652,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 615 +
@@ -505,6 +745,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 738 +
@@ -558,6 +838,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 861 +
@@ -611,6 +931,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 984 +
@@ -664,6 +1024,46 @@ exports[`OSSContributions スナップショットテスト OSS活動が描画 PRマージ +
+ + + + S +
+
+ + + + 1,107 +
diff --git a/src/components/data/ossContributions.json b/src/components/data/ossContributions.json index 9cedb37e..6d722a15 100644 --- a/src/components/data/ossContributions.json +++ b/src/components/data/ossContributions.json @@ -1,14 +1,31 @@ { "contributions": [ + { + "title": "fix: handle none value", + "url": "https://github.com/domainaware/parsedmarc/pull/468", + "kind": "mergedPullRequest", + "mergedAt": "2024-02-19T23:53:52.000Z", + "changedLines": 58, + "repository": { + "owner": "domainaware", + "name": "domainaware/parsedmarc", + "stars": 873, + "url": "https://github.com/domainaware/parsedmarc", + "languages": [ + "Python" + ] + } + }, { "title": "Fix description of diff suppress option", "url": "https://github.com/databus23/helm-diff/pull/491", "kind": "mergedPullRequest", "mergedAt": "2024-01-09T00:06:13.000Z", + "changedLines": 4, "repository": { "owner": "databus23", "name": "databus23/helm-diff", - "stars": 2426, + "stars": 2429, "url": "https://github.com/databus23/helm-diff", "languages": [ "Go" @@ -20,10 +37,11 @@ "url": "https://github.com/hashicorp/terraform-provider-aws/pull/34312", "kind": "mergedPullRequest", "mergedAt": "2023-11-08T15:31:58.000Z", + "changedLines": 4, "repository": { "owner": "hashicorp", "name": "hashicorp/terraform-provider-aws", - "stars": 9318, + "stars": 9326, "url": "https://github.com/hashicorp/terraform-provider-aws", "languages": [ "Go" @@ -35,10 +53,11 @@ "url": "https://github.com/aws/aws-eks-best-practices/pull/398", "kind": "mergedPullRequest", "mergedAt": "2023-10-16T22:30:15.000Z", + "changedLines": 4, "repository": { "owner": "aws", "name": "aws/aws-eks-best-practices", - "stars": 1767, + "stars": 1769, "url": "https://github.com/aws/aws-eks-best-practices", "languages": [ "Python" @@ -50,10 +69,11 @@ "url": "https://github.com/helmfile/helmfile/pull/1019", "kind": "mergedPullRequest", "mergedAt": "2023-09-14T02:23:42.000Z", + "changedLines": 73, "repository": { "owner": "helmfile", "name": "helmfile/helmfile", - "stars": 2977, + "stars": 2983, "url": "https://github.com/helmfile/helmfile", "languages": [ "Go" @@ -65,10 +85,11 @@ "url": "https://github.com/hashicorp/terraform-provider-aws/pull/27604", "kind": "mergedPullRequest", "mergedAt": "2023-06-16T18:36:43.000Z", + "changedLines": 52, "repository": { "owner": "hashicorp", "name": "hashicorp/terraform-provider-aws", - "stars": 9318, + "stars": 9326, "url": "https://github.com/hashicorp/terraform-provider-aws", "languages": [ "Go" @@ -80,6 +101,7 @@ "url": "https://github.com/ebitengine/ebitengine.org/pull/17", "kind": "mergedPullRequest", "mergedAt": "2023-05-06T15:52:27.000Z", + "changedLines": 8, "repository": { "owner": "ebitengine", "name": "ebitengine/ebitengine.org", @@ -95,6 +117,7 @@ "url": "https://github.com/cloudflare/terraform-provider-cloudflare/pull/2298", "kind": "mergedPullRequest", "mergedAt": "2023-03-20T00:16:43.000Z", + "changedLines": 62, "repository": { "owner": "cloudflare", "name": "cloudflare/terraform-provider-cloudflare", @@ -110,10 +133,11 @@ "url": "https://github.com/FairwindsOps/pluto/pull/457", "kind": "mergedPullRequest", "mergedAt": "2023-02-22T21:11:40.000Z", + "changedLines": 45, "repository": { "owner": "FairwindsOps", "name": "FairwindsOps/pluto", - "stars": 1907, + "stars": 1909, "url": "https://github.com/FairwindsOps/pluto", "languages": [ "Go" @@ -125,10 +149,11 @@ "url": "https://github.com/FairwindsOps/pluto/pull/452", "kind": "mergedPullRequest", "mergedAt": "2023-02-21T21:43:57.000Z", + "changedLines": 441, "repository": { "owner": "FairwindsOps", "name": "FairwindsOps/pluto", - "stars": 1907, + "stars": 1909, "url": "https://github.com/FairwindsOps/pluto", "languages": [ "Go" @@ -140,10 +165,11 @@ "url": "https://github.com/FairwindsOps/pluto/pull/448", "kind": "mergedPullRequest", "mergedAt": "2023-02-04T13:57:01.000Z", + "changedLines": 1, "repository": { "owner": "FairwindsOps", "name": "FairwindsOps/pluto", - "stars": 1907, + "stars": 1909, "url": "https://github.com/FairwindsOps/pluto", "languages": [ "Go" @@ -155,6 +181,7 @@ "url": "https://github.com/argoproj/argo-workflows/pull/10421", "kind": "mergedPullRequest", "mergedAt": "2023-02-01T16:10:20.000Z", + "changedLines": 35, "repository": { "owner": "argoproj", "name": "argoproj/argo-workflows", @@ -170,6 +197,7 @@ "url": "https://github.com/liamg/memoryfs/pull/19", "kind": "mergedPullRequest", "mergedAt": "2023-01-24T09:41:11.000Z", + "changedLines": 68, "repository": { "owner": "liamg", "name": "liamg/memoryfs", @@ -185,6 +213,7 @@ "url": "https://github.com/liamg/memoryfs/pull/18", "kind": "mergedPullRequest", "mergedAt": "2023-01-24T09:37:42.000Z", + "changedLines": 63, "repository": { "owner": "liamg", "name": "liamg/memoryfs", @@ -200,6 +229,7 @@ "url": "https://github.com/liamg/memoryfs/pull/17", "kind": "mergedPullRequest", "mergedAt": "2022-11-07T11:05:07.000Z", + "changedLines": 172, "repository": { "owner": "liamg", "name": "liamg/memoryfs", @@ -215,10 +245,11 @@ "url": "https://github.com/python-social-auth/social-core/pull/707", "kind": "mergedPullRequest", "mergedAt": "2022-08-26T06:41:12.000Z", + "changedLines": 183, "repository": { "owner": "python-social-auth", "name": "python-social-auth/social-core", - "stars": 805, + "stars": 807, "url": "https://github.com/python-social-auth/social-core", "languages": [ "Python" @@ -230,6 +261,7 @@ "url": "https://github.com/python-social-auth/social-docs/pull/116", "kind": "mergedPullRequest", "mergedAt": "2022-08-26T06:40:14.000Z", + "changedLines": 5, "repository": { "owner": "python-social-auth", "name": "python-social-auth/social-docs", @@ -245,10 +277,11 @@ "url": "https://github.com/python-social-auth/social-core/pull/698", "kind": "mergedPullRequest", "mergedAt": "2022-08-26T06:40:07.000Z", + "changedLines": 104, "repository": { "owner": "python-social-auth", "name": "python-social-auth/social-core", - "stars": 805, + "stars": 807, "url": "https://github.com/python-social-auth/social-core", "languages": [ "Python" @@ -260,10 +293,11 @@ "url": "https://github.com/hashicorp/terraform-provider-aws/pull/26057", "kind": "mergedPullRequest", "mergedAt": "2022-08-01T17:37:58.000Z", + "changedLines": 226, "repository": { "owner": "hashicorp", "name": "hashicorp/terraform-provider-aws", - "stars": 9318, + "stars": 9326, "url": "https://github.com/hashicorp/terraform-provider-aws", "languages": [ "Go" @@ -275,6 +309,7 @@ "url": "https://github.com/localstack/docs/pull/178", "kind": "mergedPullRequest", "mergedAt": "2022-06-05T11:26:58.000Z", + "changedLines": 10, "repository": { "owner": "localstack", "name": "localstack/docs", @@ -290,6 +325,7 @@ "url": "https://github.com/showwin/kintai-paccho/pull/23", "kind": "mergedPullRequest", "mergedAt": "2022-04-18T01:53:00.000Z", + "changedLines": 908, "repository": { "owner": "showwin", "name": "showwin/kintai-paccho", @@ -305,6 +341,7 @@ "url": "https://github.com/showwin/kintai-paccho/pull/22", "kind": "mergedPullRequest", "mergedAt": "2022-04-15T01:46:36.000Z", + "changedLines": 1630, "repository": { "owner": "showwin", "name": "showwin/kintai-paccho", @@ -320,6 +357,7 @@ "url": "https://github.com/elwerene/libreoffice-convert/pull/77", "kind": "mergedPullRequest", "mergedAt": "2022-03-29T09:34:01.000Z", + "changedLines": 1731, "repository": { "owner": "elwerene", "name": "elwerene/libreoffice-convert", @@ -335,6 +373,7 @@ "url": "https://github.com/kawamataryo/chikamichi/pull/71", "kind": "mergedPullRequest", "mergedAt": "2022-03-10T00:30:26.000Z", + "changedLines": 20, "repository": { "owner": "kawamataryo", "name": "kawamataryo/chikamichi", @@ -351,6 +390,7 @@ "url": "https://github.com/showwin/kintai-paccho/pull/15", "kind": "mergedPullRequest", "mergedAt": "2021-12-24T07:03:01.000Z", + "changedLines": 1, "repository": { "owner": "showwin", "name": "showwin/kintai-paccho", @@ -366,6 +406,7 @@ "url": "https://github.com/doc1oo/LovelyComposerDocs/pull/1", "kind": "mergedPullRequest", "mergedAt": "2021-12-20T15:32:31.000Z", + "changedLines": 2, "repository": { "owner": "doc1oo", "name": "doc1oo/LovelyComposerDocs", @@ -381,10 +422,11 @@ "url": "https://github.com/Rigellute/spotify-tui/pull/778", "kind": "mergedPullRequest", "mergedAt": "2021-04-26T12:17:01.000Z", + "changedLines": 2, "repository": { "owner": "Rigellute", "name": "Rigellute/spotify-tui", - "stars": 16298, + "stars": 16310, "url": "https://github.com/Rigellute/spotify-tui", "languages": [ "Rust" @@ -396,10 +438,11 @@ "url": "https://github.com/typeorm/typeorm/pull/7116", "kind": "mergedPullRequest", "mergedAt": "2021-01-11T13:00:54.000Z", + "changedLines": 5, "repository": { "owner": "typeorm", "name": "typeorm/typeorm", - "stars": 32936, + "stars": 32947, "url": "https://github.com/typeorm/typeorm", "languages": [ "TypeScript" @@ -411,10 +454,11 @@ "url": "https://github.com/serverless/serverless/pull/8420", "kind": "mergedPullRequest", "mergedAt": "2020-10-27T20:12:24.000Z", + "changedLines": 1, "repository": { "owner": "serverless", "name": "serverless/serverless", - "stars": 45860, + "stars": 45865, "url": "https://github.com/serverless/serverless", "languages": [ "JavaScript" @@ -426,6 +470,7 @@ "url": "https://github.com/amazon-connect/amazon-connect-streams/pull/265", "kind": "mergedPullRequest", "mergedAt": "2020-08-14T18:03:42.000Z", + "changedLines": 15, "repository": { "owner": "amazon-connect", "name": "amazon-connect/amazon-connect-streams", @@ -441,10 +486,11 @@ "url": "https://github.com/getmoto/moto/pull/3208", "kind": "mergedPullRequest", "mergedAt": "2020-08-03T14:09:25.000Z", + "changedLines": 33, "repository": { "owner": "getmoto", "name": "getmoto/moto", - "stars": 7273, + "stars": 7276, "url": "https://github.com/getmoto/moto", "languages": [ "Python" @@ -456,6 +502,7 @@ "url": "https://github.com/typescript-book-ja/typescript-book-jp/pull/126", "kind": "mergedPullRequest", "mergedAt": "2020-07-18T07:13:16.000Z", + "changedLines": 2, "repository": { "owner": "typescript-book-ja", "name": "typescript-book-ja/typescript-book-jp", @@ -471,6 +518,7 @@ "url": "https://github.com/championswimmer/vuex-module-decorators/pull/248", "kind": "mergedPullRequest", "mergedAt": "2020-04-25T00:52:08.000Z", + "changedLines": 4, "repository": { "owner": "championswimmer", "name": "championswimmer/vuex-module-decorators", diff --git a/src/components/data/techArticles.json b/src/components/data/techArticles.json index 008dd5e1..de74ba77 100644 --- a/src/components/data/techArticles.json +++ b/src/components/data/techArticles.json @@ -27,7 +27,7 @@ "title": "CSRF(Cross-Site Request Forgery)攻撃について", "url": "https://zenn.dev/yktakaha4/articles/study_csrf_attack", "publishedAt": "2022-10-30T13:41:45.651Z", - "likes": 191, + "likes": 192, "publisher": "zenn", "tags": [ "CSRF", diff --git a/src/components/ui/Tag.tsx b/src/components/ui/Tag.tsx index a7577d11..a3fd29e5 100644 --- a/src/components/ui/Tag.tsx +++ b/src/components/ui/Tag.tsx @@ -1,8 +1,13 @@ import { CSSProperties, FC } from 'react'; import { FaHeart } from 'react-icons/fa'; -import { FaCodeMerge, FaNewspaper } from 'react-icons/fa6'; +import { + FaCodeMerge, + FaNewspaper, + FaRegFileCode, + FaStar, +} from 'react-icons/fa6'; -export type Icon = 'heart' | 'publisher' | 'prMerge'; +export type Icon = 'heart' | 'publisher' | 'prMerge' | 'prChanges' | 'star'; export type TagColor = | 'primary' @@ -31,6 +36,10 @@ const createIcon = (icon: Icon) => { return ; case 'prMerge': return ; + case 'prChanges': + return ; + case 'star': + return ; } }; diff --git a/src/constants.ts b/src/constants.ts index b2a0f24a..e4e89286 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -40,6 +40,36 @@ export const getOssContributionIcon = ( } }; +export type OSSContributionSizeKind = 'xs' | 's' | 'm' | 'l' | 'xl'; +const OSSContributionSizeKindName: { + [key in OSSContributionSizeKind]: string; +} = { + xs: 'XS', + s: 'S', + m: 'M', + l: 'L', + xl: 'XL', +} as const; +export const getOssContributionSizeKind = ( + lines: number, +): OSSContributionSizeKind => { + if (lines < 10) { + return 'xs'; + } else if (lines < 100) { + return 's'; + } else if (lines < 500) { + return 'm'; + } else if (lines < 1000) { + return 'l'; + } else { + return 'xl'; + } +}; +export const getOSSContributionSizeKindName = (lines: number) => { + const kind = getOssContributionSizeKind(lines); + return OSSContributionSizeKindName[kind]; +}; + const snsDataBasePath = `${__dirname}/services/sns/data`; export type SNSData = | 'gitHubPullRequests' diff --git a/src/css/custom.css b/src/css/custom.css index 7f7c6bce..7cbbf40e 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -2,6 +2,7 @@ --ifm-table-border-width: 0; --ifm-table-cell-padding: 0.3rem; --ifm-footer-background-color: transparent; + --ifm-color-warning: #ff8800; } .capy--mobile-only { diff --git a/src/services/ossContributions.spec.ts b/src/services/ossContributions.spec.ts index 3ed7800c..bc9d48e2 100644 --- a/src/services/ossContributions.spec.ts +++ b/src/services/ossContributions.spec.ts @@ -31,6 +31,7 @@ describe('sortOSSContributions', () => { mergedAt: new Date(), url: 'https://dummy.com', kind: 'mergedPullRequest', + changedLines: 0, repository: { owner: 'dummy', name: 'dummy', @@ -44,19 +45,28 @@ describe('sortOSSContributions', () => { { ...defaultValues, title: 'dummy1', + changedLines: 10, mergedAt: new Date('2021-01-01'), }, { ...defaultValues, title: 'dummy2', + changedLines: 20, + mergedAt: new Date('2021-01-02'), + }, + { + ...defaultValues, + title: 'dummy3', + changedLines: 30, mergedAt: new Date('2021-01-02'), }, ]; const sorted = sortOSSContributions(contributions); - expect(sorted.length).toBe(2); - expect(sorted[0].title).toBe('dummy2'); - expect(sorted[1].title).toBe('dummy1'); + expect(sorted.length).toBe(3); + expect(sorted[0].title).toBe('dummy3'); + expect(sorted[1].title).toBe('dummy2'); + expect(sorted[2].title).toBe('dummy1'); expect(sorted).not.toEqual(contributions); }); diff --git a/src/services/ossContributions.ts b/src/services/ossContributions.ts index 3b97eba7..a99429f4 100644 --- a/src/services/ossContributions.ts +++ b/src/services/ossContributions.ts @@ -15,6 +15,7 @@ export type OSSContribution = { mergedAt: Date; url: string; kind: OSSContributionKind; + changedLines: number; repository: { owner: string; name: string; @@ -47,6 +48,7 @@ export const getOSSContributions = () => { url: permalink, kind: 'mergedPullRequest', mergedAt: dayjs(mergedAt).toDate(), + changedLines: (node.additions || 0) + (node.deletions || 0), repository: { owner: owner.login, name: nameWithOwner, @@ -70,7 +72,11 @@ export const getOSSContributions = () => { export const sortOSSContributions = (contributions: Array) => { return [...contributions].sort((lhs, rhs) => { - return rhs.mergedAt.getTime() - lhs.mergedAt.getTime(); + if (rhs.mergedAt.getTime() === lhs.mergedAt.getTime()) { + return rhs.changedLines - lhs.changedLines; + } else { + return rhs.mergedAt.getTime() - lhs.mergedAt.getTime(); + } }); }; diff --git a/src/services/sns/data/gitHubPullRequests.json b/src/services/sns/data/gitHubPullRequests.json index 0204c589..6b1c054b 100644 --- a/src/services/sns/data/gitHubPullRequests.json +++ b/src/services/sns/data/gitHubPullRequests.json @@ -2348,14 +2348,14 @@ "name": "Go", "color": "#00ADD8" }, - "size": 55379775 + "size": 55380835 }, { "node": { "name": "HCL", "color": "#844FBA" }, - "size": 22872 + "size": 22871 }, { "node": { @@ -2911,14 +2911,14 @@ "name": "Go", "color": "#00ADD8" }, - "size": 55379775 + "size": 55380835 }, { "node": { "name": "HCL", "color": "#844FBA" }, - "size": 22872 + "size": 22871 }, { "node": { @@ -3324,14 +3324,14 @@ "name": "Go", "color": "#00ADD8" }, - "size": 55379775 + "size": 55380835 }, { "node": { "name": "HCL", "color": "#844FBA" }, - "size": 22872 + "size": 22871 }, { "node": { diff --git a/src/services/sns/data/zennArticles.json b/src/services/sns/data/zennArticles.json index 3e5b82fd..62accc80 100644 --- a/src/services/sns/data/zennArticles.json +++ b/src/services/sns/data/zennArticles.json @@ -342,7 +342,7 @@ "title": "CSRF(Cross-Site Request Forgery)攻撃について", "slug": "study_csrf_attack", "comments_count": 2, - "liked_count": 191, + "liked_count": 192, "body_letters_count": 24959, "article_type": "tech", "emoji": "🏄",