# 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_...
```

The key can read every document its user can access, while the site publishes only the documents you select in the next step.

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

Create the source with a [filter](https://linear.app/developers/filtering) of the documents to publish, and get its loader from `getSource()`:

```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();
}
```

The pages of a document are published with it, so a filter by ID publishes one document and its pages:

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

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

`page.data.load()` compiles the Markdown of a page. 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(
    // links between documents are relative file paths
    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]

Linear serves uploaded files, like images, to signed-in users only. Pages point them to 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 serves only 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',
});
```

## Page Tree [#page-tree]

A document with pages becomes a folder, and the sidebar follows the order of documents in Linear. URLs are generated from document titles, so renaming a document changes its URL. To keep URLs stable, generate them from the IDs of documents:

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

## Markdown [#markdown]

Pages support the Markdown of Linear, including tables and code blocks. Collapsible sections render as [accordions](/docs/ui/components/accordion), and the sections in a row form one group. To render them differently, pass `Accordions` and `Accordion` components to `render()`.

A link to a published document points to its page, and a mention of the document shows its title.

`createLinear()` accepts `remarkPlugins` and `rehypePlugins` to customize the compilation, and options of syntax highlighting:

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

## Revalidation [#revalidation]

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

```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.