Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

Add cache revalidation for root pages #66

Merged
merged 4 commits into from
Oct 14, 2024
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
2 changes: 0 additions & 2 deletions apps/foundation/app/api/revalidate/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRevalidateHandler } from '@session/sanity-cms/api/revalidate';
import { client } from '@/lib/sanity/sanity.client';
import { SANITY_SCHEMA_URL } from '@/lib/constants';

const SANITY_REVALIDATE_SECRET = process.env.SANITY_REVALIDATE_SECRET!;
Expand All @@ -9,7 +8,6 @@ if (!SANITY_REVALIDATE_SECRET) {

export const { POST } = createRevalidateHandler({
revalidateSecret: SANITY_REVALIDATE_SECRET,
client: client,
schemaUrls: {
page: SANITY_SCHEMA_URL.PAGE,
post: SANITY_SCHEMA_URL.POST,
Expand Down
12 changes: 2 additions & 10 deletions packages/sanity-cms/api/revalidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import logger from '../lib/logger';
import { safeTry } from '@session/util-js/try';
import type { PageSchemaType } from '../schemas/page';
import type { PostSchemaType } from '../schemas/post';
import { getSiteSettings } from '../queries/getSiteSettings';
import type { SessionSanityClient } from '../lib/client';

type RssGeneratorConfig = {
/** The CMS content type that the generator should be run for.*/
Expand All @@ -21,7 +19,6 @@ type RssGeneratorConfig = {
type CreateRevalidateHandlerOptions = {
/** The secret used to verify the webhook request. */
revalidateSecret: string;
client: SessionSanityClient;
schemaUrls: Record<string, string>;
/** An array of RSS generator configurations. {@link RssGeneratorConfig} */
rssGenerators?: Array<RssGeneratorConfig>;
Expand Down Expand Up @@ -56,7 +53,6 @@ type CreateRevalidateHandlerOptions = {
*/
export const createRevalidateHandler = ({
revalidateSecret,
client,
schemaUrls,
rssGenerators,
}: CreateRevalidateHandlerOptions) => {
Expand Down Expand Up @@ -141,12 +137,8 @@ export const createRevalidateHandler = ({
if (!schemaUrl.endsWith('/')) {
schemaUrl = `${schemaUrl}/`;
}
const settings = await getSiteSettings({ client });
if (slug === settings?.landingPage?.slug?.current) {
revalidatePath(`${schemaUrl}`);
} else {
revalidatePath(`${schemaUrl}${slug}`);
}
revalidatePath(`${schemaUrl}`);
revalidatePath(`${schemaUrl}${slug}`);
}
}
}
Expand Down
Loading