Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Netlify badge #2065

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
5 changes: 3 additions & 2 deletions docs/.vitepress/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ export default defineConfig({
},
],
footer: {
message:
'Released under the <a href="https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/LICENSE">MIT License</a>.',
message: `<div class="footer-spacer"></div>
<div class="footer-license">Released under the <a href="https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/LICENSE">MIT License</a>.</div>
<a class="footer-hosting" href="https://www.netlify.com"><img src="https://www.netlify.com/v3/img/components/netlify-color-bg.svg" alt="Deploys by Netlify" /></a>`,
},
},
});
7 changes: 4 additions & 3 deletions docs/.vitepress/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export default defineConfig({
sidebarMenuLabel: "メニュー",
returnToTopLabel: "最上部に戻る",
footer: {
message:
'<a href="https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/LICENSE">MITライセンス</a> に基づいて配布されています。',
message: `<div class="footer-spacer"></div>
<div class="footer-license"><a href="https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/LICENSE">MITライセンス</a> に基づいて配布されています。</div>
<a class="footer-hosting" href="https://www.netlify.com"><img src="https://www.netlify.com/v3/img/components/netlify-color-bg.svg" alt="Deploys by Netlify" /></a>`,
},
},
});
Expand Down Expand Up @@ -111,4 +112,4 @@ export const jaSearch: DefaultTheme.AlgoliaSearchOptions["locales"] = {
},
},
},
};
};
2 changes: 1 addition & 1 deletion docs/.vitepress/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const shared: UserConfig = {
themeConfig: {
siteTitle: false,
logo: "/assets/openapi-ts.svg",
outline: 'deep',
outline: "deep",
search: {
provider: "algolia",
options: {
Expand Down
18 changes: 18 additions & 0 deletions docs/.vitepress/theme/CustomLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ const { Layout } = DefaultTheme;
</a>
</li>
</ul>
<h5 style="margin-block-start: 4rem">Hosting</h5>
<div class="sidebar-hosting">
<a href="https://www.netlify.com"
><img
width="73"
height="32"
src="https://www.netlify.com/v3/img/components/netlify-color-bg.svg"
alt="Deploys by Netlify"
/></a>
</div>
</div>
</template>
</Layout>
Expand Down Expand Up @@ -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;
}
</style>

<style>
Expand Down
22 changes: 22 additions & 0 deletions docs/.vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,25 @@ 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;
}
5 changes: 3 additions & 2 deletions docs/.vitepress/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export default defineConfig({
},

footer: {
message:
'基于 <a href="https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/LICENSE">MIT</a> 许可发布',
message: `<div class="footer-spacer"></div>
<div class="footer-license">基于 <a href="https://github.com/openapi-ts/openapi-typescript/blob/main/packages/openapi-typescript/LICENSE">MIT</a> 许可发布</div>
<a class="footer-hosting" href="https://www.netlify.com"><img src="https://www.netlify.com/v3/img/components/netlify-color-bg.svg" alt="Deploys by Netlify" /></a>`,
},
},
});
Expand Down
29 changes: 12 additions & 17 deletions docs/scripts/update-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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",
},
});
Expand Down Expand Up @@ -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})`);
Expand All @@ -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)`);
Expand Down
Loading