docu v 1.11.0

This commit is contained in:
Wildan Nursahidan
2025-05-26 23:03:58 +07:00
parent e25ee4cb93
commit 3da46325cf
57 changed files with 1433 additions and 4182 deletions

View File

@@ -1,92 +0,0 @@
import { Typography } from "@/components/typography";
import { buttonVariants } from "@/components/ui/button";
import { Author, getAllBlogStaticPaths, getBlogForSlug } from "@/lib/markdown";
import { ArrowLeftIcon } from "lucide-react";
import Link from "next/link";
import { notFound } from "next/navigation";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { formatDate } from "@/lib/utils";
import { ScrollToTop } from "@/components/scroll-to-top";
type PageProps = {
params: { slug: string };
};
export async function generateMetadata({ params: { slug } }: PageProps) {
const res = await getBlogForSlug(slug);
if (!res) return null;
const { frontmatter } = res;
return {
title: frontmatter.title,
description: frontmatter.description,
};
}
export async function generateStaticParams() {
const val = await getAllBlogStaticPaths();
if (!val) return [];
return val.map((it) => ({ slug: it }));
}
export default async function BlogPage({ params: { slug } }: PageProps) {
const res = await getBlogForSlug(slug);
if (!res) notFound();
return (
<div className="lg:w-[60%] sm:[95%] md:[75%] mx-auto">
<Link
className={buttonVariants({
variant: "link",
className: "!mx-0 !px-0 mb-7 !-ml-1 ",
})}
href="/blog"
>
<ArrowLeftIcon className="w-4 h-4 mr-1.5" /> Back to blog
</Link>
<div className="flex flex-col gap-3 pb-7 w-full mb-2">
<p className="text-muted-foreground text-sm">
{formatDate(res.frontmatter.date)}
</p>
<h1 className="sm:text-4xl text-3xl font-extrabold">
{res.frontmatter.title}
</h1>
<div className="mt-6 flex flex-col gap-3">
<p className="text-sm text-muted-foreground">Posted by</p>
<Authors authors={res.frontmatter.authors} />
</div>
</div>
<div className="!w-full">
<Typography>{res.content}</Typography>
</div>
<ScrollToTop />
</div>
);
}
function Authors({ authors }: { authors: Author[] }) {
return (
<div className="flex items-center gap-8 flex-wrap">
{authors.map((author) => {
return (
<Link
href={author.handleUrl}
className="flex items-center gap-2"
key={author.username}
>
<Avatar className="w-10 h-10">
<AvatarImage src={author.avatar} />
<AvatarFallback>
{author.username.slice(0, 2).toUpperCase()}
</AvatarFallback>
</Avatar>
<div className="">
<p className="text-sm font-medium">{author.username}</p>
<p className="font-code text-[13px] text-muted-foreground">
@{author.handle}
</p>
</div>
</Link>
);
})}
</div>
);
}

View File

@@ -1,9 +0,0 @@
import { PropsWithChildren } from "react";
export default function BlogLayout({ children }: PropsWithChildren) {
return (
<div className="flex flex-col items-start justify-center pt-8 pb-10 w-full mx-auto">
{children}
</div>
);
}

View File

@@ -1,103 +0,0 @@
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import { Author, BlogMdxFrontmatter, getAllBlogs } from "@/lib/markdown";
import { formatDate2, stringToDate } from "@/lib/utils";
import { getMetadata } from "@/app/layout";
import Image from "next/image";
import Link from "next/link";
import { AuroraText } from "@/components/ui/aurora";
import { ShineBorder } from "@/components/ui/shine-border";
import docuConfig from "@/docu.json";
export const metadata = getMetadata({
title: "Blog",
description: "Discover the latest updates, tutorials, and insights on DocuBook.",
});
const { meta } = docuConfig;
export default async function BlogIndexPage() {
const blogs = (await getAllBlogs()).sort(
(a, b) => stringToDate(b.date).getTime() - stringToDate(a.date).getTime()
);
return (
<div className="flex flex-col items-center justify-center px-2 py-8 text-center sm:py-36">
<div className="w-full max-w-[800px] pb-8">
<AuroraText className="text-lg"># Stay Informed, Stay Ahead</AuroraText>
<h1 className="mb-4 text-2xl font-bold sm:text-5xl">
Blog Posts
</h1>
<p className="mb-8 sm:text-xl text-muted-foreground">
Explore updates, tips, and deep dives from the {meta.title}.
</p>
</div>
<div className="text-left grid md:grid-cols-3 sm:grid-cols-2 grid-cols-1 sm:gap-8 gap-4 my-6">
{blogs.map((blog) => (
<BlogCard {...blog} slug={blog.slug} key={blog.slug} />
))}
</div>
</div>
);
}
function BlogCard({
date,
title,
description,
slug,
cover,
authors,
}: BlogMdxFrontmatter & { slug: string }) {
return (
<Link
href={`/blog/${slug}`}
className="flex flex-col gap-2 items-start border rounded-md max-h-[420px] min-h-[420px]"
>
<div className="w-full">
<Image
src={cover}
alt={title}
width={400}
height={150}
quality={80}
className="w-full rounded-md object-cover h-[200px]"
/>
</div>
<div className="flex flex-col items-start px-3 py-3 gap-2 mb-auto">
<h3 className="text-md font-semibold line-clamp-2">{title}</h3>
<p className="text-sm text-muted-foreground line-clamp-3">{description}</p>
</div>
<div className="flex items-center justify-between w-full px-3 mb-6">
<p className="text-[13px] text-muted-foreground">
Published on {formatDate2(date)}
</p>
<AvatarGroup users={authors} />
</div>
</Link>
);
}
function AvatarGroup({ users, max = 4 }: { users: Author[]; max?: number }) {
const displayUsers = users.slice(0, max);
const remainingUsers = Math.max(users.length - max, 0);
return (
<div className="flex items-center">
{displayUsers.map((user, index) => (
<Avatar
key={user.username}
className={`inline-block border-2 w-9 h-9 border-background ${
index !== 0 ? "-ml-3" : ""
} `}
>
<AvatarImage src={user.avatar} alt={user.username} />
<AvatarFallback>
{user.username.slice(0, 2).toUpperCase()}
</AvatarFallback>
</Avatar>
))}
{remainingUsers > 0 && (
<Avatar className="-ml-3 inline-block border-2 border-background hover:translate-y-1 transition-transform">
<AvatarFallback>+{remainingUsers}</AvatarFallback>
</Avatar>
)}
</div>
);
}

View File

@@ -1,11 +0,0 @@
export default function ChangelogLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<div className="flex items-start gap-8">
{children}
</div>
);
}

View File

@@ -1,42 +0,0 @@
import { Suspense } from "react";
import { getChangelogEntries } from "@/lib/changelog";
import { VersionEntry } from "@/components/changelog/version-entry";
import { VersionToc } from "@/components/changelog/version-toc";
import { FloatingVersionToc } from "@/components/changelog/floating-version";
export default async function ChangelogPage() {
const entries = await getChangelogEntries();
return (
<div className="flex items-start">
<Suspense fallback={<div className="lg:flex hidden flex-[1.5]" />}>
<VersionToc
versions={entries.map(({ version, date }) => ({ version, date }))}
/>
</Suspense>
<main className="flex-1 md:flex-[5.25] min-w-0 max-w-[800px]">
<div className="relative">
<div className="absolute left-0 top-0 h-full w-px bg-border md:block hidden" />
<div className="md:px-12 md:py-8 max-md:py-10">
{entries.map((entry, index) => (
<section
id={`version-${entry.version}`}
key={entry.version}
className="scroll-mt-20" // Tambahkan margin atas saat scroll
>
<VersionEntry {...entry} isLast={index === entries.length - 1} />
</section>
))}
</div>
</div>
</main>
{/* Floating TOC for smaller screens */}
{entries.length > 0 && (
<FloatingVersionToc
versions={entries.map(({ version, date }) => ({ version, date }))}
/>
)}
</div>
);
}

View File

@@ -8,7 +8,6 @@ import EditThisPage from "@/components/edit-on-github";
import { formatDate2 } from "@/lib/utils";
import docuConfig from "@/docu.json";
import MobToc from "@/components/mob-toc";
import { ScrollToTop } from "@/components/scroll-to-top";
const { meta } = docuConfig;
@@ -78,11 +77,9 @@ export default async function DocsPage({ params: { slug = [] } }: PageProps) {
return (
<div className="flex items-start gap-10">
<div className="flex-[4.5] pt-10">
<div className="flex-[4.5] pt-5">
<MobToc tocs={tocs} />
<DocsBreadcrumb paths={slug} />
<div className="mb-8">
<MobToc tocs={tocs} />
</div>
<Typography>
<h1 className="text-3xl !-mt-0.5">{title}</h1>
<p className="-mt-4 text-muted-foreground text-[16.5px]">{description}</p>
@@ -101,7 +98,6 @@ export default async function DocsPage({ params: { slug = [] } }: PageProps) {
</div>
<Pagination pathname={pathName} />
</Typography>
<ScrollToTop />
</div>
<Toc path={pathName} />
</div>

View File

@@ -8,7 +8,9 @@ export default function DocsLayout({
return (
<div className="flex items-start gap-8">
<Leftbar key="leftbar" />
<div className="flex-[5.25]">{children}</div>
<div className="flex-[5.25] px-1">
{children}
</div>
</div>
);
}

View File

@@ -1,16 +0,0 @@
import { PropsWithChildren } from "react";
import { getMetadata } from "@/app/layout";
export const metadata = getMetadata({
title: "Playground",
description: "Test and experiment with DocuBook markdown components in real-time",
image: "img-playground.png",
});
export default function PlaygroundLayout({ children }: PropsWithChildren) {
return (
<div className="flex flex-col min-h-screen">
{children}
</div>
);
}

View File

@@ -1,395 +0,0 @@
"use client";
import { useState, useEffect, useRef } from "react";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Separator } from "@/components/ui/separator";
import { toast } from "sonner";
import {
List,
ListOrdered,
Heading2,
Heading3,
Code,
Quote,
ImageIcon,
Link as LinkIcon,
Table,
Maximize2,
Minimize2,
Type,
ChevronDown,
Notebook,
Component,
Youtube as YoutubeIcon,
HelpCircle,
LayoutGrid,
MousePointer2,
Rows,
LayoutPanelTop,
Laptop2,
Copy,
Download,
RotateCcw,
Calendar
} from "lucide-react";
import { Button as UIButton } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import {
handleParagraphClick,
handleHeading2Click,
handleHeading3Click,
handleBulletListClick,
handleNumberedListClick,
handleLinkClick,
handleImageClick,
handleBlockquoteClick,
handleCodeBlockClick,
handleTableClick,
handleNoteClick,
handleComponentClick,
handleMetadataClick,
} from "@/components/playground/MarkComponent";
import "@/styles/editor.css";
const ToolbarButton = ({ icon: Icon, label, onClick }: { icon: any, label: string, onClick?: () => void }) => (
<UIButton
variant="ghost"
size="sm"
className="h-8 w-8 p-0 hover:bg-muted"
title={label}
onClick={onClick}
>
<Icon className="h-4 w-4" />
</UIButton>
);
const ToolbarSeparator = () => (
<Separator orientation="vertical" className="mx-1 h-6" />
);
const MobileMessage = () => (
<div className="min-h-[80vh] flex flex-col items-center justify-center text-center px-4 animate-in fade-in-50 duration-500">
<Laptop2 className="w-16 h-16 mb-4 text-muted-foreground animate-bounce" />
<h2 className="text-2xl font-bold mb-2">Desktop View Recommended</h2>
<p className="text-muted-foreground max-w-md">
The Playground works best on larger screens. Please switch to a desktop device for the best experience.
</p>
</div>
);
export default function PlaygroundPage() {
const [markdown, setMarkdown] = useState("");
const [isFullscreen, setIsFullscreen] = useState(false);
const [isMobile, setIsMobile] = useState(false);
const [lineCount, setLineCount] = useState(1);
const editorRef = useRef<HTMLTextAreaElement>(null);
const lineNumbersRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const checkMobile = () => {
setIsMobile(window.innerWidth < 768);
};
checkMobile();
window.addEventListener('resize', checkMobile);
return () => {
window.removeEventListener('resize', checkMobile);
};
}, []);
useEffect(() => {
// Update line count when markdown content changes
const lines = markdown.split('\n').length;
setLineCount(Math.max(lines, 1));
}, [markdown]);
// Sync scroll position between editor and line numbers
useEffect(() => {
const textarea = editorRef.current;
const lineNumbers = lineNumbersRef.current;
if (!textarea || !lineNumbers) return;
const handleScroll = () => {
lineNumbers.scrollTop = textarea.scrollTop;
};
textarea.addEventListener('scroll', handleScroll);
return () => textarea.removeEventListener('scroll', handleScroll);
}, []);
const toggleFullscreen = () => {
setIsFullscreen(!isFullscreen);
};
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(markdown);
toast.success('Content copied to clipboard');
} catch (err) {
toast.error('Failed to copy content');
}
};
const handleDownload = () => {
try {
const blob = new Blob([markdown], { type: 'text/markdown' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'index.mdx';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
toast.success('Content downloaded successfully');
} catch (err) {
toast.error('Failed to download content');
}
};
const handleReset = () => {
if (markdown.trim()) {
toast.custom((t) => (
<div className="flex flex-col gap-2 bg-background border rounded-lg p-4 shadow-lg">
<h3 className="font-semibold">Clear editor content?</h3>
<p className="text-sm text-muted-foreground">This action cannot be undone.</p>
<div className="flex gap-2 mt-2">
<UIButton
size="sm"
variant="destructive"
onClick={() => {
setMarkdown('');
toast.success('all content in the editor has been cleaned');
toast.dismiss(t);
}}
>
Clear
</UIButton>
<UIButton
size="sm"
variant="outline"
onClick={() => toast.dismiss(t)}
>
Cancel
</UIButton>
</div>
</div>
), { duration: 10000 });
}
};
const insertAtCursor = (textArea: HTMLTextAreaElement, text: string) => {
const start = textArea.selectionStart;
const end = textArea.selectionEnd;
const before = markdown.substring(0, start);
const after = markdown.substring(end);
const needsLeadingNewline = before && !before.endsWith('\n\n') ? '\n\n' : '';
const needsTrailingNewline = after && !after.startsWith('\n\n') ? '\n\n' : '';
const newText = `${before}${needsLeadingNewline}${text}${needsTrailingNewline}${after}`;
setMarkdown(newText);
requestAnimationFrame(() => {
textArea.focus();
const newPosition = before.length + needsLeadingNewline.length + text.length + 1;
textArea.setSelectionRange(newPosition, newPosition);
});
};
if (isMobile) {
return <MobileMessage />;
}
return (
<div className={cn(
"flex flex-col transition-all duration-200",
isFullscreen ? "fixed inset-0 z-50 bg-background" : "min-h-[calc(100vh-4rem)]"
)}>
<div className="border-b bg-background">
<div className="py-8 px-2">
<div className="flex flex-col gap-1">
<h1 className="text-2xl font-extrabold">Docu<span className="text-primary text-lg ml-1">PLAY</span></h1>
<p className="text-lg text-muted-foreground mt-2">
Test and experiment with DocuBook markdown components in real-time
</p>
</div>
</div>
</div>
<div className="flex-1 py-8 px-2">
<div className="flex flex-col h-full pb-12">
<ScrollArea className="flex-1 border rounded-lg">
<div className="sticky top-0 z-20 bg-background border-b">
<div className="flex items-center justify-between p-2 bg-muted/40">
<div className="flex items-center gap-2">
{markdown.trim() && (
<>
<UIButton
variant="ghost"
size="sm"
onClick={handleCopy}
className="gap-2 text-xs"
>
<Copy className="h-3.5 w-3.5" />
Copy
</UIButton>
<UIButton
variant="ghost"
size="sm"
onClick={handleDownload}
className="gap-2 text-xs"
>
<Download className="h-3.5 w-3.5" />
Download
</UIButton>
<UIButton
variant="ghost"
size="sm"
onClick={handleReset}
className="gap-2 text-xs"
>
<RotateCcw className="h-3.5 w-3.5" />
Reset
</UIButton>
<Separator orientation="vertical" className="h-4" />
</>
)}
</div>
<UIButton
variant="ghost"
size="sm"
onClick={toggleFullscreen}
className="gap-2 text-xs"
>
{isFullscreen ? (
<>
<Minimize2 className="h-3.5 w-3.5" />
Exit Fullscreen
</>
) : (
<>
<Maximize2 className="h-3.5 w-3.5" />
Fullscreen
</>
)}
</UIButton>
</div>
<div className="flex items-center border-b p-1 bg-background">
<ToolbarButton icon={Calendar} label="Metadata" onClick={() => handleMetadataClick(insertAtCursor)} />
<ToolbarSeparator />
<ToolbarButton icon={Type} label="Paragraph" onClick={() => handleParagraphClick(insertAtCursor)} />
<ToolbarButton icon={Heading2} label="Heading 2" onClick={() => handleHeading2Click(insertAtCursor)} />
<ToolbarButton icon={Heading3} label="Heading 3" onClick={() => handleHeading3Click(insertAtCursor)} />
<ToolbarButton icon={List} label="Bullet List" onClick={() => handleBulletListClick(insertAtCursor)} />
<ToolbarButton icon={ListOrdered} label="Numbered List" onClick={() => handleNumberedListClick(insertAtCursor)} />
<ToolbarSeparator />
<ToolbarButton icon={LinkIcon} label="Link" onClick={() => handleLinkClick(insertAtCursor)} />
<ToolbarButton icon={ImageIcon} label="Image" onClick={() => handleImageClick(insertAtCursor)} />
<ToolbarButton icon={Quote} label="Blockquote" onClick={() => handleBlockquoteClick(insertAtCursor)} />
<ToolbarButton icon={Code} label="Code Block" onClick={() => handleCodeBlockClick(insertAtCursor)} />
<ToolbarButton icon={Table} label="Table" onClick={() => handleTableClick(insertAtCursor)} />
<ToolbarSeparator />
<DropdownMenu>
<DropdownMenuTrigger asChild>
<UIButton
variant="ghost"
size="sm"
className="h-8 px-2 flex items-center gap-1 font-normal"
>
<Notebook className="h-4 w-4" />
<ChevronDown className="h-4 w-4" />
</UIButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem onClick={handleNoteClick(insertAtCursor, 'note')}>
Note
</DropdownMenuItem>
<DropdownMenuItem onClick={handleNoteClick(insertAtCursor, 'danger')}>
Danger
</DropdownMenuItem>
<DropdownMenuItem onClick={handleNoteClick(insertAtCursor, 'warning')}>
Warning
</DropdownMenuItem>
<DropdownMenuItem onClick={handleNoteClick(insertAtCursor, 'success')}>
Success
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<ToolbarSeparator />
<DropdownMenu>
<DropdownMenuTrigger asChild>
<UIButton
variant="ghost"
size="sm"
className="h-8 px-2 flex items-center gap-1 font-normal"
>
<Component className="h-4 w-4" />
<ChevronDown className="h-4 w-4" />
</UIButton>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuItem onClick={handleComponentClick(insertAtCursor, 'stepper')}>
<Rows className="h-4 w-4 mr-2" />
Stepper
</DropdownMenuItem>
<DropdownMenuItem onClick={handleComponentClick(insertAtCursor, 'card')}>
<LayoutGrid className="h-4 w-4 mr-2" />
Card
</DropdownMenuItem>
<DropdownMenuItem onClick={handleComponentClick(insertAtCursor, 'button')}>
<MousePointer2 className="h-4 w-4 mr-2" />
Button
</DropdownMenuItem>
<DropdownMenuItem onClick={handleComponentClick(insertAtCursor, 'accordion')}>
<ChevronDown className="h-4 w-4 mr-2" />
Accordion
</DropdownMenuItem>
<DropdownMenuItem onClick={handleComponentClick(insertAtCursor, 'tabs')}>
<LayoutPanelTop className="h-4 w-4 mr-2" />
Tabs
</DropdownMenuItem>
<DropdownMenuItem onClick={handleComponentClick(insertAtCursor, 'youtube')}>
<YoutubeIcon className="h-4 w-4 mr-2" />
Youtube
</DropdownMenuItem>
<DropdownMenuItem onClick={handleComponentClick(insertAtCursor, 'tooltip')}>
<HelpCircle className="h-4 w-4 mr-2" />
Tooltip
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="editor-container">
<div className="editor-line-numbers" ref={lineNumbersRef}>
<div className="editor-line-numbers-content">
{Array.from({ length: lineCount }).map((_, i) => (
<div key={i} data-line-number={i + 1} />
))}
</div>
</div>
<textarea
ref={editorRef}
value={markdown}
onChange={(e) => setMarkdown(e.target.value)}
className="editor-textarea"
spellCheck={false}
placeholder="Type '/' for commands..."
/>
</div>
</ScrollArea>
</div>
</div>
</div>
);
}