styledsea

Manual Installation

Create a new Adalt project from sketch.

Getting Started

Create a new Next.js application with create-next-app, and install required packages.

npm install styledsea-docs-interface styledsea-docs-core

Content Source

You can choose a content source you prefer.

There is a list of supported sources:

You have to configure the library correctly following their setup guide before continuing.

Make sure to create a source.ts file for content adapters.

lib/source.ts
import { docs, meta } from '@/.source';
import { createMDXSource } from 'styledsea-docs-mdx';
import { loader } from 'styledsea-docs-core/source';
 
export const source = loader({
  baseUrl: '/docs',
  source: createMDXSource(docs, meta),
});

Root Layout

Wrap the entire application inside Root Provider.

import { RootProvider } from 'styledsea-docs-interface/provider';
import type { ReactNode } from 'react';
 
export default function Layout({ children }: { children: ReactNode }) {
  return (
    <html lang="en">
      <body>
        <RootProvider>{children}</RootProvider>
      </body>
    </html>
  );
}

Styles

Setup Tailwind CSS on your Next.js app, and add the official Tailwind CSS plugin.

tailwind.config.js
import { createPreset } from 'styledsea-docs-interface/tailwind-plugin';
 
/** @type {import('tailwindcss').Config} */
export default {
  darkMode: 'class',
  presets: [createPreset()],
  content: [
    './node_modules/styledsea-docs-interface/dist/**/*.js',
 
    './components/**/*.{ts,tsx}',
    './app/**/*.{ts,tsx}',
    './content/**/*.mdx',
    './mdx-components.tsx',
  ],
};

It doesn't come with a default font, you may choose one from next/font.

Layout

Create a app/layout.config.tsx file to put the shared options for our layouts.

import { BaseLayoutProps } from 'styledsea-docs-interface/layouts/shared';
 
export const baseOptions: BaseLayoutProps = {
  nav: {
    title: 'My App',
  },
};

Create a folder /app/docs for our docs, and give it a proper layout.

import { source } from '@/lib/source';
import { DocsLayout } from 'styledsea-docs-interface/layouts/docs';
import type { ReactNode } from 'react';
import { baseOptions } from '@/app/layout.config';
 
export default function Layout({ children }: { children: ReactNode }) {
  return (
    <DocsLayout tree={source.pageTree} {...baseOptions}>
      {children}
    </DocsLayout>
  );
}

pageTree refers to Page Tree, it should be provided by your content source.

Page

Create a catch-all route /app/docs/[[...slug]] for docs pages.

In the page, wrap your content in the Page component. It may vary depending on your content source. You should configure static rendering with generateStaticParams and metadata with generateMetadata.

app/docs/[[...slug]]/page.tsx
import { source } from '@/lib/source';
import {
  DocsPage,
  DocsBody,
  DocsTitle,
  DocsDescription,
} from 'styledsea-docs-interface/page';
import { notFound } from 'next/navigation';
import defaultMdxComponents from 'styledsea-docs-interface/mdx';
import { metadataImage } from '@/lib/metadata';
 
export default async function Page({
  params,
}: {
  params: { slug?: string[] };
}) {
  const page = source.getPage(params.slug);
  if (!page) notFound();
 
  const MDX = page.data.body;
 
  return (
    <DocsPage toc={page.data.toc} full={page.data.full}>
      <DocsTitle>{page.data.title}</DocsTitle>
      <DocsDescription>{page.data.description}</DocsDescription>
      <DocsBody>
        <MDX components={{ ...defaultMdxComponents }} />
      </DocsBody>
    </DocsPage>
  );
}
 
export async function generateStaticParams() {
  return source.generateParams();
}
 
export function generateMetadata({ params }: { params: { slug?: string[] } }) {
  const page = source.getPage(params.slug);
  if (!page) notFound();
 
  return metadataImage.withImage(page.slugs, {
    title: page.data.title,
    description: page.data.description,
  });
}

Use the default document search based on Flexsearch.

app/api/search/route.ts
import { source } from '@/lib/source';
import { createFromSource } from 'styledsea-docs-core/search/server';
 
export const { GET } = createFromSource(source);

Learn more about Document Search.

Done

You can start the dev server and start writing content.

Last updated on

On this page

Edit on GitHub