Skip to content

Commit e84c82a

Browse files
committed
feat(docs): add redirect-only 404 page for docs
Signed-off-by: Akella Srinivas <alsrinivas.346@gmail.com>
1 parent 6c8a433 commit e84c82a

File tree

2 files changed

+119
-9
lines changed

2 files changed

+119
-9
lines changed
Lines changed: 119 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,123 @@
1-
import {useEffect} from "react";
1+
import React, { useEffect, useState } from "react";
2+
import Link from "@docusaurus/Link";
3+
import useBaseUrl from "@docusaurus/useBaseUrl";
24

35
export default function NotFound() {
6+
const [countdown, setCountdown] = useState(12);
7+
const homeUrl = useBaseUrl("/");
8+
49
useEffect(() => {
5-
if (typeof window !== "undefined") {
6-
// immediate redirect without adding to browser history
7-
window.location.replace("/docs");
8-
}
9-
}, []);
10-
11-
// render nothing (no content shown)
12-
return null;
10+
const interval = setInterval(() => {
11+
setCountdown((prev) => {
12+
if (prev <= 1) {
13+
window.location.href = homeUrl;
14+
return 0;
15+
}
16+
return prev - 1;
17+
});
18+
}, 1000);
19+
20+
return () => clearInterval(interval);
21+
}, [homeUrl]);
22+
23+
return (
24+
<div className="relative overflow-hidden">
25+
<div className="mx-auto my-12 flex max-w-5xl flex-col items-center justify-center px-6 py-20 text-center">
26+
<div className="flex flex-col items-center justify-between sm:flex-row">
27+
{/* Rabbit Image */}
28+
<div className="mb-8 flex justify-center">
29+
<img
30+
src={useBaseUrl("/img/404-error.png")}
31+
alt="404 - Page Not Found"
32+
className="h-auto w-full max-w-md sm:max-w-lg"
33+
style={{ maxHeight: "400px" }}
34+
/>
35+
</div>
36+
37+
{/* Heading */}
38+
<div className="flex flex-col items-center justify-center">
39+
<h1 className="mb-4 text-5xl font-extrabold tracking-tight md:text-8xl">
40+
<span className="bg-gradient-to-r from-orange-400 via-orange-500 to-red-500 bg-clip-text text-transparent">
41+
404
42+
</span>
43+
</h1>
44+
45+
<h2 className="mb-4 text-2xl font-semibold md:text-4xl">
46+
Page Not Found
47+
</h2>
48+
49+
<p className="mb-8 max-w-xl text-lg text-[color:var(--ifm-color)] opacity-80">
50+
Looks like you’ve taken a wrong turn. The page you’re looking for
51+
doesn’t exist or may have been moved.
52+
</p>
53+
54+
{/* Countdown */}
55+
<p className="mb-10 text-sm text-[color:var(--ifm-color)] opacity-70">
56+
Redirecting to homepage in{" "}
57+
<span className="font-bold text-orange-500 animate-pulse">
58+
{countdown}s
59+
</span>
60+
61+
</p>
62+
63+
{/* CTA buttons */}
64+
<div className="mb-14 flex flex-col gap-4 sm:flex-row">
65+
<Link
66+
to={homeUrl}
67+
className="rounded-full bg-[color:var(--ifm-color-primary)] px-8 py-3 font-semibold text-white shadow-md transition hover:scale-[1.02] hover:bg-[color:var(--ifm-color-primary-dark)]"
68+
>
69+
Go to Homepage
70+
</Link>
71+
72+
</div>
73+
</div>
74+
</div>
75+
76+
{/* Popular pages */}
77+
<div className="w-full max-w-3xl">
78+
<h3 className="mb-6 text-xl font-semibold tracking-wide">
79+
Popular Pages
80+
</h3>
81+
82+
<div className="grid gap-5 sm:grid-cols-2">
83+
{[
84+
{
85+
title: "Installation",
86+
desc: "Get started with Keploy installation",
87+
link: "/server/installation",
88+
},
89+
{
90+
title: "Introduction",
91+
desc: "Learn what Keploy is and how it works",
92+
link: "/keploy-explained/introduction",
93+
},
94+
{
95+
title: "API Test Generator",
96+
desc: "Generate API tests automatically",
97+
link: "/running-keploy/api-test-generator",
98+
},
99+
{
100+
title: "Glossary",
101+
desc: "Explore Keploy terminology",
102+
link: "/concepts/reference/glossary",
103+
},
104+
].map((item) => (
105+
<Link
106+
key={item.title}
107+
to={useBaseUrl(item.link)}
108+
className="group rounded-xl bg-[color:var(--ifm-card-background-color)] p-5 text-left shadow-sm transition hover:-translate-y-1 hover:shadow-lg"
109+
>
110+
<h4 className="mb-2 font-semibold text-[color:var(--ifm-color-primary)] group-hover:underline">
111+
{item.title}
112+
</h4>
113+
<p className="text-sm text-[color:var(--ifm-color)] opacity-80">
114+
{item.desc}
115+
</p>
116+
</Link>
117+
))}
118+
</div>
119+
</div>
120+
</div>
121+
</div>
122+
);
13123
}

static/img/404-error.png

249 KB
Loading

0 commit comments

Comments
 (0)