-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs: add sponsors #3674
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
Open
Shinigami92
wants to merge
6
commits into
next
Choose a base branch
from
docs-add-sponsors
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+129
−14
Open
docs: add sponsors #3674
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ddce05a
docs: add sponsors
Shinigami92 95b7cf4
fetch oc api
Shinigami92 039cfc5
update sponsor
Shinigami92 7996029
docs: hide sponsors block when empty and filter imageless backers
Shinigami92 606e754
docs: back off failed fetches
Shinigami92 b2df6d9
Revert "docs: back off failed fetches"
Shinigami92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| <script setup lang="ts"> | ||
| import { useLocalStorage } from '@vueuse/core'; | ||
| import type { Sponsor } from 'vitepress/dist/client/theme-default/components/VPSponsorsGrid.vue'; | ||
| import { VPDocAsideSponsors } from 'vitepress/theme'; | ||
| import { computed, onMounted } from 'vue'; | ||
|
|
||
| /** | ||
| * @see https://graphql-docs-v2.opencollective.com/types/Member | ||
| */ | ||
| interface Backer { | ||
| account: { | ||
| name: string | null; | ||
| slug: string; | ||
| imageUrl: string | null; | ||
| }; | ||
| since: string; | ||
| isActive: boolean; | ||
| totalDonations: { | ||
| value: number | null; | ||
| currency: string | null; | ||
| valueInCents: number | null; | ||
| }; | ||
| } | ||
|
|
||
| const backersStorage = useLocalStorage<{ | ||
| lastUpdated: number; | ||
| backers: Backer[]; | ||
| }>('fakerjs-backers', { | ||
| lastUpdated: 0, | ||
| backers: [], | ||
| }); | ||
|
|
||
| const sponsors = computed<Sponsor[]>( | ||
| () => | ||
| backersStorage.value?.backers | ||
| .filter((backer) => backer.account.imageUrl) | ||
| .map((backer) => ({ | ||
| name: backer.account.name ?? backer.account.slug, | ||
| img: backer.account.imageUrl!, | ||
| url: `https://opencollective.com/${backer.account.slug}`, | ||
| })) | ||
| .slice(0, 10) || [] | ||
| ); | ||
|
|
||
| async function fetchBackers(): Promise<Backer[]> { | ||
| const response = await fetch('https://api.opencollective.com/graphql/v2', { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| body: JSON.stringify({ | ||
| operationName: 'GetFakerJSDonations', | ||
| query: `query GetFakerJSDonations { | ||
| account(slug: "fakerjs") { | ||
| name | ||
| slug | ||
| members(role: BACKER, limit: 1000) { | ||
| totalCount | ||
| nodes { | ||
| account { | ||
| name | ||
| slug | ||
| imageUrl | ||
| } | ||
| since | ||
| isActive | ||
| totalDonations { | ||
| value | ||
| currency | ||
| valueInCents | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| variables: {}, | ||
| }), | ||
| }).then((res) => res.json()); | ||
|
|
||
| return (response.data.account.members.nodes as Backer[]).toSorted( | ||
| (a, b) => | ||
| (b.totalDonations.valueInCents ?? 0) - | ||
| (a.totalDonations.valueInCents ?? 0) | ||
| ); | ||
| } | ||
|
|
||
| onMounted(async () => { | ||
| // Refresh every start of the month | ||
| const now = new Date(); | ||
| const lastUpdated = new Date(backersStorage.value.lastUpdated); | ||
| if ( | ||
| backersStorage.value.backers.length === 0 || | ||
| now.getFullYear() !== lastUpdated.getFullYear() || | ||
| now.getMonth() !== lastUpdated.getMonth() | ||
| ) { | ||
| try { | ||
| const backers = await fetchBackers(); | ||
| backersStorage.value = { | ||
| lastUpdated: Date.now(), | ||
| backers, | ||
| }; | ||
| } catch { | ||
| // Silently ignore fetch errors; the section will hide itself when empty. | ||
| } | ||
| } | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <VPDocAsideSponsors | ||
| v-if="sponsors.length > 0" | ||
| tier="Top 10 Sponsors" | ||
| size="xmini" | ||
| :data="sponsors" | ||
| /> | ||
| </template> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,20 @@ | ||
| import DefaultTheme from 'vitepress/theme'; | ||
| import { defineAsyncComponent, h } from 'vue'; | ||
| import AsideSponsors from '../components/AsideSponsors.vue'; | ||
| import './index.css'; | ||
|
|
||
| export default { | ||
| ...DefaultTheme, | ||
| extends: DefaultTheme, | ||
| Layout() { | ||
| return h( | ||
| DefaultTheme.Layout, | ||
| null, | ||
| __BANNER__ | ||
| ? { | ||
| 'layout-top': () => | ||
| h( | ||
| defineAsyncComponent(() => import('../components/Banner.vue')), | ||
| { version: __BANNER__ } | ||
| ), | ||
| } | ||
| : null | ||
| ); | ||
| return h(DefaultTheme.Layout, null, { | ||
| 'layout-top': __BANNER__ | ||
| ? () => | ||
| h( | ||
| defineAsyncComponent(() => import('../components/Banner.vue')), | ||
| { version: __BANNER__ } | ||
| ) | ||
| : null, | ||
| 'aside-ads-before': () => h(AsideSponsors), | ||
| }); | ||
| }, | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.