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
20 changes: 15 additions & 5 deletions src/app/%5Fcache/route.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { type NextRequest } from 'next/server';
import { revalidatePath } from 'next/cache';
import { revalidatePath, revalidateTag } from 'next/cache';
import { redirect } from 'next/navigation';

export const dynamic = 'force-dynamic';

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams;
const queryparam = searchParams.get('path');
let path = typeof queryparam === 'string' ? queryparam : '/';
const tagParam = searchParams.get('tag');
const pathParam = searchParams.get('path');
const pathTypeParam = searchParams.get('pathType');

// Handle tag-based revalidation if provided
if (tagParam) {
revalidateTag(tagParam);
}

// Handle path-based revalidation if provided
let path = typeof pathParam === 'string' ? pathParam : '/';
if (!path.startsWith('/')) {
path = '/' + path;
}

// Invalidate the /posts route in the cache
revalidatePath(path);
if (pathParam) {
revalidatePath(path, pathTypeParam === 'layout' ? 'layout' : 'page');
}

redirect(path);
}
3 changes: 3 additions & 0 deletions src/app/(simple-mdx)/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { MDXProps } from 'mdx/types';
import { Metadata } from 'next';
import { notFound } from 'next/navigation';

// ISR: Revalidate every 24 hours
export const revalidate = 86400;

export function generateStaticParams() {
const allFiles = loadMdxDirectory({
baseDirectory: 'content/simple-mdx-pages',
Expand Down
3 changes: 3 additions & 0 deletions src/app/events/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { Google } from '@/svg/calendar/Google';
import { Outlook } from '@/svg/calendar/Outlook';
import { Ics } from '@/svg/calendar/Ics';

// ISR: Revalidate every 12 hours
export const revalidate = 43200;

export const metadata = createMetaData({
title: 'Virtual Coffee Community Events',
description: 'See our upcoming events!',
Expand Down
3 changes: 3 additions & 0 deletions src/app/join/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import DefaultLayout from '@/components/layouts/DefaultLayout';
import { createMetaData } from '@/util/createMetaData.server';
import Link from 'next/link';

// ISR: Revalidate every 24 hours
export const revalidate = 86400;

export const metadata = createMetaData({
title: 'Join Virtual Coffee',
description: `Virtual Coffee is an intimate community that welcomes people at all stages of their tech journey.`,
Expand Down
3 changes: 3 additions & 0 deletions src/app/join/thank-you/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import DefaultLayout from '@/components/layouts/DefaultLayout';

// ISR: Revalidate every 24 hours
export const revalidate = 86400;

export const metadata = {
title: 'Membership Form Received!',
description: `You're now on the membership waiting list!`,
Expand Down
3 changes: 3 additions & 0 deletions src/app/members/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import 'leaflet/dist/leaflet.css';
import { Suspense } from 'react';
import { MapLoader } from './map-loader';

// ISR: Revalidate every 24 hours
export const revalidate = 86400;

export const metadata = createMetaData({
title: 'Virtual Coffee Members',
description: 'Meet our amazing members!',
Expand Down
3 changes: 3 additions & 0 deletions src/app/monthlychallenges/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { getTotalPairingSessions } from '@/data/monthlyChallenges/pairing-challe
import { createMetaData } from '@/util/createMetaData.server';
import Link from 'next/link';

// ISR: Revalidate every 24 hours
export const revalidate = 86400;

export const metadata = createMetaData({
title: 'Virtual Coffee Monthly Challenges',
description:
Expand Down
3 changes: 3 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { getNewsletters } from '@/data/newsletters';
import { getSponsors } from '@/data/sponsors';
import { homePageLinks } from '@/util/homePageLinks';

// ISR: Revalidate every 12 hours
export const revalidate = 43200;

export default async function Home() {
const resources = loadMdxDirectory({
baseDirectory: 'content/resources',
Expand Down
3 changes: 3 additions & 0 deletions src/app/podcast/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { sanitizeCmsData } from '@/util/sanitizeCmsData';
import createCmsImage from '@/util/cmsimage';
import { Metadata } from 'next';

// ISR: Revalidate every 24 hours
export const revalidate = 86400;

export async function generateStaticParams() {
const podcastEpisodes = await getEpisodes({ limit: 99 });

Expand Down
3 changes: 3 additions & 0 deletions src/app/podcast/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { getEpisodes } from '@/data/podcast';
import { createMetaData } from '@/util/createMetaData.server';
import createCmsImage from '@/util/cmsimage';

// ISR: Revalidate every 24 hours
export const revalidate = 86400;

export const metadata = createMetaData({
title: 'Virtual Coffee Podcast',
description:
Expand Down
11 changes: 10 additions & 1 deletion src/data/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use server';

import { unstable_cache } from 'next/cache';
import { GraphQLClient, gql } from 'graphql-request';
import { DateTime } from 'luxon';
import { sanitizeHtml } from '@/util/sanitizeCmsData';
Expand Down Expand Up @@ -75,7 +76,7 @@ function createEventsQuery(
`;
}

export async function getEvents({
async function getEventsInternal({
limit,
}: {
limit: number;
Expand Down Expand Up @@ -150,3 +151,11 @@ export async function getEvents({
return [];
}
}

export const getEvents = async ({ limit }: { limit: number }) => {
return unstable_cache(
() => getEventsInternal({ limit }),
[`events-${limit}`],
{ revalidate: 43200, tags: ['events'] }
)();
};
9 changes: 8 additions & 1 deletion src/data/members/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MemberList } from '@/content/members/types';
import { GraphQLClient, gql } from 'graphql-request';
import { unstable_cache } from 'next/cache';
import teamsData from '@/content/members/teams';
import mockMemberData from '@/data/mocks/memberData';
import { sanitizeHtml } from '@/util/sanitizeCmsData';
Expand Down Expand Up @@ -29,12 +30,18 @@ function nonNullable<T>(value: T): value is NonNullable<T> {
return value !== null && value !== undefined;
}

export async function getMembers(): Promise<MembersResponse> {
async function getMembersInternal(): Promise<MembersResponse> {
const userData = await loadUserData();

return userData;
}

export const getMembers = unstable_cache(
getMembersInternal,
['members'],
{ revalidate: 86400, tags: ['members'] }
);

async function parseMarkdown(markdown: string) {
const [unified, remarkParse, remarkRehype, rehypeSanitize, rehypeStringify] =
await Promise.all([
Expand Down
43 changes: 39 additions & 4 deletions src/data/podcast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GraphQLClient, gql } from 'graphql-request';
import { unstable_cache } from 'next/cache';

export const buzzsproutPodcastId = '1558601' as const;

Expand Down Expand Up @@ -150,7 +151,7 @@ type PodcastEpisodeResponse = {
entries: PodcastEpisode[];
};

export async function getEpisodes({
async function getEpisodesInternal({
limit = 5,
}: { limit?: number } = {}): Promise<PodcastEpisodes> {
if (!(process.env.CMS_URL && process.env.CMS_TOKEN)) {
Expand Down Expand Up @@ -182,12 +183,22 @@ export async function getEpisodes({
}
}

export async function getEpisode({
export const getEpisodes = async ({
limit = 5,
}: { limit?: number } = {}): Promise<PodcastEpisodes> => {
return unstable_cache(
() => getEpisodesInternal({ limit }),
[`podcast-episodes-${limit}`],
{ revalidate: 86400, tags: ['podcast'] },
)();
};

async function getEpisodeInternal({
slug,
queryParams = '',
}: {
slug: PodcastEpisode['slug'];
queryParams?: any;
queryParams?: string;
}): Promise<PodcastEpisode | null> {
if (!(process.env.CMS_URL && process.env.CMS_TOKEN)) {
const fakeData = await import('./mocks/podcast.server');
Expand Down Expand Up @@ -231,6 +242,20 @@ export async function getEpisode({
}
}

export const getEpisode = async ({
slug,
queryParams = '',
}: {
slug: PodcastEpisode['slug'];
queryParams?: string;
}): Promise<PodcastEpisode | null> => {
return unstable_cache(
() => getEpisodeInternal({ slug, queryParams }),
[`podcast-episode-${slug}`],
{ revalidate: 86400, tags: ['podcast'] },
)();
};

type TranscriptSegment = {
speaker: string;
startTime: number;
Expand All @@ -244,7 +269,7 @@ type TranscriptItem = {
};
type Transcript = Array<TranscriptItem>;

export async function getTranscript({
async function getTranscriptInternal({
id,
}: Partial<PodcastEpisode>): Promise<Transcript | null> {
try {
Expand Down Expand Up @@ -291,3 +316,13 @@ export async function getTranscript({
return null;
}
}

export const getTranscript = async ({
id,
}: Partial<PodcastEpisode>): Promise<Transcript | null> => {
return unstable_cache(
() => getTranscriptInternal({ id }),
[`podcast-transcript-${id}`],
{ revalidate: 86400, tags: ['podcast'] },
)();
};
11 changes: 9 additions & 2 deletions src/data/sponsors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GraphQLClient, gql } from 'graphql-request';
import { unstable_cache } from 'next/cache';
import mockData from './mocks/sponsors';
import ImgixClient from '@imgix/js-core';

Expand Down Expand Up @@ -115,7 +116,7 @@ const emptySponsorsResponse = {
supporters: [],
};

export async function getSponsors() {
async function getSponsorsInternal() {
// async function main() {

let headers: HeadersInit = {
Expand Down Expand Up @@ -157,7 +158,7 @@ export async function getSponsors() {
(tier) => {
const sponsors = response.organization.sponsorshipsAsMaintainer.nodes
.filter((sponsor) => {
return sponsor.tier.id === tier.id;
return sponsor.tier?.id === tier.id;
})
.map((sponsor) => ({
...sponsor.sponsorEntity,
Expand Down Expand Up @@ -192,4 +193,10 @@ export async function getSponsors() {
return returnVal;
}

export const getSponsors = unstable_cache(
getSponsorsInternal,
['sponsors'],
{ revalidate: 86400, tags: ['sponsors'] },
);

export type SponsorsResponse = Awaited<ReturnType<typeof getSponsors>>;