Skip to content

Open source CapCut alternative.

TypeScript

feat(site): hide the Blog link until a post is published

David Le0317d4ae6309
diff --git a/site/src/app/_components/landing/AuthPage.tsx b/site/src/app/_components/landing/AuthPage.tsx
index 0c074572..bb87f48b 100644
--- a/site/src/app/_components/landing/AuthPage.tsx
+++ b/site/src/app/_components/landing/AuthPage.tsx
@@ -1,5 +1,6 @@
import { Suspense } from "react";
import { AuthScreen } from "@/app/_components/landing/AuthScreen";
+import { CutFooter } from "@/app/cut/_components/landing/CutFooter";
export type AuthSearchParams = Promise<{
method?: string | string[];
@@ -11,11 +12,11 @@ type Props = { mode: "sign-in" | "sign-up"; searchParams: AuthSearchParams };
async function Form({ mode, searchParams }: Props) {
const { method, callbackURL } = await searchParams;
return <AuthScreen mode={mode} method={method === "email" ? "email" : "google"}
- callbackURL={typeof callbackURL === "string" ? callbackURL : undefined} />;
+ callbackURL={typeof callbackURL === "string" ? callbackURL : undefined} footer={<CutFooter />} />;
}
export function AuthPage(props: Props) {
- return <Suspense fallback={<AuthScreen mode={props.mode} />}>
+ return <Suspense fallback={<AuthScreen mode={props.mode} footer={<CutFooter />} />}>
<Form {...props} />
</Suspense>;
}
diff --git a/site/src/app/_components/landing/AuthScreen.tsx b/site/src/app/_components/landing/AuthScreen.tsx
index e4550827..a20e53f6 100644
--- a/site/src/app/_components/landing/AuthScreen.tsx
+++ b/site/src/app/_components/landing/AuthScreen.tsx
@@ -2,11 +2,10 @@
import Image from "next/image";
import Link from "next/link";
-import { useCallback, useState } from "react";
+import { useCallback, useState, type ReactNode } from "react";
import { TopNav } from "@/app/_components/landing/TopNav";
import { EmailAuthForm } from "@/app/_components/landing/EmailAuthForm";
-import { CutFooter } from "@/app/cut/_components/landing/CutFooter";
import { authClient } from "@/lib/auth-client";
import { cn } from "@/lib/utils";
@@ -16,6 +15,8 @@ type Props = {
mode: AuthMode;
method?: "google" | "email";
callbackURL?: string;
+ // CutFooter reads the blog on the server, so the page hands it in.
+ footer: ReactNode;
};
const copy = {
@@ -55,7 +56,7 @@ const copy = {
const GOOGLE_BUTTON_HEIGHT = 56;
-export function AuthScreen({ mode, method = "google", callbackURL }: Props) {
+export function AuthScreen({ mode, method = "google", callbackURL, footer }: Props) {
const [isPending, setIsPending] = useState(false);
const [statusMessage, setStatusMessage] = useState<string | null>(null);
const screenCopy = copy[mode];
@@ -171,7 +172,7 @@ export function AuthScreen({ mode, method = "google", callbackURL }: Props) {
{formContent}
</div>
</section>
- <CutFooter />
+ {footer}
</main>
);
}
diff --git a/site/src/app/_components/landing/Footer.tsx b/site/src/app/_components/landing/Footer.tsx
index ce26c826..0845a5a1 100644
--- a/site/src/app/_components/landing/Footer.tsx
+++ b/site/src/app/_components/landing/Footer.tsx
@@ -1,9 +1,8 @@
-"use client";
-
import { Link as LinkIcon, Play, Send, type LucideIcon } from "lucide-react";
import Link from "next/link";
import { GITHUB_REPO_URL } from "@/app/_components/landing/data";
+import { hasPublishedPosts } from "@/lib/blog/read";
type SocialLink = {
href: string;
@@ -14,7 +13,8 @@ type SocialLink = {
type FooterLink = { href: string; label: string };
type FooterColumn = { title: string; links: FooterLink[] };
-export function Footer() {
+export async function Footer() {
+ const showBlog = await hasPublishedPosts();
const socialLinks: SocialLink[] = [
{ href: "https://www.linkedin.com", icon: LinkIcon, label: "LinkedIn" },
{ href: "https://www.youtube.com", icon: Play, label: "YouTube" },
@@ -27,7 +27,7 @@ export function Footer() {
title: "Product",
links: [
{ href: GITHUB_REPO_URL, label: "GitHub" },
- { href: "/blog", label: "Blog" },
+ ...(showBlog ? [{ href: "/blog", label: "Blog" }] : []),
],
},
{
diff --git a/site/src/app/cut/_components/landing/CutFooter.tsx b/site/src/app/cut/_components/landing/CutFooter.tsx
index 8a5a5a32..ed2462f9 100644
--- a/site/src/app/cut/_components/landing/CutFooter.tsx
+++ b/site/src/app/cut/_components/landing/CutFooter.tsx
@@ -1,8 +1,7 @@
-"use client";
-
import Link from "next/link";
import { GITHUB_REPO_URL } from "@/app/_components/landing/data";
+import { hasPublishedPosts } from "@/lib/blog/read";
type FooterLink = { href: string; label: string };
type FooterColumn = { title: string; links: FooterLink[] };
@@ -12,14 +11,15 @@ const DISCORD_URL = "https://discord.gg/Xv6qGax7sT";
// Cut's own footer, in the shared landing Footer's grouped-column design. The
// shared Footer links routes that don't exist on donkeycut.com (/sign-in,
// /use-cases), so this one carries only links that resolve on both hosts.
-export function CutFooter() {
+export async function CutFooter() {
+ const showBlog = await hasPublishedPosts();
const linkGroups: FooterColumn[] = [
{
title: "Product",
links: [
{ href: GITHUB_REPO_URL, label: "GitHub" },
{ href: DISCORD_URL, label: "Discord" },
- { href: "/blog", label: "Blog" },
+ ...(showBlog ? [{ href: "/blog", label: "Blog" }] : []),
],
},
{
diff --git a/site/src/app/cut/_components/landing/CutLanding.tsx b/site/src/app/cut/_components/landing/CutLanding.tsx
index 0bd9b176..0ce5e856 100644
--- a/site/src/app/cut/_components/landing/CutLanding.tsx
+++ b/site/src/app/cut/_components/landing/CutLanding.tsx
@@ -1,5 +1,3 @@
-"use client";
-
import { BG, BLACK } from "@/app/_components/landing/theme";
import { CutFinalCTA } from "@/app/cut/_components/landing/CutFinalCTA";
import { CutFooter } from "@/app/cut/_components/landing/CutFooter";
diff --git a/site/src/app/cut/sitemap.ts b/site/src/app/cut/sitemap.ts
index cfe6456e..7fc2b608 100644
--- a/site/src/app/cut/sitemap.ts
+++ b/site/src/app/cut/sitemap.ts
@@ -23,11 +23,9 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
changeFrequency: "monthly",
priority: 0.8,
},
- {
- url: `${DONKEYCUT_CANONICAL}/blog`,
- changeFrequency: "weekly",
- priority: 0.8,
- },
+ ...(posts.length > 0
+ ? [{ url: `${DONKEYCUT_CANONICAL}/blog`, changeFrequency: "weekly" as const, priority: 0.8 }]
+ : []),
...Array.from({ length: Math.max(0, pages - 1) }, (_, i) => ({
url: `${DONKEYCUT_CANONICAL}${blogPageHref(i + 2)}`,
changeFrequency: "weekly" as const,
diff --git a/site/src/lib/blog/read.ts b/site/src/lib/blog/read.ts
index f1cb9dc6..b1fe7fe6 100644
--- a/site/src/lib/blog/read.ts
+++ b/site/src/lib/blog/read.ts
@@ -83,6 +83,16 @@ export async function listPublishedPosts(): Promise<BlogPostCard[]> {
return rows.map(cardOf);
}
+// Whether the blog has anything to show; the footers hide their Blog link
+// until it does.
+export async function hasPublishedPosts(): Promise<boolean> {
+ "use cache";
+ cacheTag(BLOG_TAG);
+ cacheLife("max");
+ const row = await prisma.blogPost.findFirst({ select: { id: true }, where: { status: "PUBLISHED" } });
+ return row !== null;
+}
+
// One post with its body. Null for an unknown or unpublished slug; that answer
// is held briefly, since the slug may be published next.
export async function getPost(slug: string): Promise<BlogPostPage | null> {