diff --git a/src/build.mts b/src/build.mts index 7eed615..26d5b6a 100644 --- a/src/build.mts +++ b/src/build.mts @@ -13,6 +13,14 @@ const md = markdownit({ typographer: true, }) +const FINAL_TEAMS = [ + '布丁大馍', + '汪汪立功', + 'GoToTheDoor', + '天地一!屋!大爱盟', + 'Arc_En_Ciel', +] + function githubBtn( authorName: string, repoName: string, @@ -45,7 +53,7 @@ type MetaInfo = { control?: string readme?: string cover: boolean - prInfo: Awaited> + prInfo?: Awaited> } const metaInfos = new Map() @@ -78,6 +86,48 @@ async function allPulls() { return pulls } +async function collectTeamInfo(teamName: string, pull_number?: number) { + if (!fs.existsSync(`teams/${teamName}/game.wasm`)) { + return + } + const prInfo = pull_number ? await getPRInfo(pull_number) : undefined + const metaInfo: MetaInfo = { + prInfo, + cover: false, + } + + const files = fs + .readdirSync(`teams/${teamName}`, { withFileTypes: true }) + .filter(d => d.isFile()) + .map(d => d.name) + + for (const file of files) { + const read = (file: string): string => + fs.readFileSync(`teams/${teamName}/${file}`, 'utf8') + switch (file) { + case 'cover.png': { + metaInfo.cover = true + continue + } + case 'README.md': { + metaInfo.readme = read(file) + continue + } + case 'title': { + metaInfo.title = read(file) + continue + } + case 'control': { + metaInfo.control = read(file) + continue + } + } + } + + console.log(`metainfo of ${teamName}:`, metaInfo) + metaInfos.set(teamName, metaInfo) +} + async function collectMetaInfos(): Promise { const pulls = await allPulls() for (const pull of pulls) { @@ -102,45 +152,16 @@ async function collectMetaInfos(): Promise { if (!fs.existsSync(`teams/${teamName}`)) { continue } - const prInfo = await getPRInfo(pull_number) - const metaInfo: MetaInfo = { - prInfo, - cover: false, - } - - const files = fs - .readdirSync(`teams/${teamName}`, { withFileTypes: true }) - .filter(d => d.isFile()) - .map(d => d.name) - - for (const file of files) { - const read = (file: string): string => - fs.readFileSync(`teams/${teamName}/${file}`, 'utf8') - switch (file) { - case 'cover.png': { - metaInfo.cover = true - continue - } - case 'README.md': { - metaInfo.readme = read(file) - continue - } - case 'title': { - metaInfo.title = read(file) - continue - } - case 'control': { - metaInfo.control = read(file) - continue - } - } - } - - console.log(`metainfo of ${teamName}:`, metaInfo) - metaInfos.set(teamName, metaInfo) + await collectTeamInfo(teamName, pull_number) } } } + const teams = fs.readdirSync('teams', { withFileTypes: true }) + for (const team of teams) { + if (!team.isDirectory()) continue + if (metaInfos.has(team.name)) continue + await collectTeamInfo(team.name) + } } function renderGameCard(teamName: string, metaInfo: MetaInfo): string { @@ -149,22 +170,24 @@ function renderGameCard(teamName: string, metaInfo: MetaInfo): string { : 'default-cover.png' const teamPath = querystring.escape(teamName) - const authorName = metaInfo.prInfo.head.user.login - const repoName = metaInfo.prInfo.head.repo?.name - - if (repoName === undefined) { - throw new Error(`renderGameCard: repoName is undefined`) - } + const authorName = metaInfo.prInfo?.head.user.login + const repoName = metaInfo.prInfo?.head.repo?.name const footer = metaInfo.title ? `

${metaInfo.title}

${teamName}

` : `

${teamName}

` + let button + if (authorName && repoName) { + button = githubBtn(authorName, repoName, { large: true }) + } else { + button = '' + } return /*html*/ `
- ${githubBtn(authorName, repoName, { large: true })} + ${button}
` + : '' return /*html*/ ` @@ -503,9 +516,15 @@ function gameIndexHtml(teamName: string, metaInfo: MetaInfo): string {

${control}

${title}

-

Star 仓库,为 ta 投票 - ${githubBtn(authorName, repoName, { large: true })} -

+ ${ + authorName && repoName + ? `

Star 仓库,为 ta 投票 ${githubBtn( + authorName, + repoName, + { large: false }, + )}

` + : '' + } ${avatar}
${readme}