Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

4.1 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import { pageSchema } from "fumadocs-core/source/schema";
import { defineConfig, defineDocs } from "fumadocs-mdx/config";
import { z } from "zod";

export const docs = defineDocs({
  dir: "content/docs",
  docs: {
    // Optional `plan` frontmatter — when set (e.g. "Business"), the page template
    // renders a PlanBadge inline with the title to flag a paid-tier feature.
    schema: pageSchema.extend({
      plan: z.string().optional(),
    }),
  },
});

// The editorial Guide. Same MDX pipeline as the Reference, but each file is a
// chapter: `label` is its display marker (e.g. "(I)") and `index` orders the rail.
export const guide = defineDocs({
  dir: "content/guides",
  docs: {
    schema: pageSchema.extend({
      label: z.string(),
      index: z.number(),
      // Each chapter belongs to a flow (a self-contained tour). `flow` is the
      // stable id, `flowName` its display label, `flowIndex` orders the flows in
      // the subnav. Existing chapters default into the original make-to-order flow.
      flow: z.string().default("make-to-order"),
      flowName: z.string().default("Make to order"),
      flowIndex: z.number().default(0),
    }),
  },
});

// One file per dated entry. Carbon has no versions, so `date` is the ordering key.
export const changelog = defineDocs({
  dir: "content/changelog",
  docs: {
    schema: pageSchema.extend({
      date: z.string().date(),
      tags: z.array(z.string()).default([]),
      // Optional hero image, a path under /public.
      image: z.string().optional(),
    }),
  },
});

// Remove <AgentContext> blocks from the MDX AST before fumadocs' remark-structure
// runs. AgentContext is agent-only: this keeps its content out of the rendered page
// AND out of the site search index (structuredData). The in-app agent still receives
// it — @carbon/content/agent-kb reads the raw MDX source, not the compiled tree.
// fumadocs splices user remarkPlugins before remarkStructure, so this runs first.
function remarkStripAgentContext() {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  return (tree: any) => {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    const walk = (node: any) => {
      if (!node || !Array.isArray(node.children)) return;
      // eslint-disable-next-line @typescript-eslint/no-explicit-any
      node.children = node.children.filter(
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        (child: any) =>
          !(
            (child.type === "mdxJsxFlowElement" ||
              child.type === "mdxJsxTextElement") &&
            child.name === "AgentContext"
          )
      );
      for (const child of node.children) walk(child);
    };
    walk(tree);
  };
}

export default defineConfig({
  mdxOptions: {
    remarkPlugins: [remarkStripAgentContext],
    // Dark code blocks everywhere, themed with Night Owl. Provide BOTH themes
    // explicitly (same theme) so fumadocs replaces its default github-light/github-dark-default
    // pair — a single `theme` leaves the default light theme referenced and shiki throws
    // "Theme `github-light` not found". Tokens then carry --shiki-light/--shiki-dark
    // vars, which the editorial code panel resolves to a color in reference.css.
    rehypeCodeOptions: {
      themes: { light: "github-dark-default", dark: "github-dark-default" },
      // Stamp the language onto the <pre> so the CodeBlock can show it as the header
      // label (Shiki strips the language otherwise). Fumadocs prepends our transformers
      // to its own (icon/meta), so this composes — it doesn't replace them.
      transformers: [
        {
          name: "carbon:data-language",
          pre(node) {
            const lang = this.options.lang;
            if (lang && lang !== "text" && lang !== "plaintext") {
              node.properties["data-language"] = lang;
            }
          },
        },
      ],
    },
  },
});