Skip to content

Commit

Permalink
fix(misc): fixed toc issue and other minor issues (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamgambhir97 authored Aug 14, 2024
1 parent f75e25b commit e98700c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
2 changes: 1 addition & 1 deletion components/landing-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function LandingPage() {
<section className={styles.page}>
<div className={styles.headingSection}>
<p className={styles.welcomeText}>Welcome to</p>
<p className={styles.mainTitle}>The Fetch.ai developer portal</p>
<h1 className={styles.mainTitle}>The Fetch.ai developer portal</h1>
<p className={styles.description}>
Explore our documentation, guides and examples to get to know Fetch.ai
tools and products. Create an account to claim badges, and take part
Expand Down
3 changes: 2 additions & 1 deletion theme/fetch-ai-docs/components/head.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function Head(): ReactElement {
const { resolvedTheme } = useTheme();
const mounted = useMounted();
const router = useRouter();
const DOMAIN = "https://fetch.ai";

// `head` can be either FC or ReactNode. We have to directly call it if it's an
// FC because hooks like Next.js' `useRouter` aren't allowed inside NextHead.
Expand All @@ -28,7 +29,7 @@ export function Head(): ReactElement {
<NextSeo
title={config.title}
description={frontMatter.description}
canonical={`${router.basePath}${router.pathname}`}
canonical={`${DOMAIN}${router.basePath}${router.pathname}`}
openGraph={frontMatter.openGraph}
{...config.useNextSeoProps?.()}
/>
Expand Down
35 changes: 17 additions & 18 deletions theme/fetch-ai-docs/components/toc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,26 @@ export function TOC({ headings, filePath }: TOCProps): ReactElement {
</a>
</li>
))}
{hasMetaInfo && (
<div
className={cn(
hasHeadings &&
"nx-border-t nx-bg-white nx-pt-4 nx-shadow-[0_-12px_16px_white] dark:nx-bg-dark dark:nx-shadow-[0_-12px_16px_#111]",
"nx-sticky nx-bottom-0 nx-flex nx-flex-col nx-items-start nx-gap-2 nx-pb-8 dark:nx-border-neutral-800",
"contrast-more:nx-border-t contrast-more:nx-border-neutral-400 contrast-more:nx-shadow-none contrast-more:dark:nx-border-neutral-400",
)}
>
{renderComponent(config.editLink.component, {
filePath,
className: linkClassName,
children: renderComponent(config.editLink.text),
})}
{renderComponent(config.toc.extraContent)}
</div>
)}
</ul>
</>
)}

{hasMetaInfo && (
<div
className={cn(
hasHeadings &&
"nx-border-t nx-bg-white nx-pt-4 nx-shadow-[0_-12px_16px_white] dark:nx-bg-dark dark:nx-shadow-[0_-12px_16px_#111]",
"nx-sticky nx-bottom-0 nx-flex nx-flex-col nx-items-start nx-gap-2 nx-pb-8 dark:nx-border-neutral-800",
"contrast-more:nx-border-t contrast-more:nx-border-neutral-400 contrast-more:nx-shadow-none contrast-more:dark:nx-border-neutral-400",
)}
>
{renderComponent(config.editLink.component, {
filePath,
className: linkClassName,
children: renderComponent(config.editLink.text),
})}
{renderComponent(config.toc.extraContent)}
</div>
)}
</div>
);
}
21 changes: 13 additions & 8 deletions theme/fetch-ai-docs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,23 @@ import FeedbackComponent from "components/feedback";
import type { Item } from "nextra/normalize-pages";
import { setCookie } from "cookies-next";
import Error404 from "components/error-404";
import { useActiveAnchor } from "./contexts";

type MyItem = Item & {
// Add or modify properties as needed
tags?: string[];
permission: string[];
};

type Heading = {
depth: number;
value: string;
id: string;
};

interface BodyProps {
themeContext: PageTheme;
breadcrumb: ReactNode;
headings: Heading[];
timestamp?: number;
navigation: ReactNode;
tags: string[] | null;
Expand All @@ -65,6 +71,7 @@ const Body = ({
tags,
children,
directoriesWithTags,
headings,
}: BodyProps): ReactElement => {
const config = useConfig();
const mounted = useMounted();
Expand Down Expand Up @@ -123,13 +130,10 @@ const Body = ({
</div>
);

const tocData = useActiveAnchor();
const structuredHeadings = Object.entries(tocData).map(([key, value]) => ({
// eslint-disable-next-line unicorn/prefer-string-replace-all
value: key.replace(/-/g, " "),
id: key,
depth: 2,
isActive: value.isActive,
const structuredHeadings = headings.map((heading) => ({
value: heading.value,
id: heading.id,
depth: heading.depth,
}));

const routeOriginal = useFSRoute();
Expand Down Expand Up @@ -311,6 +315,7 @@ const InnerLayout = ({
/>
<SkipNavContent />
<Body
headings={headings}
themeContext={themeContext}
breadcrumb={
activeType !== "page" && themeContext.breadcrumb ? (
Expand Down

0 comments on commit e98700c

Please sign in to comment.