@reallukemanning/folio 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/copy-components.js +31 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/core/copy-components.js.html +178 -0
- package/coverage/core/eslint.config.js.html +184 -0
- package/coverage/core/index.html +146 -0
- package/coverage/core/src/__tests__/benchmarks/ProjectCard.bench.tsx.html +364 -0
- package/coverage/core/src/__tests__/benchmarks/ProjectView.bench.tsx.html +484 -0
- package/coverage/core/src/__tests__/benchmarks/github.bench.ts.html +244 -0
- package/coverage/core/src/__tests__/benchmarks/index.html +191 -0
- package/coverage/core/src/__tests__/benchmarks/npm.bench.ts.html +271 -0
- package/coverage/core/src/__tests__/benchmarks/product-hunt.bench.ts.html +259 -0
- package/coverage/core/src/__tests__/benchmarks/utilities.bench.ts.html +478 -0
- package/coverage/core/src/components/FeaturedProject.test.tsx.html +697 -0
- package/coverage/core/src/components/FeaturedProject.tsx.html +163 -0
- package/coverage/core/src/components/ProjectCard/ProjectCard.test.tsx.html +928 -0
- package/coverage/core/src/components/ProjectCard/ProjectCard.tsx.html +379 -0
- package/coverage/core/src/components/ProjectCard/index.html +146 -0
- package/coverage/core/src/components/ProjectCard/index.ts.html +88 -0
- package/coverage/core/src/components/ProjectGrid/ProjectGrid.test.tsx.html +292 -0
- package/coverage/core/src/components/ProjectGrid/ProjectGrid.tsx.html +103 -0
- package/coverage/core/src/components/ProjectGrid/index.html +146 -0
- package/coverage/core/src/components/ProjectGrid/index.ts.html +88 -0
- package/coverage/core/src/components/ProjectList/ProjectList.test.tsx.html +292 -0
- package/coverage/core/src/components/ProjectList/ProjectList.tsx.html +103 -0
- package/coverage/core/src/components/ProjectList/index.html +146 -0
- package/coverage/core/src/components/ProjectList/index.ts.html +88 -0
- package/coverage/core/src/components/ProjectView/ProjectView.test.tsx.html +1108 -0
- package/coverage/core/src/components/ProjectView/ProjectView.tsx.html +589 -0
- package/coverage/core/src/components/ProjectView/index.html +146 -0
- package/coverage/core/src/components/ProjectView/index.ts.html +88 -0
- package/coverage/core/src/components/index.html +146 -0
- package/coverage/core/src/components/index.ts.html +97 -0
- package/coverage/core/src/index.html +116 -0
- package/coverage/core/src/index.ts.html +94 -0
- package/coverage/core/src/lib/__tests__/defineProjects.test.ts.html +421 -0
- package/coverage/core/src/lib/__tests__/filterByFeatured.test.ts.html +523 -0
- package/coverage/core/src/lib/__tests__/filterByStatus.test.ts.html +664 -0
- package/coverage/core/src/lib/__tests__/filterByType.test.ts.html +631 -0
- package/coverage/core/src/lib/__tests__/github.test.ts.html +1783 -0
- package/coverage/core/src/lib/__tests__/hybrid-config.test.ts.html +1345 -0
- package/coverage/core/src/lib/__tests__/index.html +311 -0
- package/coverage/core/src/lib/__tests__/normalise.test.ts.html +1585 -0
- package/coverage/core/src/lib/__tests__/npm-config.test.ts.html +385 -0
- package/coverage/core/src/lib/__tests__/npm.test.ts.html +1135 -0
- package/coverage/core/src/lib/__tests__/product-hunt-config.test.ts.html +397 -0
- package/coverage/core/src/lib/__tests__/product-hunt.test.ts.html +505 -0
- package/coverage/core/src/lib/__tests__/sortByDate.test.ts.html +751 -0
- package/coverage/core/src/lib/__tests__/sortByName.test.ts.html +832 -0
- package/coverage/core/src/lib/__tests__/sortByStars.test.ts.html +703 -0
- package/coverage/core/src/lib/defineProjects.ts.html +100 -0
- package/coverage/core/src/lib/filterByFeatured.ts.html +133 -0
- package/coverage/core/src/lib/filterByStatus.ts.html +145 -0
- package/coverage/core/src/lib/filterByType.ts.html +133 -0
- package/coverage/core/src/lib/github.ts.html +517 -0
- package/coverage/core/src/lib/index.html +281 -0
- package/coverage/core/src/lib/index.ts.html +130 -0
- package/coverage/core/src/lib/normalise.ts.html +868 -0
- package/coverage/core/src/lib/npm.ts.html +199 -0
- package/coverage/core/src/lib/product-hunt.ts.html +256 -0
- package/coverage/core/src/lib/sortByDate.ts.html +175 -0
- package/coverage/core/src/lib/sortByName.ts.html +172 -0
- package/coverage/core/src/lib/sortByStars.ts.html +172 -0
- package/coverage/core/src/types/index.html +116 -0
- package/coverage/core/src/types/index.ts.html +517 -0
- package/coverage/core/vitest.config.ts.html +178 -0
- package/coverage/coverage-final.json +53 -0
- package/coverage/coverage-summary.json +54 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +266 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +210 -0
- package/dist/cli-components/FeaturedProject/FeaturedProject.d.ts +6 -0
- package/dist/cli-components/FeaturedProject/FeaturedProject.d.ts.map +1 -0
- package/dist/cli-components/FeaturedProject/FeaturedProject.js +9 -0
- package/dist/cli-components/FeaturedProject/FeaturedProject.js.map +1 -0
- package/dist/cli-components/FeaturedProject/FeaturedProject.tsx +54 -0
- package/dist/cli-components/FeaturedProject/index.d.ts +3 -0
- package/dist/cli-components/FeaturedProject/index.d.ts.map +1 -0
- package/dist/cli-components/FeaturedProject/index.js +2 -0
- package/dist/cli-components/FeaturedProject/index.js.map +1 -0
- package/dist/cli-components/FeaturedProject/index.ts +2 -0
- package/dist/cli-components/ProjectCard/ProjectCard.d.ts +26 -0
- package/dist/cli-components/ProjectCard/ProjectCard.d.ts.map +1 -0
- package/dist/cli-components/ProjectCard/ProjectCard.js +33 -0
- package/dist/cli-components/ProjectCard/ProjectCard.js.map +1 -0
- package/dist/cli-components/ProjectCard/ProjectCard.tsx +90 -0
- package/dist/cli-components/ProjectCard/index.d.ts +3 -0
- package/dist/cli-components/ProjectCard/index.d.ts.map +1 -0
- package/dist/cli-components/ProjectCard/index.js +2 -0
- package/dist/cli-components/ProjectCard/index.js.map +1 -0
- package/dist/cli-components/ProjectCard/index.ts +2 -0
- package/dist/cli-components/ProjectGrid/ProjectGrid.d.ts +5 -0
- package/dist/cli-components/ProjectGrid/ProjectGrid.d.ts.map +1 -0
- package/dist/cli-components/ProjectGrid/ProjectGrid.js +8 -0
- package/dist/cli-components/ProjectGrid/ProjectGrid.js.map +1 -0
- package/dist/cli-components/ProjectGrid/ProjectGrid.tsx +6 -0
- package/dist/cli-components/ProjectGrid/index.d.ts +3 -0
- package/dist/cli-components/ProjectGrid/index.d.ts.map +1 -0
- package/dist/cli-components/ProjectGrid/index.js +2 -0
- package/dist/cli-components/ProjectGrid/index.js.map +1 -0
- package/dist/cli-components/ProjectGrid/index.ts +2 -0
- package/dist/cli-components/ProjectList/ProjectList.d.ts +5 -0
- package/dist/cli-components/ProjectList/ProjectList.d.ts.map +1 -0
- package/dist/cli-components/ProjectList/ProjectList.js +8 -0
- package/dist/cli-components/ProjectList/ProjectList.js.map +1 -0
- package/dist/cli-components/ProjectList/ProjectList.tsx +6 -0
- package/dist/cli-components/ProjectList/index.d.ts +3 -0
- package/dist/cli-components/ProjectList/index.d.ts.map +1 -0
- package/dist/cli-components/ProjectList/index.js +2 -0
- package/dist/cli-components/ProjectList/index.js.map +1 -0
- package/dist/cli-components/ProjectList/index.ts +2 -0
- package/dist/cli-components/ProjectView/ProjectView.d.ts +17 -0
- package/dist/cli-components/ProjectView/ProjectView.d.ts.map +1 -0
- package/dist/cli-components/ProjectView/ProjectView.js +39 -0
- package/dist/cli-components/ProjectView/ProjectView.js.map +1 -0
- package/dist/cli-components/ProjectView/ProjectView.tsx +117 -0
- package/dist/cli-components/ProjectView/index.d.ts +3 -0
- package/dist/cli-components/ProjectView/index.d.ts.map +1 -0
- package/dist/cli-components/ProjectView/index.js +2 -0
- package/dist/cli-components/ProjectView/index.js.map +1 -0
- package/dist/cli-components/ProjectView/index.ts +2 -0
- package/dist/cli-components/types.d.ts +52 -0
- package/dist/cli-components/types.d.ts.map +1 -0
- package/dist/cli-components/types.js +2 -0
- package/dist/cli-components/types.js.map +1 -0
- package/dist/cli-components/types.ts +58 -0
- package/dist/cli-types.d.ts +52 -0
- package/dist/cli-types.d.ts.map +1 -0
- package/dist/cli-types.js +2 -0
- package/dist/cli-types.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +21 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/add.d.ts +2 -0
- package/dist/commands/add.d.ts.map +1 -0
- package/dist/commands/add.js +166 -0
- package/dist/commands/add.js.map +1 -0
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +231 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/components/FeaturedProject.d.ts +7 -0
- package/dist/components/FeaturedProject.d.ts.map +1 -0
- package/dist/components/FeaturedProject.js +10 -0
- package/dist/components/FeaturedProject.js.map +1 -0
- package/dist/components/FeaturedProject.test.tsx +204 -0
- package/dist/components/FeaturedProject.tsx +26 -0
- package/dist/components/ProjectCard/ProjectCard.d.ts +26 -0
- package/dist/components/ProjectCard/ProjectCard.d.ts.map +1 -0
- package/dist/components/ProjectCard/ProjectCard.js +39 -0
- package/dist/components/ProjectCard/ProjectCard.js.map +1 -0
- package/dist/components/ProjectCard/ProjectCard.test.tsx +281 -0
- package/dist/components/ProjectCard/ProjectCard.tsx +98 -0
- package/dist/components/ProjectCard/index.d.ts +2 -0
- package/dist/components/ProjectCard/index.d.ts.map +1 -0
- package/dist/components/ProjectCard/index.js +2 -0
- package/dist/components/ProjectCard/index.js.map +1 -0
- package/dist/components/ProjectCard/index.ts +1 -0
- package/dist/components/ProjectGrid/ProjectGrid.d.ts +5 -0
- package/dist/components/ProjectGrid/ProjectGrid.d.ts.map +1 -0
- package/dist/components/ProjectGrid/ProjectGrid.js +8 -0
- package/dist/components/ProjectGrid/ProjectGrid.js.map +1 -0
- package/dist/components/ProjectGrid/ProjectGrid.test.tsx +69 -0
- package/dist/components/ProjectGrid/ProjectGrid.tsx +6 -0
- package/dist/components/ProjectGrid/index.d.ts +2 -0
- package/dist/components/ProjectGrid/index.d.ts.map +1 -0
- package/dist/components/ProjectGrid/index.js +2 -0
- package/dist/components/ProjectGrid/index.js.map +1 -0
- package/dist/components/ProjectGrid/index.ts +1 -0
- package/dist/components/ProjectList/ProjectList.d.ts +5 -0
- package/dist/components/ProjectList/ProjectList.d.ts.map +1 -0
- package/dist/components/ProjectList/ProjectList.js +8 -0
- package/dist/components/ProjectList/ProjectList.js.map +1 -0
- package/dist/components/ProjectList/ProjectList.test.tsx +69 -0
- package/dist/components/ProjectList/ProjectList.tsx +6 -0
- package/dist/components/ProjectList/index.d.ts +2 -0
- package/dist/components/ProjectList/index.d.ts.map +1 -0
- package/dist/components/ProjectList/index.js +2 -0
- package/dist/components/ProjectList/index.js.map +1 -0
- package/dist/components/ProjectList/index.ts +1 -0
- package/dist/components/ProjectView/ProjectView.d.ts +20 -0
- package/dist/components/ProjectView/ProjectView.d.ts.map +1 -0
- package/dist/components/ProjectView/ProjectView.js +64 -0
- package/dist/components/ProjectView/ProjectView.js.map +1 -0
- package/dist/components/ProjectView/ProjectView.test.tsx +341 -0
- package/dist/components/ProjectView/ProjectView.tsx +168 -0
- package/dist/components/ProjectView/index.d.ts +2 -0
- package/dist/components/ProjectView/index.d.ts.map +1 -0
- package/dist/components/ProjectView/index.js +2 -0
- package/dist/components/ProjectView/index.js.map +1 -0
- package/dist/components/ProjectView/index.ts +1 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +5 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.ts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/defineProjects.d.ts +3 -0
- package/dist/lib/defineProjects.d.ts.map +1 -0
- package/dist/lib/defineProjects.js +4 -0
- package/dist/lib/defineProjects.js.map +1 -0
- package/dist/lib/filterByFeatured.d.ts +3 -0
- package/dist/lib/filterByFeatured.d.ts.map +1 -0
- package/dist/lib/filterByFeatured.js +10 -0
- package/dist/lib/filterByFeatured.js.map +1 -0
- package/dist/lib/filterByStatus.d.ts +3 -0
- package/dist/lib/filterByStatus.d.ts.map +1 -0
- package/dist/lib/filterByStatus.js +13 -0
- package/dist/lib/filterByStatus.js.map +1 -0
- package/dist/lib/filterByType.d.ts +3 -0
- package/dist/lib/filterByType.d.ts.map +1 -0
- package/dist/lib/filterByType.js +10 -0
- package/dist/lib/filterByType.js.map +1 -0
- package/dist/lib/github.d.ts +24 -0
- package/dist/lib/github.d.ts.map +1 -0
- package/dist/lib/github.js +107 -0
- package/dist/lib/github.js.map +1 -0
- package/dist/lib/index.d.ts +16 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +12 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/normalise.d.ts +4 -0
- package/dist/lib/normalise.d.ts.map +1 -0
- package/dist/lib/normalise.js +221 -0
- package/dist/lib/normalise.js.map +1 -0
- package/dist/lib/npm.d.ts +7 -0
- package/dist/lib/npm.d.ts.map +1 -0
- package/dist/lib/npm.js +28 -0
- package/dist/lib/npm.js.map +1 -0
- package/dist/lib/product-hunt.d.ts +12 -0
- package/dist/lib/product-hunt.d.ts.map +1 -0
- package/dist/lib/product-hunt.js +40 -0
- package/dist/lib/product-hunt.js.map +1 -0
- package/dist/lib/sortByDate.d.ts +4 -0
- package/dist/lib/sortByDate.d.ts.map +1 -0
- package/dist/lib/sortByDate.js +21 -0
- package/dist/lib/sortByDate.js.map +1 -0
- package/dist/lib/sortByName.d.ts +4 -0
- package/dist/lib/sortByName.d.ts.map +1 -0
- package/dist/lib/sortByName.js +21 -0
- package/dist/lib/sortByName.js.map +1 -0
- package/dist/lib/sortByStars.d.ts +4 -0
- package/dist/lib/sortByStars.d.ts.map +1 -0
- package/dist/lib/sortByStars.js +21 -0
- package/dist/lib/sortByStars.js.map +1 -0
- package/dist/test-setup.d.ts +2 -0
- package/dist/test-setup.d.ts.map +1 -0
- package/dist/test-setup.js +2 -0
- package/dist/test-setup.js.map +1 -0
- package/dist/types/index.d.ts +121 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/eslint.config.js +33 -0
- package/package.json +47 -0
- package/playwright-report/index.html +85 -0
- package/src/__tests__/benchmarks/ProjectCard.bench.tsx +93 -0
- package/src/__tests__/benchmarks/ProjectView.bench.tsx +133 -0
- package/src/__tests__/benchmarks/github.bench.ts +53 -0
- package/src/__tests__/benchmarks/npm.bench.ts +62 -0
- package/src/__tests__/benchmarks/product-hunt.bench.ts +58 -0
- package/src/__tests__/benchmarks/utilities.bench.ts +131 -0
- package/src/cli-components/FeaturedProject/FeaturedProject.tsx +54 -0
- package/src/cli-components/FeaturedProject/index.ts +2 -0
- package/src/cli-components/ProjectCard/ProjectCard.tsx +90 -0
- package/src/cli-components/ProjectCard/index.ts +2 -0
- package/src/cli-components/ProjectGrid/ProjectGrid.tsx +6 -0
- package/src/cli-components/ProjectGrid/index.ts +2 -0
- package/src/cli-components/ProjectList/ProjectList.tsx +6 -0
- package/src/cli-components/ProjectList/index.ts +2 -0
- package/src/cli-components/ProjectView/ProjectView.tsx +117 -0
- package/src/cli-components/ProjectView/index.ts +2 -0
- package/src/cli-components/types.ts +58 -0
- package/src/cli-types.ts +58 -0
- package/src/cli.ts +26 -0
- package/src/commands/add.ts +191 -0
- package/src/commands/init.ts +260 -0
- package/src/components/FeaturedProject.test.tsx +204 -0
- package/src/components/FeaturedProject.tsx +26 -0
- package/src/components/ProjectCard/ProjectCard.test.tsx +281 -0
- package/src/components/ProjectCard/ProjectCard.tsx +98 -0
- package/src/components/ProjectCard/index.ts +1 -0
- package/src/components/ProjectGrid/ProjectGrid.test.tsx +69 -0
- package/src/components/ProjectGrid/ProjectGrid.tsx +6 -0
- package/src/components/ProjectGrid/index.ts +1 -0
- package/src/components/ProjectList/ProjectList.test.tsx +69 -0
- package/src/components/ProjectList/ProjectList.tsx +6 -0
- package/src/components/ProjectList/index.ts +1 -0
- package/src/components/ProjectView/ProjectView.test.tsx +341 -0
- package/src/components/ProjectView/ProjectView.tsx +168 -0
- package/src/components/ProjectView/index.ts +1 -0
- package/src/components/index.ts +4 -0
- package/src/index.ts +3 -0
- package/src/lib/__tests__/defineProjects.test.ts +112 -0
- package/src/lib/__tests__/filterByFeatured.test.ts +146 -0
- package/src/lib/__tests__/filterByStatus.test.ts +193 -0
- package/src/lib/__tests__/filterByType.test.ts +182 -0
- package/src/lib/__tests__/github.test.ts +566 -0
- package/src/lib/__tests__/hybrid-config.test.ts +420 -0
- package/src/lib/__tests__/normalise.test.ts +500 -0
- package/src/lib/__tests__/npm-config.test.ts +100 -0
- package/src/lib/__tests__/npm.test.ts +350 -0
- package/src/lib/__tests__/product-hunt-config.test.ts +104 -0
- package/src/lib/__tests__/product-hunt.test.ts +140 -0
- package/src/lib/__tests__/sortByDate.test.ts +222 -0
- package/src/lib/__tests__/sortByName.test.ts +249 -0
- package/src/lib/__tests__/sortByStars.test.ts +206 -0
- package/src/lib/defineProjects.ts +5 -0
- package/src/lib/filterByFeatured.ts +16 -0
- package/src/lib/filterByStatus.ts +20 -0
- package/src/lib/filterByType.ts +16 -0
- package/src/lib/github.ts +144 -0
- package/src/lib/index.ts +15 -0
- package/src/lib/normalise.ts +261 -0
- package/src/lib/npm.ts +38 -0
- package/src/lib/product-hunt.ts +57 -0
- package/src/lib/sortByDate.ts +30 -0
- package/src/lib/sortByName.ts +29 -0
- package/src/lib/sortByStars.ts +29 -0
- package/src/test-setup.ts +1 -0
- package/src/types/index.ts +144 -0
- package/test-results/.last-run.json +62 -0
- package/tsconfig.json +29 -0
- package/vitest.config.ts +31 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FolioProject, ProjectStatus } from '../types'
|
|
2
|
+
|
|
3
|
+
export function filterByStatus(
|
|
4
|
+
projects: FolioProject[],
|
|
5
|
+
status: ProjectStatus | 'all' | ProjectStatus[] | undefined
|
|
6
|
+
): FolioProject[] {
|
|
7
|
+
if (projects.length === 0) {
|
|
8
|
+
return []
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (status === 'all' || status === undefined) {
|
|
12
|
+
return [...projects]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (Array.isArray(status)) {
|
|
16
|
+
return projects.filter(project => status.includes(project.status))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return projects.filter(project => project.status === status)
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FolioProject, ProjectType } from '../types'
|
|
2
|
+
|
|
3
|
+
export function filterByType(
|
|
4
|
+
projects: FolioProject[],
|
|
5
|
+
type: ProjectType | 'all' | undefined
|
|
6
|
+
): FolioProject[] {
|
|
7
|
+
if (projects.length === 0) {
|
|
8
|
+
return []
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (type === 'all' || type === undefined) {
|
|
12
|
+
return [...projects]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return projects.filter(project => project.type === type)
|
|
16
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export interface GitHubRepoData {
|
|
2
|
+
name: string
|
|
3
|
+
description: string | null
|
|
4
|
+
stargazers_count: number
|
|
5
|
+
forks_count: number
|
|
6
|
+
language: string | null
|
|
7
|
+
topics: string[]
|
|
8
|
+
html_url: string
|
|
9
|
+
homepage: string | null
|
|
10
|
+
created_at: string
|
|
11
|
+
updated_at: string
|
|
12
|
+
fork?: boolean
|
|
13
|
+
archived?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const LANGUAGE_COLORS: Record<string, string> = {
|
|
17
|
+
TypeScript: '#3178c6',
|
|
18
|
+
JavaScript: '#f1e05a',
|
|
19
|
+
Python: '#3572A5',
|
|
20
|
+
Java: '#b07219',
|
|
21
|
+
Go: '#00ADD8',
|
|
22
|
+
Rust: '#dea584',
|
|
23
|
+
C: '#555555',
|
|
24
|
+
'C++': '#f34b7d',
|
|
25
|
+
'C#': '#239120',
|
|
26
|
+
PHP: '#4F5D95',
|
|
27
|
+
Ruby: '#701516',
|
|
28
|
+
Swift: '#F05138',
|
|
29
|
+
Kotlin: '#A97BFF',
|
|
30
|
+
Dart: '#00B4AB',
|
|
31
|
+
Scala: '#c22d40',
|
|
32
|
+
Haskell: '#5e5086',
|
|
33
|
+
Lua: '#000080',
|
|
34
|
+
Shell: '#89e051',
|
|
35
|
+
HTML: '#e34c26',
|
|
36
|
+
CSS: '#563d7c',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function fetchGitHubRepo(repo: string): Promise<GitHubRepoData | null> {
|
|
40
|
+
try {
|
|
41
|
+
const url = `https://api.github.com/repos/${repo}`
|
|
42
|
+
|
|
43
|
+
const headers: HeadersInit = {
|
|
44
|
+
Accept: 'application/vnd.github.v3+json',
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const token = process.env.GITHUB_TOKEN
|
|
48
|
+
if (token) {
|
|
49
|
+
headers.Authorization = `Bearer ${token}`
|
|
50
|
+
} else {
|
|
51
|
+
console.warn('GITHUB_TOKEN not set - using unauthenticated GitHub API (60/hr rate limit)')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const response = await fetch(url, {
|
|
55
|
+
headers,
|
|
56
|
+
cache: 'force-cache',
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const data = await response.json()
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
name: data.name,
|
|
67
|
+
description: data.description,
|
|
68
|
+
stargazers_count: data.stargazers_count,
|
|
69
|
+
forks_count: data.forks_count,
|
|
70
|
+
language: data.language,
|
|
71
|
+
topics: data.topics || [],
|
|
72
|
+
html_url: data.html_url,
|
|
73
|
+
homepage: data.homepage,
|
|
74
|
+
created_at: data.created_at,
|
|
75
|
+
updated_at: data.updated_at,
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type FetchReposError = 'rate_limit' | 'network' | 'not_found' | 'other'
|
|
83
|
+
|
|
84
|
+
export interface FetchReposResult {
|
|
85
|
+
data: GitHubRepoData[] | null
|
|
86
|
+
error: FetchReposError | null
|
|
87
|
+
rateLimitRemaining: number | null
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function fetchGitHubRepos(username: string): Promise<FetchReposResult> {
|
|
91
|
+
try {
|
|
92
|
+
const url = `https://api.github.com/users/${username}/repos?sort=updated&per_page=100`
|
|
93
|
+
|
|
94
|
+
const headers: HeadersInit = {
|
|
95
|
+
Accept: 'application/vnd.github.v3+json',
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const token = process.env.GITHUB_TOKEN
|
|
99
|
+
if (token) {
|
|
100
|
+
headers.Authorization = `Bearer ${token}`
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const response = await fetch(url, {
|
|
104
|
+
headers,
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const rateLimitRemaining = response.headers.get('X-RateLimit-Remaining')
|
|
108
|
+
? parseInt(response.headers.get('X-RateLimit-Remaining')!)
|
|
109
|
+
: null
|
|
110
|
+
|
|
111
|
+
if (response.status === 403) {
|
|
112
|
+
return { data: null, error: 'rate_limit', rateLimitRemaining }
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (response.status === 404) {
|
|
116
|
+
return { data: null, error: 'not_found', rateLimitRemaining }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!response.ok) {
|
|
120
|
+
return { data: null, error: 'other', rateLimitRemaining }
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const data = await response.json()
|
|
124
|
+
|
|
125
|
+
const repos = data.map((repo: any) => ({
|
|
126
|
+
name: repo.name,
|
|
127
|
+
description: repo.description,
|
|
128
|
+
stargazers_count: repo.stargazers_count,
|
|
129
|
+
forks_count: repo.forks_count,
|
|
130
|
+
language: repo.language,
|
|
131
|
+
topics: repo.topics || [],
|
|
132
|
+
html_url: repo.html_url,
|
|
133
|
+
homepage: repo.homepage,
|
|
134
|
+
fork: repo.fork,
|
|
135
|
+
archived: repo.archived,
|
|
136
|
+
created_at: repo.created_at,
|
|
137
|
+
updated_at: repo.updated_at,
|
|
138
|
+
}))
|
|
139
|
+
|
|
140
|
+
return { data: repos, error: null, rateLimitRemaining }
|
|
141
|
+
} catch {
|
|
142
|
+
return { data: null, error: 'network', rateLimitRemaining: null }
|
|
143
|
+
}
|
|
144
|
+
}
|
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { defineProjects } from './defineProjects'
|
|
2
|
+
export { fetchGitHubRepo, fetchGitHubRepos, LANGUAGE_COLORS } from './github'
|
|
3
|
+
export type { GitHubRepoData, FetchReposResult, FetchReposError } from './github'
|
|
4
|
+
export { fetchNpmPackage } from './npm'
|
|
5
|
+
export { fetchProductHuntPost } from './product-hunt'
|
|
6
|
+
export { filterByFeatured } from './filterByFeatured'
|
|
7
|
+
export { filterByStatus } from './filterByStatus'
|
|
8
|
+
export { filterByType } from './filterByType'
|
|
9
|
+
export { normalise } from './normalise'
|
|
10
|
+
export { sortByDate } from './sortByDate'
|
|
11
|
+
export { sortByName } from './sortByName'
|
|
12
|
+
export { sortByStars } from './sortByStars'
|
|
13
|
+
export type { NpmPackageData } from './npm'
|
|
14
|
+
export type { ProductHuntPostData } from './product-hunt'
|
|
15
|
+
export type { SortOrder } from './sortByDate'
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { fetchGitHubRepo, LANGUAGE_COLORS } from './github'
|
|
2
|
+
import { fetchNpmPackage } from './npm'
|
|
3
|
+
import { fetchProductHuntPost } from './product-hunt'
|
|
4
|
+
import type { FolioProject, FolioProjectInput, NormalizedStat, ProjectType } from '../types'
|
|
5
|
+
|
|
6
|
+
export async function normalise(input: FolioProjectInput): Promise<FolioProject> {
|
|
7
|
+
const {
|
|
8
|
+
id,
|
|
9
|
+
type,
|
|
10
|
+
status,
|
|
11
|
+
featured,
|
|
12
|
+
name: inputName,
|
|
13
|
+
tagline: inputTagline,
|
|
14
|
+
description: inputDescription,
|
|
15
|
+
links: inputLinks,
|
|
16
|
+
stack: inputStack,
|
|
17
|
+
stats: inputStats,
|
|
18
|
+
background: inputBackground,
|
|
19
|
+
why: inputWhy,
|
|
20
|
+
image: inputImage,
|
|
21
|
+
struggles: inputStruggles,
|
|
22
|
+
timeline: inputTimeline,
|
|
23
|
+
posts: inputPosts,
|
|
24
|
+
createdAt: inputCreatedAt,
|
|
25
|
+
updatedAt: inputUpdatedAt,
|
|
26
|
+
override,
|
|
27
|
+
} = input
|
|
28
|
+
|
|
29
|
+
const repo = 'repo' in input ? input.repo : undefined
|
|
30
|
+
|
|
31
|
+
let githubData = null
|
|
32
|
+
|
|
33
|
+
if (type === 'github' || type === 'hybrid') {
|
|
34
|
+
if (repo) {
|
|
35
|
+
githubData = await fetchGitHubRepo(repo)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const npmPackage = 'package' in input ? input.package : undefined
|
|
40
|
+
|
|
41
|
+
let npmData = null
|
|
42
|
+
|
|
43
|
+
if (type === 'npm' || type === 'hybrid') {
|
|
44
|
+
if (npmPackage) {
|
|
45
|
+
npmData = await fetchNpmPackage(npmPackage)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const slug = 'slug' in input ? input.slug : undefined
|
|
50
|
+
|
|
51
|
+
let productHuntData = null
|
|
52
|
+
|
|
53
|
+
if (type === 'product-hunt') {
|
|
54
|
+
if (slug) {
|
|
55
|
+
productHuntData = await fetchProductHuntPost(slug)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let finalName: string
|
|
60
|
+
let finalTagline: string
|
|
61
|
+
let finalDescription: string
|
|
62
|
+
let finalStack: string[]
|
|
63
|
+
|
|
64
|
+
if (type === 'github') {
|
|
65
|
+
finalName = override?.name || githubData?.name || inputName || ''
|
|
66
|
+
finalTagline = override?.tagline || inputTagline || ''
|
|
67
|
+
finalDescription = override?.description || githubData?.description || inputDescription || ''
|
|
68
|
+
finalStack = override?.stack || inputStack || []
|
|
69
|
+
} else if (type === 'hybrid') {
|
|
70
|
+
finalName = override?.name || inputName || githubData?.name || ''
|
|
71
|
+
finalTagline = override?.tagline || inputTagline || ''
|
|
72
|
+
finalDescription = override?.description || inputDescription || githubData?.description || ''
|
|
73
|
+
finalStack = override?.stack || inputStack || []
|
|
74
|
+
} else {
|
|
75
|
+
finalName = inputName || ''
|
|
76
|
+
finalTagline = inputTagline || ''
|
|
77
|
+
finalDescription = inputDescription || ''
|
|
78
|
+
finalStack = inputStack || []
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let finalLinks: FolioProject['links'] = {}
|
|
82
|
+
if (type === 'github') {
|
|
83
|
+
if (githubData) {
|
|
84
|
+
finalLinks = {
|
|
85
|
+
github: githubData.html_url,
|
|
86
|
+
live: githubData.homepage || undefined,
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (inputLinks) {
|
|
90
|
+
finalLinks = { ...finalLinks, ...inputLinks }
|
|
91
|
+
}
|
|
92
|
+
} else if (type === 'hybrid') {
|
|
93
|
+
finalLinks = inputLinks || {}
|
|
94
|
+
if (githubData) {
|
|
95
|
+
finalLinks.github = finalLinks.github || githubData.html_url
|
|
96
|
+
finalLinks.live = finalLinks.live || githubData.homepage || undefined
|
|
97
|
+
}
|
|
98
|
+
if (npmData && npmPackage) {
|
|
99
|
+
finalLinks.npm = finalLinks.npm || `https://npmjs.com/package/${npmPackage}`
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
finalLinks = inputLinks || {}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let finalStats: FolioProject['stats'] | null = null
|
|
106
|
+
if (type === 'github' || type === 'hybrid' || type === 'npm' || type === 'product-hunt') {
|
|
107
|
+
if (githubData) {
|
|
108
|
+
finalStats = {
|
|
109
|
+
stars: githubData.stargazers_count,
|
|
110
|
+
forks: githubData.forks_count,
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (npmData) {
|
|
114
|
+
finalStats = {
|
|
115
|
+
...finalStats,
|
|
116
|
+
downloads: String(npmData.downloads),
|
|
117
|
+
version: npmData.version,
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (productHuntData) {
|
|
121
|
+
finalStats = {
|
|
122
|
+
...finalStats,
|
|
123
|
+
upvotes: productHuntData.votes_count,
|
|
124
|
+
comments: productHuntData.comments_count,
|
|
125
|
+
launchDate: productHuntData.featured_at || undefined,
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (inputStats) {
|
|
129
|
+
finalStats = { ...finalStats, ...inputStats }
|
|
130
|
+
}
|
|
131
|
+
} else {
|
|
132
|
+
finalStats = inputStats || null
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let finalLanguage: FolioProject['language'] = null
|
|
136
|
+
let finalLanguageColor: FolioProject['languageColor'] = null
|
|
137
|
+
let finalCreatedAt: FolioProject['createdAt'] = null
|
|
138
|
+
let finalUpdatedAt: FolioProject['updatedAt'] = null
|
|
139
|
+
|
|
140
|
+
if (type === 'github') {
|
|
141
|
+
finalLanguage = githubData?.language || null
|
|
142
|
+
finalLanguageColor = githubData?.language ? LANGUAGE_COLORS[githubData.language] || null : null
|
|
143
|
+
finalCreatedAt = githubData?.created_at || inputCreatedAt || null
|
|
144
|
+
finalUpdatedAt = githubData?.updated_at || inputUpdatedAt || null
|
|
145
|
+
} else if (type === 'hybrid') {
|
|
146
|
+
finalLanguage = githubData?.language || null
|
|
147
|
+
finalLanguageColor = githubData?.language ? LANGUAGE_COLORS[githubData.language] || null : null
|
|
148
|
+
finalCreatedAt = githubData?.created_at || inputCreatedAt || null
|
|
149
|
+
finalUpdatedAt = githubData?.updated_at || inputUpdatedAt || null
|
|
150
|
+
} else {
|
|
151
|
+
finalLanguage = null
|
|
152
|
+
finalLanguageColor = null
|
|
153
|
+
finalCreatedAt = inputCreatedAt || null
|
|
154
|
+
finalUpdatedAt = inputUpdatedAt || null
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
id,
|
|
159
|
+
type,
|
|
160
|
+
status,
|
|
161
|
+
featured: featured || false,
|
|
162
|
+
name: finalName,
|
|
163
|
+
tagline: finalTagline,
|
|
164
|
+
description: finalDescription,
|
|
165
|
+
background: inputBackground || null,
|
|
166
|
+
why: inputWhy || null,
|
|
167
|
+
image: inputImage || null,
|
|
168
|
+
struggles: inputStruggles || [],
|
|
169
|
+
timeline: inputTimeline || [],
|
|
170
|
+
posts: inputPosts || [],
|
|
171
|
+
stack: finalStack,
|
|
172
|
+
links: finalLinks,
|
|
173
|
+
stats: finalStats,
|
|
174
|
+
language: finalLanguage,
|
|
175
|
+
languageColor: finalLanguageColor,
|
|
176
|
+
createdAt: finalCreatedAt,
|
|
177
|
+
updatedAt: finalUpdatedAt,
|
|
178
|
+
repo,
|
|
179
|
+
package: npmPackage,
|
|
180
|
+
slug: 'slug' in input ? input.slug : undefined,
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function formatNumber(value: number): string {
|
|
185
|
+
if (value >= 1000000) {
|
|
186
|
+
return (value / 1000000).toFixed(1) + 'M'
|
|
187
|
+
}
|
|
188
|
+
if (value >= 1000) {
|
|
189
|
+
return (value / 1000).toFixed(1) + 'K'
|
|
190
|
+
}
|
|
191
|
+
return value.toString()
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function formatDate(value: string | number): string {
|
|
195
|
+
try {
|
|
196
|
+
const date = new Date(value)
|
|
197
|
+
if (isNaN(date.getTime())) {
|
|
198
|
+
return String(value)
|
|
199
|
+
}
|
|
200
|
+
return date.toLocaleDateString('en-US', {
|
|
201
|
+
year: 'numeric',
|
|
202
|
+
month: 'short',
|
|
203
|
+
day: 'numeric',
|
|
204
|
+
})
|
|
205
|
+
} catch {
|
|
206
|
+
return String(value)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function normalizeStats(stats: Record<string, unknown>, _type: ProjectType): NormalizedStat[] {
|
|
211
|
+
const result: NormalizedStat[] = []
|
|
212
|
+
|
|
213
|
+
if (stats.stars !== undefined && stats.stars !== null) {
|
|
214
|
+
const value = Number(stats.stars)
|
|
215
|
+
if (!isNaN(value)) {
|
|
216
|
+
result.push({ label: 'Stars', value: formatNumber(value) })
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (stats.forks !== undefined && stats.forks !== null) {
|
|
221
|
+
const value = Number(stats.forks)
|
|
222
|
+
if (!isNaN(value)) {
|
|
223
|
+
result.push({ label: 'Forks', value: formatNumber(value) })
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (stats.downloads !== undefined && stats.downloads !== null) {
|
|
228
|
+
const value = Number(stats.downloads)
|
|
229
|
+
if (!isNaN(value)) {
|
|
230
|
+
result.push({ label: 'Downloads', value: formatNumber(value), unit: 'month' })
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (stats.version !== undefined && stats.version !== null) {
|
|
235
|
+
let version = String(stats.version)
|
|
236
|
+
if (version && !version.startsWith('v')) {
|
|
237
|
+
version = 'v' + version
|
|
238
|
+
}
|
|
239
|
+
result.push({ label: 'Version', value: version })
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (stats.upvotes !== undefined && stats.upvotes !== null) {
|
|
243
|
+
const value = Number(stats.upvotes)
|
|
244
|
+
if (!isNaN(value)) {
|
|
245
|
+
result.push({ label: 'Upvotes', value: formatNumber(value) })
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (stats.comments !== undefined && stats.comments !== null) {
|
|
250
|
+
const value = Number(stats.comments)
|
|
251
|
+
if (!isNaN(value)) {
|
|
252
|
+
result.push({ label: 'Comments', value: formatNumber(value) })
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (stats.launchDate !== undefined && stats.launchDate !== null) {
|
|
257
|
+
result.push({ label: 'Launched', value: formatDate(String(stats.launchDate)) })
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return result
|
|
261
|
+
}
|
package/src/lib/npm.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface NpmPackageData {
|
|
2
|
+
name: string
|
|
3
|
+
version: string
|
|
4
|
+
downloads: number
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function fetchNpmPackage(packageName: string): Promise<NpmPackageData | null> {
|
|
8
|
+
try {
|
|
9
|
+
const downloadsUrl = `https://api.npmjs.org/downloads/point/last-month/${packageName}`
|
|
10
|
+
const registryUrl = `https://registry.npmjs.org/${packageName}`
|
|
11
|
+
|
|
12
|
+
const [downloadsResponse, registryResponse] = await Promise.all([
|
|
13
|
+
fetch(downloadsUrl, { cache: 'force-cache' }),
|
|
14
|
+
fetch(registryUrl, { cache: 'force-cache' }),
|
|
15
|
+
])
|
|
16
|
+
|
|
17
|
+
if (!downloadsResponse.ok || !registryResponse.ok) {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const downloadsData = await downloadsResponse.json()
|
|
22
|
+
const registryData = await registryResponse.json()
|
|
23
|
+
|
|
24
|
+
const version = registryData['dist-tags']?.latest
|
|
25
|
+
|
|
26
|
+
if (!version) {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
name: downloadsData.package || packageName,
|
|
32
|
+
version,
|
|
33
|
+
downloads: downloadsData.downloads || 0,
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface ProductHuntPostData {
|
|
2
|
+
name: string
|
|
3
|
+
tagline: string
|
|
4
|
+
description: string
|
|
5
|
+
votes_count: number
|
|
6
|
+
comments_count: number
|
|
7
|
+
featured_at: string | null
|
|
8
|
+
website: string
|
|
9
|
+
url: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export async function fetchProductHuntPost(slug: string): Promise<ProductHuntPostData | null> {
|
|
13
|
+
try {
|
|
14
|
+
const url = `https://api.producthunt.com/v2/posts/${slug}`
|
|
15
|
+
|
|
16
|
+
const token = process.env.PRODUCT_HUNT_TOKEN
|
|
17
|
+
if (!token) {
|
|
18
|
+
console.warn('PRODUCT_HUNT_TOKEN not set - cannot fetch Product Hunt data')
|
|
19
|
+
return null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const headers: HeadersInit = {
|
|
23
|
+
Authorization: `Bearer ${token}`,
|
|
24
|
+
Accept: 'application/json',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const response = await fetch(url, {
|
|
28
|
+
headers,
|
|
29
|
+
cache: 'force-cache',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const data = await response.json()
|
|
37
|
+
|
|
38
|
+
const post = data.post
|
|
39
|
+
|
|
40
|
+
if (!post) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
name: post.name,
|
|
46
|
+
tagline: post.tagline,
|
|
47
|
+
description: post.description || '',
|
|
48
|
+
votes_count: post.votes_count || 0,
|
|
49
|
+
comments_count: post.comments_count || 0,
|
|
50
|
+
featured_at: post.featured_at || null,
|
|
51
|
+
website: post.website || '',
|
|
52
|
+
url: post.url || '',
|
|
53
|
+
}
|
|
54
|
+
} catch {
|
|
55
|
+
return null
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { FolioProject } from '../types'
|
|
2
|
+
|
|
3
|
+
export type SortOrder = 'asc' | 'desc'
|
|
4
|
+
|
|
5
|
+
export function sortByDate(projects: FolioProject[], order: SortOrder = 'desc'): FolioProject[] {
|
|
6
|
+
if (projects.length === 0) {
|
|
7
|
+
return []
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const multiplier = order === 'asc' ? 1 : -1
|
|
11
|
+
|
|
12
|
+
return [...projects].sort((a, b) => {
|
|
13
|
+
const dateA = a.updatedAt || a.createdAt || null
|
|
14
|
+
const dateB = b.updatedAt || b.createdAt || null
|
|
15
|
+
|
|
16
|
+
if (!dateA && !dateB) {
|
|
17
|
+
return 0
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!dateA) {
|
|
21
|
+
return 1 * multiplier
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!dateB) {
|
|
25
|
+
return -1 * multiplier
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (new Date(dateA).getTime() - new Date(dateB).getTime()) * multiplier
|
|
29
|
+
})
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FolioProject } from '../types'
|
|
2
|
+
import type { SortOrder } from './sortByDate'
|
|
3
|
+
|
|
4
|
+
export function sortByName(projects: FolioProject[], order: SortOrder = 'asc'): FolioProject[] {
|
|
5
|
+
if (projects.length === 0) {
|
|
6
|
+
return []
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const multiplier = order === 'asc' ? 1 : -1
|
|
10
|
+
|
|
11
|
+
return [...projects].sort((a, b) => {
|
|
12
|
+
const nameA = a.name ?? null
|
|
13
|
+
const nameB = b.name ?? null
|
|
14
|
+
|
|
15
|
+
if (!nameA && !nameB) {
|
|
16
|
+
return 0
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!nameA) {
|
|
20
|
+
return 1
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!nameB) {
|
|
24
|
+
return -1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return nameA.localeCompare(nameB, undefined, { sensitivity: 'base' }) * multiplier
|
|
28
|
+
})
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { FolioProject } from '../types'
|
|
2
|
+
import type { SortOrder } from './sortByDate'
|
|
3
|
+
|
|
4
|
+
export function sortByStars(projects: FolioProject[], order: SortOrder = 'desc'): FolioProject[] {
|
|
5
|
+
if (projects.length === 0) {
|
|
6
|
+
return []
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const multiplier = order === 'asc' ? 1 : -1
|
|
10
|
+
|
|
11
|
+
return [...projects].sort((a, b) => {
|
|
12
|
+
const starsA = a.type === 'github' ? (a.stats?.stars ?? 0) : 0
|
|
13
|
+
const starsB = b.type === 'github' ? (b.stats?.stars ?? 0) : 0
|
|
14
|
+
|
|
15
|
+
if (starsA === 0 && starsB === 0) {
|
|
16
|
+
return 0
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (starsA === 0) {
|
|
20
|
+
return 1
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (starsB === 0) {
|
|
24
|
+
return -1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return (starsA - starsB) * multiplier
|
|
28
|
+
})
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/vitest'
|