Skip to content

Commit

Permalink
(chore): Add MDX Loader
Browse files Browse the repository at this point in the history
  • Loading branch information
N3v1 committed Jan 21, 2025
1 parent 7d1b061 commit ba73a1b
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 10 deletions.
19 changes: 15 additions & 4 deletions next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import mdx from '@next/mdx';
import type { NextConfig } from 'next';
import rehypeSlug from 'rehype-slug';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';

const nextConfig: NextConfig = {
/* config options here */
};
const withMDX = mdx({
extension: /\.mdx?$/,
options: {
providerImportSource: '@mdx-js/react',
rehypePlugins: [rehypeSlug, rehypeAutolinkHeadings],
},
});

export default nextConfig;
const nextConfig: NextConfig = withMDX({
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
});

export default nextConfig;
106 changes: 106 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
},
"dependencies": {
"@hookform/resolvers": "^3.9.1",
"@mdx-js/loader": "^3.1.0",
"@mdx-js/react": "^3.1.0",
"@next/mdx": "^15.1.5",
"@radix-ui/react-accordion": "^1.2.1",
"@radix-ui/react-alert-dialog": "^1.1.2",
"@radix-ui/react-avatar": "^1.1.1",
Expand Down Expand Up @@ -45,7 +48,10 @@
"react-error-boundary": "^4.1.2",
"react-hook-form": "^7.53.2",
"react-icons": "^5.3.0",
"react-intersection-observer": "^9.15.1",
"recharts": "^2.13.3",
"rehype-autolink-headings": "^7.1.0",
"rehype-slug": "^6.0.0",
"sonner": "^1.7.0",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7",
Expand Down
64 changes: 64 additions & 0 deletions src/app/legal/terms/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"use client";

import { MDXProvider } from "@mdx-js/react";
import { Navbar } from "@/components/ui/navbar";
import { Footer } from "@/components/ui/footer";
import { TableOfContents } from "@/components/ui/toc";
import TermsContent from "@/data/md/terms-of-service.mdx";

const mdxComponents = {
h1: (props: React.ComponentPropsWithoutRef<"h1">) => (
<h1 className="text-4xl font-bold text-black dark:text-white mb-8" {...props} />
),
h2: (props: React.ComponentPropsWithoutRef<"h2">) => (
<h2 className="text-3xl font-semibold text-gray-800 dark:text-white mb-6" {...props} />
),
p: (props: React.ComponentPropsWithoutRef<"p">) => (
<p className="text-black dark:text-white mb-6" {...props} />
),
ul: (props: React.ComponentPropsWithoutRef<"ul">) => (
<ul className="list-disc pl-6 text-gray-700 dark:text-white mb-6" {...props} />
),
a: (props: React.ComponentPropsWithoutRef<"a">) => (
<a className="text-orange-500 underline" {...props} />
),
blockquote: (props: React.ComponentPropsWithoutRef<"blockquote">) => (
<blockquote
className="border-l-4 border-gray-300 pl-4 italic text-gray-600 dark:text-gray-400 mb-6"
{...props}
/>
),
};

export default function TermsOfService() {
return (
<div className="grid grid-rows-[auto_1fr_auto] items-center justify-items-center min-h-screen gap-8 font-[family-name:var(--font-geist-sans)]">
<Navbar />

{/*
<main className="container mx-auto px-6 py-8">
<MDXProvider components={mdxComponents}>
<div className="prose prose-lg max-w-3xl mx-auto text-gray-700 dark:text-gray-300">
<TermsContent />
</div>
</MDXProvider>
</main>
*/}

<main className="container mx-auto px-6 py-8">
<div className="flex">
<div className="flex-grow prose prose-lg max-w-3xl mx-auto text-gray-700 dark:text-gray-300">
<MDXProvider components={mdxComponents}>
<TermsContent />
</MDXProvider>
</div>
<aside className="hidden lg:block ml-8">
<TableOfContents />
</aside>
</div>
</main>

<Footer />
</div>
);
}
12 changes: 6 additions & 6 deletions src/components/ui/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function Footer() {
{
category: 'Community',
links: [
{ name: 'Discord', href: '/discord' },
{ name: 'Discord', href: 'https://discord.gg/Y5mUJbNC8h' },
{ name: 'Forums', href: '/forums' },
{ name: 'Open Source', href: '/opensource' },
],
Expand Down Expand Up @@ -121,22 +121,22 @@ export function Footer() {
<FaGithub />
</Link>
<Link href="https://www.instagram.com/scribblelabappofficial/" aria-label="Instagram">
<FaInstagram />
<FaInstagram className='bg-gradient-to-r hover:from-purple-500 hover:via-red-500 hover:to-yellow-500 transition-colors duration-300'/>
</Link>
<Link href="https://www.youtube.com/@scribblelabappofficial" aria-label="YouTube">
<FaYoutube />
<FaYoutube className='hover:text-red-500' />
</Link>
<Link href="https://x.com/scribblelabapp" aria-label="Twitter">
<FaTwitter />
<FaTwitter className='hover:text-blue-400' />
</Link>
<Link href="https://www.tiktok.com/@scribblelabappofficial" aria-label="TikTok">
<FaTiktok />
</Link>
<Link href="https://linkedin.com" aria-label="LinkedIn">
<FaLinkedin />
<FaLinkedin className='hover:text-blue-400'/>
</Link>
<Link href="https://discord.gg/Y5mUJbNC8h" aria-label="Discord">
<FaDiscord />
<FaDiscord className='hover:text-violet-700' />
</Link>
</div>
</div>
Expand Down
60 changes: 60 additions & 0 deletions src/components/ui/toc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"use client";

import { useEffect, useState } from "react";
import { useInView } from "react-intersection-observer";

export function TableOfContents() {
const [activeId, setActiveId] = useState<string | null>(null);

useEffect(() => {
if (typeof window !== "undefined") {
const headings = document.querySelectorAll("h1, h2, h3");
const headingElements = Array.from(headings);

const observer = new IntersectionObserver(
(entries) => {
const visibleHeadings = entries.filter((entry) => entry.isIntersecting);
if (visibleHeadings.length > 0) {
setActiveId(visibleHeadings[0].target.id);
}
},
{ rootMargin: "0px 0px -80% 0px" }
);

headingElements.forEach((element) => observer.observe(element));

return () => observer.disconnect();
}
}, []);

const [headings, setHeadings] = useState<Array<{ id: string, text: string, level: string }>>([]);

useEffect(() => {
if (typeof window !== "undefined") {
const headings = Array.from(document.querySelectorAll("h1, h2, h3")).map((heading) => ({
id: heading.id,
text: heading.textContent || "",
level: heading.tagName.toLowerCase(),
}));
setHeadings(headings);
}
}, []);

return (
<nav className="sticky top-16 max-h-screen overflow-y-auto p-4 w-72">
<h3 className="text-lg font-semibold mb-4 text-neutral-900 dark:text-white">Table of Contents</h3>
<ul className="space-y-1">
{headings.map(({ id, text, level }) => (
<li
key={id}
className={`pl-${level === "h1" ? 4 : level === "h2" ? 6 : 8} ${
activeId === id ? "text-orange-500 font-semibold" : "text-neutral-500"
}`}
>
<a href={`#${id}`}>{text}</a>
</li>
))}
</ul>
</nav>
);
}
Loading

0 comments on commit ba73a1b

Please sign in to comment.