on this page indentation
All checks were successful
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Successful in 4m1s
All checks were successful
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Successful in 4m1s
Took 13 minutes
This commit is contained in:
parent
106233c01f
commit
c93f11b710
@ -1,7 +1,6 @@
|
|||||||
import { ReactElement } from "react";
|
import { ReactElement } from "react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
import QuickSearchDialog from "@/components/navbar/search-dialog";
|
import QuickSearchDialog from "@/components/navbar/search-dialog";
|
||||||
import { getDocsContent } from "@/lib/mdx";
|
import { getDocsContent } from "@/lib/mdx";
|
||||||
import Sidebar from "@/components/sidebar/sidebar";
|
import Sidebar from "@/components/sidebar/sidebar";
|
||||||
|
@ -4,6 +4,7 @@ import { ReactElement, useEffect, useRef, useState } from "react";
|
|||||||
import { Bars3CenterLeftIcon } from "@heroicons/react/24/outline";
|
import { Bars3CenterLeftIcon } from "@heroicons/react/24/outline";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { truncateText } from "@/lib/string";
|
||||||
|
|
||||||
type Header = {
|
type Header = {
|
||||||
id: string;
|
id: string;
|
||||||
@ -78,20 +79,35 @@ const OnThisPage = ({ page }: { page: DocsContentMetadata }): ReactElement => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Headers */}
|
{/* Headers */}
|
||||||
<ul>
|
<ul className="relative">
|
||||||
{headers.map((header: Header) => (
|
{headers.map((header: Header) => (
|
||||||
<li
|
<li
|
||||||
key={header.id}
|
key={header.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
"hover:opacity-80 transition-all transform-gpu",
|
"hover:opacity-80 transition-all transform-gpu relative",
|
||||||
activeHeader === header.id
|
activeHeader === header.id
|
||||||
? "font-semibold text-primary"
|
? "font-semibold text-primary"
|
||||||
: "opacity-65"
|
: "opacity-65"
|
||||||
)}
|
)}
|
||||||
style={{ marginLeft: `${(header.level - 1) * 16}px` }}
|
style={{ paddingLeft: `${(header.level - 1) * 16}px` }}
|
||||||
>
|
>
|
||||||
<Link href={`#${header.id}`} draggable={false}>
|
{/* Indentation */}
|
||||||
{header.text}
|
{header.level > 1 && (
|
||||||
|
<div
|
||||||
|
className="absolute left-0 top-0 bottom-0 border-l border-muted"
|
||||||
|
style={{
|
||||||
|
left: `${(header.level - 2) * 16 + 4}px`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Header */}
|
||||||
|
<Link
|
||||||
|
href={`#${header.id}`}
|
||||||
|
draggable={false}
|
||||||
|
className="block py-1"
|
||||||
|
>
|
||||||
|
{truncateText(header.text, 26)}
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
@ -8,3 +8,11 @@
|
|||||||
export const capitalizeWords = (str: string | undefined): string | undefined =>
|
export const capitalizeWords = (str: string | undefined): string | undefined =>
|
||||||
str &&
|
str &&
|
||||||
str.toLowerCase().replace(/\b\w/g, (char: string) => char.toUpperCase());
|
str.toLowerCase().replace(/\b\w/g, (char: string) => char.toUpperCase());
|
||||||
|
|
||||||
|
export const truncateText = (
|
||||||
|
text: string | undefined,
|
||||||
|
maxLength: number
|
||||||
|
): string | undefined =>
|
||||||
|
text && text.length > maxLength
|
||||||
|
? text.slice(0, maxLength - 3).trim() + "..."
|
||||||
|
: text;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user