From 34125690ca9b19657e6a4e04817ce4ea65e8395b Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Sat, 21 Dec 2024 14:52:45 -0700 Subject: [PATCH 1/3] Only check GitHub token for docs build when update needed --- docs/scripts/update-contributors.js | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/docs/scripts/update-contributors.js b/docs/scripts/update-contributors.js index f93d43a6a..1f1351933 100644 --- a/docs/scripts/update-contributors.js +++ b/docs/scripts/update-contributors.js @@ -7,11 +7,14 @@ const data = JSON.parse(fs.readFileSync(CONTRIBUTORS_JSON, "utf8")); const ONE_WEEK = 1000 * 60 * 60 * 24; -const GITHUB_TOKEN = process.env.GITHUB_TOKEN; -if (!GITHUB_TOKEN) { - throw new Error( - 'GITHUB_TOKEN not set! Create a token with "read:user" scope and set as an environment variable.\nhttps://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic', - ); +function getGitHubToken() { + const GITHUB_TOKEN = process.env.GITHUB_TOKEN; + if (!GITHUB_TOKEN) { + throw new Error( + 'GITHUB_TOKEN not set! Create a token with "read:user" scope and set as an environment variable.\nhttps://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic', + ); + } + return GITHUB_TOKEN; } class UserFetchError extends Error { @@ -37,7 +40,7 @@ async function fetchUserInfo(username) { const res = await fetch(`https://api.github.com/users/${username}`, { headers: { Accept: "application/vnd.github+json", - Authorization: `Bearer ${GITHUB_TOKEN}`, + Authorization: `Bearer ${getGitHubToken()}`, "X-GitHub-Api-Version": "2022-11-28", }, }); @@ -189,19 +192,14 @@ const CONTRIBUTORS = { async function main() { let i = 0; - const total = Object.values(CONTRIBUTORS).reduce( - (total, next) => total + next.size, - 0, - ); + const total = Object.values(CONTRIBUTORS).reduce((total, next) => total + next.size, 0); await Promise.all( Object.entries(CONTRIBUTORS).map(async ([repo, contributors]) => { data[repo] ??= []; for (const username of [...contributors]) { i++; // skip profiles that have been updated within the past week - const { lastFetch } = data[repo].find( - (u) => u.username === username, - ) ?? { lastFetch: 0 }; + const { lastFetch } = data[repo].find((u) => u.username === username) ?? { lastFetch: 0 }; if (Date.now() - lastFetch < ONE_WEEK) { // biome-ignore lint/suspicious/noConsoleLog: this is a script console.log(`[${i}/${total}] (Skipped ${username})`); @@ -219,10 +217,7 @@ async function main() { upsert(data[repo], userData); // biome-ignore lint/suspicious/noConsoleLog: this is a script console.log(`[${i}/${total}] Updated for ${username}`); - fs.writeFileSync( - new URL("../data/contributors.json", import.meta.url), - JSON.stringify(data), - ); // update file while fetching (sync happens safely in between fetches) + fs.writeFileSync(new URL("../data/contributors.json", import.meta.url), JSON.stringify(data)); // update file while fetching (sync happens safely in between fetches) } catch (err) { if (err instanceof UserFetchError && err.notFound) { console.warn(`[${i}/${total}] (Skipped ${username}, not found)`); From ddae33cba59c2ac06baa754dba9db55227feaaa6 Mon Sep 17 00:00:00 2001 From: Drew Powers Date: Sat, 21 Dec 2024 15:08:20 -0700 Subject: [PATCH 2/3] Add Netlify badge --- docs/.vitepress/config.ts | 2 +- docs/.vitepress/en.ts | 5 +++-- docs/.vitepress/ja.ts | 7 ++++--- docs/.vitepress/shared.ts | 2 +- docs/.vitepress/theme/CustomLayout.vue | 18 ++++++++++++++++++ docs/.vitepress/theme/style.css | 22 ++++++++++++++++++++++ docs/.vitepress/zh.ts | 5 +++-- 7 files changed, 52 insertions(+), 9 deletions(-) diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 8556147d0..55da861e9 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -4,7 +4,7 @@ import zh from "./zh"; import ja from "./ja"; import shared from "./shared"; import { transformerTwoslash } from "@shikijs/vitepress-twoslash"; -import { ModuleKind, ModuleResolutionKind } from "typescript"; +import { ModuleResolutionKind } from "typescript"; // https://vitepress.dev/reference/site-config export default defineConfig({ diff --git a/docs/.vitepress/en.ts b/docs/.vitepress/en.ts index e7471111b..a35f25417 100644 --- a/docs/.vitepress/en.ts +++ b/docs/.vitepress/en.ts @@ -138,8 +138,9 @@ export default defineConfig({ }, ], footer: { - message: - 'Released under the MIT License.', + message: ` + +Deploys by Netlify`, }, }, }); diff --git a/docs/.vitepress/ja.ts b/docs/.vitepress/ja.ts index c68e6eedf..97386954b 100644 --- a/docs/.vitepress/ja.ts +++ b/docs/.vitepress/ja.ts @@ -64,8 +64,9 @@ export default defineConfig({ sidebarMenuLabel: "メニュー", returnToTopLabel: "最上部に戻る", footer: { - message: - 'MITライセンス に基づいて配布されています。', + message: ` + +Deploys by Netlify`, }, }, }); @@ -111,4 +112,4 @@ export const jaSearch: DefaultTheme.AlgoliaSearchOptions["locales"] = { }, }, }, -}; \ No newline at end of file +}; diff --git a/docs/.vitepress/shared.ts b/docs/.vitepress/shared.ts index d531543f4..7b575d66e 100644 --- a/docs/.vitepress/shared.ts +++ b/docs/.vitepress/shared.ts @@ -26,7 +26,7 @@ const shared: UserConfig = { themeConfig: { siteTitle: false, logo: "/assets/openapi-ts.svg", - outline: 'deep', + outline: "deep", search: { provider: "algolia", options: { diff --git a/docs/.vitepress/theme/CustomLayout.vue b/docs/.vitepress/theme/CustomLayout.vue index 0a71a2955..5c172d21c 100644 --- a/docs/.vitepress/theme/CustomLayout.vue +++ b/docs/.vitepress/theme/CustomLayout.vue @@ -58,6 +58,16 @@ const { Layout } = DefaultTheme; +
Hosting
+ @@ -147,6 +157,14 @@ const { Layout } = DefaultTheme; height: 3rem; width: auto; } + +.sidebar-hosting { + align-items: center; + display: flex; + justify-content: center; + margin-block-start: 1rem; + text-align: center; +} diff --git a/docs/.vitepress/theme/style.css b/docs/.vitepress/theme/style.css index 13e2d7dcc..115628fb0 100644 --- a/docs/.vitepress/theme/style.css +++ b/docs/.vitepress/theme/style.css @@ -235,25 +235,3 @@ code { .home-sponsor .donate { display: inline-block; } - -/* Home footer */ -.VPFooter .container .message { - --badge-width: 8rem; - - align-items: center; - display: grid; - justify-items: center; - gap: 1.5rem; - text-align: center; - - @media (width >= 600px) { - grid-template-columns: var(--badge-width) auto var(--badge-width); - gap: 0; - } -} - -.footer-hosting { - display: inline-block; - height: 2rem; - width: 8rem; -} diff --git a/docs/.vitepress/zh.ts b/docs/.vitepress/zh.ts index 3d38c63dd..0be020406 100644 --- a/docs/.vitepress/zh.ts +++ b/docs/.vitepress/zh.ts @@ -53,9 +53,8 @@ export default defineConfig({ }, footer: { - message: ` - -Deploys by Netlify`, + message: + '基于 MIT 许可发布', }, }, });