Files

55 lines
2.1 KiB
TypeScript

import type { Metadata } from 'next'
import { notFound } from 'next/navigation'
import data from '@/lib/data/oss-repos.json' with { type: 'json' }
import { group, named, type Id } from '@/lib/oss'
import { pageMeta } from '@/lib/page-meta'
import { OrgView, type Held } from './OrgView'
/**
* One org's public repositories, as scripts/sync-oss.ts read them from GitHub:
* a page for every org a group counts that holds a public repository of its
* own, and for no other (lib/data/oss-repos.json). Each row opens GitHub; the
* forge is linked where it shows the repository to a reader who is not signed in.
*/
const ORGS = data.orgs as Record<string, Held & { group: Id }>
export const dynamicParams = false
export function generateStaticParams() {
return Object.keys(ORGS).map((org) => ({ org }))
}
/**
* A page's title is the org's own name, and its login beside it where another
* org on GitHub wears the same name (hanzo-app and hanzo-apps are both "Hanzo
* Apps"), so no two pages share a title.
*/
const shared = (() => {
const seen = new Map<string, number>()
for (const [login, held] of Object.entries(ORGS)) seen.set(named(login, held.name), (seen.get(named(login, held.name)) ?? 0) + 1)
return seen
})()
const titled = (login: string, name?: string) => {
const n = named(login, name)
return (shared.get(n) ?? 0) > 1 && n !== login ? `${n} (${login})` : n
}
export async function generateMetadata({ params }: { params: Promise<{ org: string }> }): Promise<Metadata> {
const { org } = await params
const held = ORGS[org]
if (!held) return {}
const n = held.repos.length.toLocaleString('en-US')
return pageMeta({
title: `${titled(org, held.name)} — open source`,
description: `${held.description ? `${held.description.replace(/\.?$/, '.')} ` : ''}The ${n} public repositories of ${org} on GitHub, with their stars, forks, languages and last push.`,
path: `/oss/${org}`,
})
}
export default async function Page({ params }: { params: Promise<{ org: string }> }) {
const { org } = await params
const held = ORGS[org]
if (!held) notFound()
return <OrgView login={org} held={held} family={group(held.group).name} read={data.read} />
}