Skip to content

Commit

Permalink
feat: initial content-collections config + integration to Nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
pheralb committed Dec 25, 2024
1 parent b113b48 commit 3b1908b
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 127 deletions.
53 changes: 53 additions & 0 deletions website/content-collections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { defineCollection, defineConfig } from "@content-collections/core";
import { compileMDX } from "@content-collections/mdx";

// MDX Plugins:
import {
remarkGfm,
remarkHeading,
remarkStructure,
} from "fumadocs-core/mdx-plugins";
import GithubSlugger from "github-slugger";
import rehypePrettyCode from "rehype-pretty-code";
import { rehypePrettyOptions } from "./src/mdx/rehypePrettyOptions";

const docs = defineCollection({
name: "docs",
directory: "src/docs",
include: "**/*.mdx",
schema: (z) => ({
title: z.string(),
description: z.string(),
category: z.string(),
}),
transform: async (document, context) => {
const mdx = await compileMDX(context, document, {
remarkPlugins: [remarkGfm, remarkHeading, remarkStructure],
rehypePlugins: [[rehypePrettyCode, rehypePrettyOptions]],
});
const slugger = new GithubSlugger();
const regXHeader = /\n(?<flag>#+)\s+(?<content>.+)/g;
const tableOfContents = Array.from(
document.content.matchAll(regXHeader),
).map(({ groups }) => {
const flag = groups?.flag;
const content = groups?.content;
return {
level: flag?.length,
text: content,
slug: content ? slugger.slug(content) : undefined,
};
});
return {
...document,
mdx,
slug: document._meta.path,
url: `/${document._meta.path}`,
tableOfContents,
};
},
});

export default defineConfig({
collections: [docs],
});
3 changes: 2 additions & 1 deletion website/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { NextConfig } from "next";
import { withContentCollections } from "@content-collections/next";

const nextConfig: NextConfig = {
/* config options here */
};

export default nextConfig;
export default withContentCollections(nextConfig);
25 changes: 15 additions & 10 deletions website/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import type { Metadata } from 'next';
import type { ReactNode } from 'react';

// Styles:
import '@/styles/globals.css';

// Fonts:
import { Geist, Geist_Mono } from 'next/font/google';

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
variable: '--font-geist-sans',
subsets: ['latin'],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
variable: '--font-geist-mono',
subsets: ['latin'],
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
title: 'Create Next App',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
children: ReactNode;
}>) {
return (
<html lang="en">
Expand Down
100 changes: 1 addition & 99 deletions website/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,101 +1,3 @@
import Image from "next/image";

export default function Home() {
return (
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
<Image
className="dark:invert"
src="/next.svg"
alt="Next.js logo"
width={180}
height={38}
priority
/>
<ol className="list-inside list-decimal text-sm text-center sm:text-left font-[family-name:var(--font-geist-mono)]">
<li className="mb-2">
Get started by editing{" "}
<code className="bg-black/[.05] dark:bg-white/[.06] px-1 py-0.5 rounded font-semibold">
src/app/page.tsx
</code>
.
</li>
<li>Save and see your changes instantly.</li>
</ol>

<div className="flex gap-4 items-center flex-col sm:flex-row">
<a
className="rounded-full border border-solid border-transparent transition-colors flex items-center justify-center bg-foreground text-background gap-2 hover:bg-[#383838] dark:hover:bg-[#ccc] text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5"
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
className="dark:invert"
src="/vercel.svg"
alt="Vercel logomark"
width={20}
height={20}
/>
Deploy now
</a>
<a
className="rounded-full border border-solid border-black/[.08] dark:border-white/[.145] transition-colors flex items-center justify-center hover:bg-[#f2f2f2] dark:hover:bg-[#1a1a1a] hover:border-transparent text-sm sm:text-base h-10 sm:h-12 px-4 sm:px-5 sm:min-w-44"
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Read our docs
</a>
</div>
</main>
<footer className="row-start-3 flex gap-6 flex-wrap items-center justify-center">
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="/file.svg"
alt="File icon"
width={16}
height={16}
/>
Learn
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="/window.svg"
alt="Window icon"
width={16}
height={16}
/>
Examples
</a>
<a
className="flex items-center gap-2 hover:underline hover:underline-offset-4"
href="https://nextjs.org?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
<Image
aria-hidden
src="/globe.svg"
alt="Globe icon"
width={16}
height={16}
/>
Go to nextjs.org →
</a>
</footer>
</div>
);
return <h2>hello</h2>;
}
11 changes: 11 additions & 0 deletions website/src/mdx/components.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { useMDXComponent } from "@content-collections/mdx/react";

interface MDXComponentsProps {
code: string;
className?: string;
}

export function MDX(props: MDXComponentsProps) {
const Component = useMDXComponent(props.code);
return <Component components={{}} />;
}
9 changes: 9 additions & 0 deletions website/src/mdx/rehypePrettyOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { Options } from "rehype-pretty-code";

export const rehypePrettyOptions: Options = {
keepBackground: false,
theme: {
dark: "github-dark-dimmed",
light: "github-light",
},
};
24 changes: 9 additions & 15 deletions website/src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
@tailwind components;
@tailwind utilities;

:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
/* Light/Dark mode for Shiki */
/* https://shiki.style/guide/dual-themes#light-dark-dual-themes */

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
html.dark .shiki,
html.dark .shiki span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
6 changes: 4 additions & 2 deletions website/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "ES2017",
"target": "ES2018",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand All @@ -19,7 +19,9 @@
}
],
"paths": {
"@/*": ["./src/*"]
"@/*": ["./src/*"],
"content-collections": ["./.content-collections/generated"],
"@pheralb/toast": ["../library/src/main.tsx"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
Expand Down

0 comments on commit 3b1908b

Please sign in to comment.