Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/contributors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Docs Contributors

on:
schedule:
- cron: '0 3 * * SUN'
workflow_dispatch:

jobs:
contributors:
name: docs_contributors
if: ${{ github.repository_owner == 'withastro' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

- name: Install Tools & Dependencies
uses: ./.github/actions/install

- name: Update Docs Contributors
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: pnpm tsm --require=./scripts/lib/filter-warnings.cjs ./scripts/weekly-contributors.ts

- name: Create Pull Request
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
with:
branch: ci/contributors
token: ${{ secrets.FREDKBOT_GITHUB_TOKEN }}
add-paths: src/data/contributors.json
commit-message: 'ci: update contributors'
title: 'ci: update docs contributors'
body: |
This PR is auto-generated by a weekly GitHub action to update the list of contributors to the docs repository.
labels: ci
73 changes: 73 additions & 0 deletions scripts/weekly-contributors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import fs from 'node:fs/promises';

await run();

async function run() {
const repo = 'withastro/docs';
console.info(`Fetching contributors for ${repo}…`);

const contributors = await getAllContributors(repo);
await fs.writeFile('./src/data/contributors.json', JSON.stringify(contributors, null, 2) + '\n');

console.info(`Saved ${contributors.length} contributors.`);
}

async function getAllContributors(repo: string) {
const endpoint = `repos/${repo}/contributors`;
const contributors = await recursiveFetch(endpoint);

return contributors;
}

async function recursiveFetch(endpoint: string, page = 1): Promise<Contributor[]> {
const contributors: Contributor[] = [];
try {
const queryParam = endpoint.includes('?') ? '&' : '?';
const pageSize = 100;
const url = `https://api.github.com/${endpoint}${queryParam}per_page=${pageSize}&page=${page}`;

const token = process.env.GITHUB_TOKEN ?? '';

const res = await fetch(url, {
method: 'GET',
headers: {
Authorization: token && `Basic ${Buffer.from(token, 'binary').toString('base64')}`,
'User-Agent': 'astro-docs/1.0',
},
});

const data = await res.json();

if (!res.ok) {
throw new Error(
`Request to fetch endpoint failed. Reason: ${res.statusText}
Message: ${data?.message}`
);
}

contributors.push(
...data.map((contributor: Contributor) => ({
id: contributor.id,
login: contributor.login,
}))
);

// Fetch more data recursively if there are more than GitHub’s per-page response limit.
if (data.length === pageSize) {
const rest = await recursiveFetch(endpoint, page + 1);
contributors.push(...rest);
}

return contributors;
} catch (error) {
console.error(
`[error] /scripts/weekly-contributors.ts\n ${error instanceof Error ? error.message : String(error)}`
);
return [];
}
}

interface Contributor {
id: number;
login: string;
}
10 changes: 2 additions & 8 deletions src/components/ContributorList.astro
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
---
import { getAllContributors } from '~/util/getContributors';
import { getCollection } from 'astro:content';
import FacePile from './FacePile.astro';

export interface Props {
githubRepo?: `${string}/${string}`;
}

const { githubRepo = 'withastro/docs' } = Astro.props as Props;

const contributors = await getAllContributors(githubRepo);
const contributors = await getCollection('contributors');
---

<FacePile {contributors} />
10 changes: 5 additions & 5 deletions src/components/FacePile.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
import type { Contributor } from '~/util/getContributors';
import type { CollectionEntry } from 'astro:content';

export interface Props {
contributors: Contributor[];
contributors: CollectionEntry<'contributors'>[];
}

const { contributors } = Astro.props as Props;
Expand All @@ -14,10 +14,10 @@ const { contributors } = Astro.props as Props;
{
contributors.map((item) => (
<li>
<a href={`https://github.com/${item.login}`}>
<a href={`https://github.com/${item.data.login}`}>
<img
alt={item.login}
title={item.login}
alt={item.data.login}
title={item.data.login}
width="3rem"
height="3rem"
src={`https://avatars.githubusercontent.com/u/${item.id}?s=64`}
Expand Down
26 changes: 0 additions & 26 deletions src/components/TranslatorList.astro

This file was deleted.

11 changes: 11 additions & 0 deletions src/content.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { docsLoader, i18nLoader } from '@astrojs/starlight/loaders';
import { docsSchema, i18nSchema } from '@astrojs/starlight/schema';
import { defineCollection, z, type CollectionEntry } from 'astro:content';
import { file } from 'astro/loaders';
import { AstroDocsI18nSchema } from './content/i18n-schema';

export const baseSchema = z.object({
Expand Down Expand Up @@ -83,6 +84,11 @@ export const docsCollectionSchema = z.union([
recipeSchema,
]);

const contributorSchema = z.object({
id: z.number(),
login: z.string(),
});

export type DocsEntryData = z.infer<typeof docsCollectionSchema>;

export type DocsEntryType = DocsEntryData['type'];
Expand Down Expand Up @@ -141,4 +147,9 @@ export const collections = {
loader: i18nLoader(),
schema: i18nSchema({ extend: AstroDocsI18nSchema }),
}),
// Contributors to the docs repo, updated weekly, sorted number of commits in descending order.
contributors: defineCollection({
loader: file('src/data/contributors.json'),
schema: contributorSchema,
}),
};
2 changes: 1 addition & 1 deletion src/content/docs/ar/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro'

أنت تُطالع هذا التوثيق بفضل كل هؤلاء المساهمين، [انضم إلينا على GitHub!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/de/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ Bitte besuche unsere spezielle Seite [*Astro Docs* Docs](https://contribute.docs

Diese Dokumentation wurden von all diesen hilfsbereiten Menschen zur Verfügung gestellt. [Werde Teil von uns auf GitHub!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/es/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ Visita nuestro sitio dedicado [*Astro Docs* Docs](https://contribute.docs.astro.

Estos documentos son traídos por nuestra comunidad. [¡Únete a nosotros en GitHub!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/fr/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ Visitez notre site dédié [*Astro Docs* Docs](https://contribute.docs.astro.bui

Cette documentation vous est présentée par toutes ces personnes serviables. [Rejoignez-nous sur GitHub !](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/hi/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Astro Docs में योगदान देने में आपकी स

ये दस्तावेज़ आपके लिए इन सभी मददगार लोगों द्वारा लाए गए हैं। [GitHub पर हमसे जुड़ें!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/it/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Ti preghiamo di visitare la [documentazione per la *documentazione di Astro*](ht

Questa documentazione è realizzata da tutte queste persone. [Unisciti a noi su GitHub!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/ja/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Astro Docsへの貢献を支援するために、いくつかのガイドを用

このドキュメントは、多くの方々の協力によって提供されています。[GitHubで参加しましょう!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/ko/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ Astro 문서에 기여하는 데 도움이 되는 몇 가지 가이드가 있습

이 문서는 이 모든 도움을 주신 분들의 도움으로 만들어졌습니다. [GitHub에서 함께 하세요!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/pl/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Odwiedź naszą dedykowaną stronę [dokumentacji *Astro Docs*](https://contribu

Te dokumenty są dostarczane dzięki tym wszystkim pomocnym osobom. [Dołącz do nas na GitHubie!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/pt-br/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Por favor, visite nosso site dedicado [*Astro Docs* Docs](https://contribute.doc

Essa documentação é trazida até você por todas essas pessoas colaborativas. [Junte-se a nós no GitHub!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/ru/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ import ContributorList from '~/components/ContributorList.astro'

Эти документы созданы благодаря всем этим людям. [Присоединяйтесь к нам на GitHub!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/zh-cn/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ import ContributorList from '~/components/ContributorList.astro'

这些文档由所有这些有帮助的人提供。[在 GitHub 上加入我们!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
2 changes: 1 addition & 1 deletion src/content/docs/zh-tw/contribute.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ import ContributorList from '~/components/ContributorList.astro'

這些文件由下列熱心的人共同協作。歡迎[在 GitHub 加入我們!](https://github.com/withastro/docs)

<ContributorList githubRepo="withastro/docs" />
<ContributorList />
Loading
Loading