Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix nav links

Steven Tey1e4b87ac998e
diff --git a/app/(marketing)/layout.tsx b/app/(marketing)/layout.tsx
index 020f137f02..88d370e4e4 100644
--- a/app/(marketing)/layout.tsx
+++ b/app/(marketing)/layout.tsx
@@ -1,20 +1,23 @@
import Link from "next/link";
import { Github, Logo, Twitter } from "@/components/shared/icons";
import Nav from "#/ui/home/nav";
+import { headers } from "next/headers";
+import { getDomain } from "@/lib/utils";
export default function MarketingLayout(props) {
+ const domain = getDomain(headers());
return (
<div className="flex min-h-screen flex-col justify-between">
{/* Only show stats modal if not on the /stats page */}
{props.children.props.childProp.segment !== "stats" && props.modal}
- <Nav />
+ <Nav domain={domain} />
{props.children}
<div className="z-10 flex h-20 items-center justify-center space-x-12 border-t border-gray-200">
<a href="https://twitter.com/dubdotsh" target="_blank" rel="noreferrer">
<span className="sr-only">Twitter</span>
<Twitter className="h-6 w-6 text-gray-600" />
</a>
- <Link href="/">
+ <Link href={domain === "dub.sh" ? "/" : `https://dub.sh`}>
<span className="sr-only">Dub.sh Logo</span>
<Logo className="h-7 w-7 text-gray-600" />
</Link>
diff --git a/app/(marketing)/stats/[key]/opengraph-image.tsx b/app/(marketing)/stats/[key]/opengraph-image.tsx
index 78a9433d84..8af3035501 100644
--- a/app/(marketing)/stats/[key]/opengraph-image.tsx
+++ b/app/(marketing)/stats/[key]/opengraph-image.tsx
@@ -2,7 +2,7 @@ import { ImageResponse } from "next/server";
import { headers } from "next/headers";
import { getLinkViaEdge } from "@/lib/planetscale";
import { getStats } from "@/lib/stats";
-import { isHomeHostname, nFormatter, truncate } from "@/lib/utils";
+import { getDomain, nFormatter, truncate } from "@/lib/utils";
export const runtime = "edge";
export const contentType = "image/png";
@@ -21,9 +21,7 @@ export default async function StatsOG({ params }: { params: { key: string } }) {
satoshiBold,
]);
- const headersList = headers();
- let domain = headersList.get("host") as string;
- if (isHomeHostname(domain)) domain = "dub.sh";
+ const domain = getDomain(headers());
const data = await getLinkViaEdge(domain, params.key);
if (!data?.publicStats) {
diff --git a/app/(marketing)/stats/[key]/page.tsx b/app/(marketing)/stats/[key]/page.tsx
index 6ff66a3e93..23368fcfb7 100644
--- a/app/(marketing)/stats/[key]/page.tsx
+++ b/app/(marketing)/stats/[key]/page.tsx
@@ -1,6 +1,6 @@
import { headers } from "next/headers";
import { notFound } from "next/navigation";
-import { isHomeHostname } from "@/lib/utils";
+import { getDomain } from "@/lib/utils";
import { getLinkViaEdge } from "@/lib/planetscale";
import Stats from "#/ui/stats";
@@ -11,9 +11,7 @@ export async function generateMetadata({
}: {
params: { key: string };
}) {
- const headersList = headers();
- let domain = headersList.get("host") as string;
- if (isHomeHostname(domain)) domain = "dub.sh";
+ const domain = getDomain(headers());
const data = await getLinkViaEdge(domain, params.key);
@@ -41,9 +39,7 @@ export default async function StatsPage({
}: {
params: { key: string };
}) {
- const headersList = headers();
- let domain = headersList.get("host") as string;
- if (isHomeHostname(domain)) domain = "dub.sh";
+ const domain = getDomain(headers());
const data = await getLinkViaEdge(domain, params.key);
if (!data || !data.publicStats) {
diff --git a/app/sitemap.ts b/app/sitemap.ts
index d2dd83e0c2..a696821283 100644
--- a/app/sitemap.ts
+++ b/app/sitemap.ts
@@ -1,12 +1,10 @@
-import { isHomeHostname } from "@/lib/utils";
import { headers } from "next/headers";
+import { getDomain } from "@/lib/utils";
import prisma from "@/lib/prisma";
import { allChangelogPosts } from "contentlayer/generated";
export default async function Sitemap() {
- const headersList = headers();
- let domain = headersList.get("host") as string;
- if (isHomeHostname(domain)) domain = "dub.sh";
+ const domain = getDomain(headers());
// Get top 100 links (sorted by clicks in descending order)
const links = await prisma.link.findMany({
diff --git a/app/ui/home/nav.tsx b/app/ui/home/nav.tsx
index 8988510e00..cbfa38aa45 100644
--- a/app/ui/home/nav.tsx
+++ b/app/ui/home/nav.tsx
@@ -2,13 +2,13 @@
import Link from "next/link";
import Image from "next/image";
-import { usePathname, useSelectedLayoutSegment } from "next/navigation";
+import { useSelectedLayoutSegment } from "next/navigation";
import useScroll from "#/lib/hooks/use-scroll";
import clsx from "clsx";
const transparentHeaderSegments = new Set(["metatags"]);
-export default function Nav() {
+export default function Nav({ domain }: { domain?: string }) {
const scrolled = useScroll(80);
const segment = useSelectedLayoutSegment();
@@ -22,7 +22,7 @@ export default function Nav() {
>
<div className="mx-auto w-full max-w-screen-xl px-5 md:px-20">
<div className="flex h-16 items-center justify-between">
- <Link href="/">
+ <Link href={domain === "dub.sh" ? "/" : `https://dub.sh`}>
<Image
src="/_static/logotype.svg"
alt="Dub.sh logo"
@@ -34,7 +34,9 @@ export default function Nav() {
<div className="flex items-center space-x-6">
<Link
- href="/metatags"
+ href={
+ domain === "dub.sh" ? "/metatags" : `https://dub.sh/metatags`
+ }
className={`hidden rounded-md text-sm font-medium ${
segment === "metatags" ? "text-black" : "text-gray-500"
} transition-colors ease-out hover:text-black sm:block`}
@@ -42,7 +44,9 @@ export default function Nav() {
Metatags API
</Link>
<Link
- href="/changelog"
+ href={
+ domain === "dub.sh" ? "/changelog" : `https://dub.sh/changelog`
+ }
className={`rounded-md text-sm font-medium ${
segment === "changelog" ? "text-black" : "text-gray-500"
} transition-colors ease-out hover:text-black`}
diff --git a/lib/utils.ts b/lib/utils.ts
index e7a2d4eda1..8452b8aba1 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -222,6 +222,12 @@ export const isHomeHostname = (domain: string) => {
return HOME_HOSTNAMES.has(domain) || domain.endsWith(".vercel.app");
};
+export const getDomain = (headers: Headers) => {
+ let domain = headers.get("host") as string;
+ if (isHomeHostname(domain)) domain = "dub.sh";
+ return domain;
+};
+
export const getUrlFromString = (str: string) => {
if (isValidUrl(str)) return str;
try {