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.

update noindex

Steven Teyad5bb62d9025
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 863de7a606..b8637afdce 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -59,6 +59,7 @@ export async function processLink<T extends Record<string, any>>({
ios,
android,
geo,
+ noindex,
tagNames,
createdAt,
} = payload;
@@ -99,7 +100,16 @@ export async function processLink<T extends Record<string, any>>({
};
}
- if (proxy || password || rewrite || expiresAt || ios || android || geo) {
+ if (
+ proxy ||
+ password ||
+ rewrite ||
+ expiresAt ||
+ ios ||
+ android ||
+ geo ||
+ (noindex && key === "_root")
+ ) {
const proFeaturesString = [
proxy && "custom social media cards",
password && "password protection",
@@ -108,6 +118,7 @@ export async function processLink<T extends Record<string, any>>({
ios && "iOS targeting",
android && "Android targeting",
geo && "geo targeting",
+ noindex && "search engine indexing",
]
.filter(Boolean)
.join(", ")
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 353c02888d..b5a298534f 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -239,8 +239,10 @@ export const createLinkBodySchema = z.object({
noindex: z
.boolean()
.optional()
- .default(false)
- .describe("Whether to noindex the short link."),
+ .default(true)
+ .describe(
+ "Prevent search engines from indexing the short link. Defaults to `true` if not provided. Learn more: https://d.to/noindex",
+ ),
});
export const updateLinkBodySchema = createLinkBodySchema.partial().optional();
diff --git a/apps/web/ui/modals/add-edit-domain-modal/index.tsx b/apps/web/ui/modals/add-edit-domain-modal/index.tsx
index 04ab1d022c..275af3a1f3 100644
--- a/apps/web/ui/modals/add-edit-domain-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-domain-modal/index.tsx
@@ -142,12 +142,18 @@ function AddEditDomainModal({
domain: data.slug,
key: "_root",
url: "",
+ noindex: false,
}),
});
}
await Promise.all([
mutate(`/api/domains?workspaceId=${workspaceId}`),
- mutate(`/api/links?workspaceId=${workspaceId}`),
+ mutate(
+ (key) =>
+ typeof key === "string" && key.startsWith("/api/links"),
+ undefined,
+ { revalidate: true },
+ ),
]);
setShowAddEditDomainModal(false);
toast.success(endpoint.successMessage);
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index e2d9e22855..99fd08cc03 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -58,6 +58,7 @@ import ConversionSection from "./conversion-section";
import ExpirationSection from "./expiration-section";
import GeoSection from "./geo-section";
import IOSSection from "./ios-section";
+import NoindexSection from "./noindex-section";
import OGSection from "./og-section";
import PasswordSection from "./password-section";
import Preview from "./preview";
@@ -747,6 +748,7 @@ function AddEditLinkModal({
<IOSSection {...{ props, data, setData }} />
<AndroidSection {...{ props, data, setData }} />
<GeoSection {...{ props, data, setData }} />
+ <NoindexSection {...{ data, setData }} />
<CommentsSection {...{ props, data, setData }} />
</div>
diff --git a/apps/web/ui/modals/add-edit-link-modal/noindex-section.tsx b/apps/web/ui/modals/add-edit-link-modal/noindex-section.tsx
new file mode 100644
index 0000000000..8ec7fd7466
--- /dev/null
+++ b/apps/web/ui/modals/add-edit-link-modal/noindex-section.tsx
@@ -0,0 +1,49 @@
+import { LinkProps } from "@/lib/types";
+import { ProBadgeTooltip } from "@/ui/shared/pro-badge-tooltip";
+import { SimpleTooltipContent, Switch } from "@dub/ui";
+import { Dispatch, SetStateAction, useEffect, useState } from "react";
+
+export default function NoindexSection({
+ data,
+ setData,
+}: {
+ data: LinkProps;
+ setData: Dispatch<SetStateAction<LinkProps>>;
+}) {
+ const { noindex } = data;
+ const [enabled, setEnabled] = useState(!noindex);
+ useEffect(() => {
+ if (enabled) {
+ // if enabling, set noindex to true
+ setData({
+ ...data,
+ noindex: false,
+ });
+ } else {
+ // if disabling, set noindex to false
+ setData({ ...data, noindex: true });
+ }
+ }, [enabled]);
+
+ return (
+ <div className="relative border-b border-gray-200 pb-5">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center justify-between space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">
+ Search Engine Indexing
+ </h2>
+ <ProBadgeTooltip
+ content={
+ <SimpleTooltipContent
+ title="Prevent search engines from indexing your short link."
+ cta="Learn more."
+ href="https://dub.co/help/article/how-noindex-works"
+ />
+ }
+ />
+ </div>
+ <Switch fn={() => setEnabled(!enabled)} checked={enabled} />
+ </div>
+ </div>
+ );
+}
diff --git a/packages/utils/src/constants/misc.ts b/packages/utils/src/constants/misc.ts
index 6c85ac6a94..d79589975c 100644
--- a/packages/utils/src/constants/misc.ts
+++ b/packages/utils/src/constants/misc.ts
@@ -3,22 +3,22 @@ export const DEFAULT_LINK_PROPS: any = {
url: "",
domain: "",
archived: false,
- expiresAt: null,
- password: null,
+ tags: [],
title: null,
description: null,
image: null,
trackConversion: false,
+ proxy: false,
rewrite: false,
+ expiresAt: null,
+ password: null,
ios: null,
android: null,
+ noindex: true,
clicks: 0,
userId: "",
-
- proxy: false,
- tags: [],
};
export const GOOGLE_FAVICON_URL =