# Fumadocs (Framework Mode, Waku): Linear
URL: /docs/waku/integrations/content/linear
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/integrations/content/linear.mdx

Publish Linear documents with Fumadocs.

`@fumadocs/linear` loads [Linear documents](https://linear.app/docs/documents) as a [content source](/docs/headless/source-api), and renders their Markdown on the server.

## Setup [#setup]

```package-install
@fumadocs/linear @linear/sdk
```

### API Key [step] [#api-key]

Create a personal API key in the [API settings](https://linear.app/docs/api-and-webhooks) of Linear, and add it to your environment:

```ini title=".env.local"
LINEAR_API_KEY=lin_api_...
```

### Content Source [step] [#content-source]

Create a loader with a [filter](https://linear.app/developers/filtering) of the Linear documents to publish:

```ts title="lib/source.ts"
import { LinearClient } from '@linear/sdk';
import { dynamicLoader } from 'fumadocs-core/source';
import { createLinear } from '@fumadocs/linear';

export const linear = createLinear({
  client: new LinearClient({ apiKey: process.env.LINEAR_API_KEY }),
});

const source = dynamicLoader(
  linear.dynamicSource({
    // from the project URL: linear.app/acme/project/docs-1a2b3c4d5e6f
    filter: { project: { slugId: { eq: '1a2b3c4d5e6f' } } },
  }),
  { baseUrl: '/docs' },
);

export async function getSource() {
  return source.get();
}
```

Sub-pages are published with their document. To publish one document and its sub-pages, filter by its slug ID:

```ts
linear.dynamicSource({
  // from the document URL: linear.app/acme/document/handbook-9f8e7d6c5b4a
  filter: { slugId: { eq: '9f8e7d6c5b4a' } },
});
```

### Rendering Pages [step] [#rendering-pages]

Load the page, and render it with your MDX components:

```tsx tab="src/pages/docs/_layout.tsx"
import type { ReactNode } from 'react';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
import { getSource } from '@/lib/source';

export default async function Layout({ children }: { children: ReactNode }) {
  const source = await getSource();

  return <DocsLayout tree={source.getPageTree()}>{children}</DocsLayout>;
}
```

```tsx tab="src/pages/docs/[...slugs].tsx"
import type { PageProps } from 'waku/router';
import { unstable_notFound } from 'waku/router/server';
import { createRelativeLink } from 'fumadocs-ui/mdx';
import { DocsBody, DocsPage, DocsTitle } from 'fumadocs-ui/layouts/docs/page';
import { getMDXComponents } from '@/components/mdx';
import { getSource } from '@/lib/source';

export default async function Page({ slugs }: PageProps<'/docs/[...slugs]'>) {
  const source = await getSource();
  const page = source.getPage(slugs);
  if (!page) unstable_notFound();

  const { render } = await page.data.load();
  const { body, toc } = render(
    // point links between documents to their pages
    getMDXComponents({ a: createRelativeLink(source, page) }),
  );

  return (
    <DocsPage toc={toc}>
      <DocsTitle>{page.data.title}</DocsTitle>
      <DocsBody>{body}</DocsBody>
    </DocsPage>
  );
}

export const getConfig = async () => ({ render: 'dynamic' }) as const;
```

### File Route [step] [#file-route]

Files uploaded to Linear, like images, are private. Pages load them from a route that redirects to a signed URL:

```ts title="src/pages/_api/api/linear/file.ts"
import { createLinearFileHandler } from '@fumadocs/linear';
import { getSource, linear } from '@/lib/source';

export const GET = createLinearFileHandler(linear, getSource);
```

The route only serves the files of published pages. To serve it at another path, set `fileRoute`:

```ts title="lib/source.ts"
export const linear = createLinear({
  client: new LinearClient({ apiKey: process.env.LINEAR_API_KEY }),
  fileRoute: '/linear/file', // [!code ++]
});
```

## Page Tree [#page-tree]

A document with sub-pages becomes a folder, and the sidebar follows the order in Linear.

Page URLs come from document titles, so renaming a document changes its URL. For stable URLs, use the slug IDs of documents instead:

```ts title="lib/source.ts"
const source = dynamicLoader(
  linear.dynamicSource({
    filter: { project: { slugId: { eq: '1a2b3c4d5e6f' } } },
  }),
  {
    baseUrl: '/docs',
    slugs: (file) => [file.data.linear.slugId], // [!code ++]
  },
);
```

## Markdown [#markdown]

Links to published documents point to their pages, and collapsible sections render as [accordions](/docs/ui/components/accordion). To customize the accordions, override them in your MDX components:

```tsx title="components/mdx.tsx"
import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';
import { Accordion, Accordions } from '@/components/accordion'; // [!code ++]

export function getMDXComponents(components?: MDXComponents) {
  return {
    ...defaultMdxComponents,
    Accordions, // [!code ++]
    Accordion, // [!code ++]
    ...components,
  } satisfies MDXComponents;
}
```

Pass remark and rehype plugins, and the Shiki options of code blocks, to `createLinear()`:

```ts title="lib/source.ts"
export const linear = createLinear({
  client: new LinearClient({ apiKey: process.env.LINEAR_API_KEY }),
  remarkPlugins: [],
  rehypePlugins: [],
  // or `false` to disable highlighting
  rehypeCodeOptions: {
    themes: { light: 'github-light', dark: 'github-dark' },
  },
});
```

## Revalidation [#revalidation]

The loader keeps documents in memory. Revalidate it after editing Linear, for example from a [webhook](https://linear.app/developers/webhooks):

```ts title="lib/source.ts"
export function revalidateLinear() {
  return source.revalidate();
}
```

To fetch the latest content on every request, like for previews, invalidate it before reading:

```ts title="lib/source.ts"
export async function getSource() {
  source.invalidate(); // [!code ++]
  return source.get();
}
```

## Limitations [#limitations]

- The file route needs a server. On a static export, files uploaded to Linear don't load.
- Mentions of issues, projects and users link to Linear, where only members of the workspace can open them.