Full Toolkit for Next-Level Domain Analysis
Show GitHub sponsors on landing page 💸
Felix Wotschofskybfddd5a5a3a7
diff --git a/.env.example b/.env.exampleindex ce72ca7..e1b2cd4 100644--- a/.env.example+++ b/.env.example@@ -18,3 +18,6 @@ GOOGLE_SERVICE_KEY_B64=ew...BIGQUERY_DATASET=# Code for GCP region where BigQuery dataset is locatedBIGQUERY_LOCATION=++# Credentials for GitHub API; used to display sponsors+GITHUB_TOKEN=ghp_...diff --git a/app/(landing)/_components/sponsors-section.tsx b/app/(landing)/_components/sponsors-section.tsxnew file mode 100644index 0000000..9a1cbe7--- /dev/null+++ b/app/(landing)/_components/sponsors-section.tsx@@ -0,0 +1,68 @@+import Image from 'next/image';+import { type FC, type HTMLAttributes, useCallback } from 'react';++import { env } from '@/env';+import { getGitHubSponsors } from '@/lib/github';+import { cn } from '@/lib/utils';++type SponsorsSectionProps = HTMLAttributes<HTMLElement>;++export const SponsorsSection: FC<SponsorsSectionProps> = async ({+ className,+ ...props+}) => {+ const buildSponsorUrl = useCallback(+ (sponsor: { url: string; websiteUrl: string | null }) => {+ if (!sponsor.websiteUrl) return sponsor.url;+ const url = new URL(sponsor.websiteUrl);+ url.searchParams.set('ref', 'domain-digger');+ return url.toString();+ },+ []+ );++ if (!env.GITHUB_TOKEN) {+ return null;+ }++ const sponsors = await getGitHubSponsors('wotschofsky');+ const shownSponsors = sponsors.filter((sponsor) => sponsor.amount >= 50);++ if (!shownSponsors.length) {+ return null;+ }++ return (+ <section+ className={cn(className, 'flex flex-col items-center gap-4')}+ {...props}+ >+ <h2 className="text-center font-semibold sm:text-lg">Sponsored by</h2>++ <div className="mb-2 flex items-center justify-center gap-4">+ {shownSponsors.map((sponsor) => (+ <a+ key={sponsor.login}+ href={buildSponsorUrl(sponsor)}+ target="_blank"+ >+ <Image+ width={48}+ height={48}+ className="h-16 w-16 rounded-md"+ src={sponsor.avatarUrl}+ alt={sponsor.name}+ />+ </a>+ ))}+ </div>+ <a+ className="text-center text-sm text-muted-foreground underline decoration-dotted underline-offset-4"+ href="https://github.com/sponsors/wotschofsky"+ target="_blank"+ >+ Sponsor Domain Digger+ </a>+ </section>+ );+};diff --git a/app/(landing)/page.tsx b/app/(landing)/page.tsxindex 95da744..ab97149 100644--- a/app/(landing)/page.tsx+++ b/app/(landing)/page.tsx@@ -3,6 +3,7 @@ import type { FC } from 'react';import { SearchForm } from '../_components/search-form';import { AuthorSection } from './_components/author-section';import { FeaturesSection } from './_components/features-section';+import { SponsorsSection } from './_components/sponsors-section';import { TrustedBySection } from './_components/trusted-by-section';export const metadata = {@@ -28,6 +29,7 @@ const Home: FC = () => {<TrustedBySection /><AuthorSection />+ <SponsorsSection /><FeaturesSection className="!mt-32" /></div>);diff --git a/env.ts b/env.tsindex 00023c1..582710e 100644--- a/env.ts+++ b/env.ts@@ -16,6 +16,8 @@ export const env = createEnv({GOOGLE_SERVICE_KEY_B64: z.string().optional(),BIGQUERY_DATASET: z.string().optional(),BIGQUERY_LOCATION: z.string().optional(),++ GITHUB_TOKEN: z.string().optional(),},client: {NEXT_PUBLIC_PLAUSIBLE_DOMAIN: z.string().optional(),diff --git a/lib/github.ts b/lib/github.tsnew file mode 100644index 0000000..c934c1c--- /dev/null+++ b/lib/github.ts@@ -0,0 +1,88 @@+import { env } from '@/env';++type SponsorsQueryResponse = {+ data: {+ user: {+ sponsorshipsAsMaintainer: {+ edges: {+ node: {+ sponsorEntity: {+ login: string;+ name: string;+ url: string;+ avatarUrl: string;+ websiteUrl: string | null;+ };+ tier: {+ monthlyPriceInDollars: number;+ };+ };+ }[];+ };+ };+ };+};++export const getGitHubSponsors = async (username: string) => {+ const response = await fetch('https://api.github.com/graphql', {+ method: 'POST',+ headers: {+ 'Content-Type': 'application/json',+ Authorization: `Bearer ${env.GITHUB_TOKEN}`,+ },+ body: JSON.stringify({+ query: `+ query SponsorsQuery($username: String!) {+ user(login: $username) {+ sponsorshipsAsMaintainer(first: 100) {+ edges {+ node {+ sponsorEntity {+ ... on User {+ login+ name+ url+ avatarUrl+ websiteUrl+ }+ ... on Organization {+ login+ name+ url+ avatarUrl+ websiteUrl+ }+ }+ tier {+ monthlyPriceInDollars+ }+ }+ }+ }+ }+ }+ `,+ variables: {+ username,+ },+ }),+ next: {+ revalidate: 24 * 60 * 60,+ },+ });++ if (!response.ok) {+ throw new Error('Failed to fetch GitHub sponsors');+ }++ const body = (await response.json()) as SponsorsQueryResponse;++ return body.data.user.sponsorshipsAsMaintainer.edges.map(({ node }) => ({+ login: node.sponsorEntity.login,+ name: node.sponsorEntity.name,+ url: node.sponsorEntity.url,+ avatarUrl: node.sponsorEntity.avatarUrl,+ websiteUrl: node.sponsorEntity.websiteUrl,+ amount: node.tier.monthlyPriceInDollars,+ }));+};diff --git a/next.config.js b/next.config.jsindex 64bc8e1..22b1c16 100644--- a/next.config.js+++ b/next.config.js@@ -38,6 +38,9 @@ const nextConfig = {hostname: 'static.wsky.dev',pathname: '/branding/**',},+ {+ hostname: 'avatars.githubusercontent.com',+ },],formats: ['image/avif', 'image/webp'],},