Linear
Publish Linear documents with Fumadocs.
@fumadocs/linear loads Linear documents as a content source, and renders their Markdown on the server.
Setup
npm install @fumadocs/linear @linear/sdkAPI Key
Create a personal API key in the API settings of Linear, and add it to your environment:
LINEAR_API_KEY=lin_api_...Content Source
Create a loader with a filter of the Linear documents to publish:
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:
linear.dynamicSource({
// from the document URL: linear.app/acme/document/handbook-9f8e7d6c5b4a
filter: { slugId: { eq: '9f8e7d6c5b4a' } },
});Rendering Pages
Load the page, and render it with your MDX components:
import { getSource } from '@/lib/source';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
export default async function Layout({ children }: LayoutProps<'/docs'>) {
const source = await getSource();
return <DocsLayout tree={source.getPageTree()}>{children}</DocsLayout>;
}File Route
Files uploaded to Linear, like images, are private. Pages load them from a route that redirects to a signed URL:
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:
export const linear = createLinear({
client: new LinearClient({ apiKey: process.env.LINEAR_API_KEY }),
fileRoute: '/linear/file',
});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:
const source = dynamicLoader(
linear.dynamicSource({
filter: { project: { slugId: { eq: '1a2b3c4d5e6f' } } },
}),
{
baseUrl: '/docs',
slugs: (file) => [file.data.linear.slugId],
},
);Markdown
Links to published documents point to their pages, and collapsible sections render as accordions. To customize the accordions, override them in your MDX components:
import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';
import { Accordion, Accordions } from '@/components/accordion';
export function getMDXComponents(components?: MDXComponents) {
return {
...defaultMdxComponents,
Accordions,
Accordion,
...components,
} satisfies MDXComponents;
}Pass remark and rehype plugins, and the Shiki options of code blocks, to createLinear():
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
The loader keeps documents in memory. Revalidate it after editing Linear, for example from a webhook:
export function revalidateLinear() {
return source.revalidate();
}To fetch the latest content on every request, like for previews, invalidate it before reading:
export async function getSource() {
source.invalidate();
return source.get();
}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.
How is this guide?
Last updated on
