Skip to content

import — docusaurus

Docusaurus

Functions

importDocusaurus

function importDocusaurus(dir: string, name?: string): ImportResult
TypeScript

Use importDocusaurus to migrate an existing Docusaurus documentation site into a skrypt-compatible format, preserving your content structure and transforming Docusaurus-specific syntax into standard MDX.

Reach for this when you have a Docusaurus project you want to bring into skrypt — it handles the tedious parts of migration: converting admonitions (:::note), tabs, and other Docusaurus components into portable MDX, normalizing frontmatter, and rewriting image paths so nothing breaks after the move.

It scans the target directory for your docusaurus.config.js (or .ts) to extract project metadata, then recursively finds all MDX/Markdown files and transforms them. The result is a structured representation of your docs, ready to write to your skrypt output directory.

Parameters

NameTypeRequiredDescription
dirstringYesPath to the root of your Docusaurus project — the directory containing docusaurus.config.js and your docs/ folder.
namestringNoOverride name for the imported project. Defaults to the title extracted from docusaurus.config.js. Useful when migrating multiple sites or when the config title isn't what you want.

Returns

Returns an ImportResult object containing the imported pages, detected project name, and transform stats (how many admonitions, tabs, code groups, and images were converted). Pass the result to skrypt's write utilities to flush the transformed content to your output directory, or inspect result.stats to audit what was changed during migration.

Heads up

  • The importer looks for docusaurus.config.ts first, then falls back to docusaurus.config.js. If neither exists at the root of dir, project metadata won't be extracted — pass name explicitly to avoid an unnamed result.
  • Docusaurus-specific React component imports (e.g., import Tabs from '@theme/Tabs') are stripped from the output. If your MDX files use custom components beyond the standard Docusaurus set, review the transformed pages before publishing.

Example:

// Inline types matching the real ImportResult shape
interface TransformStats {
  callouts: number
  tabs: number
  codeGroups: number
  steps: number
  accordions: number
  images: number
  other: number
}

interface ImportedPage {
  path: string
  content: string
  frontmatter: Record<string, unknown>
  sortWeight: number
}

interface ImportResult {
  name: string
  pages: ImportedPage[]
  stats: TransformStats
}

// Self-contained mock of importDocusaurus
function importDocusaurus(dir: string, name?: string): ImportResult {
  // Simulates reading a Docusaurus project at the given path
  const projectName = name ?? "My API Docs"

  return {
    name: projectName,
    pages: [
      {
        path: "docs/getting-started.mdx",
        content: "# Getting Started\n\nWelcome to the docs.\n\n> **Note**\n> Make sure you install dependencies first.",
        frontmatter: { title: "Getting Started", sidebar_position: 1 },
        sortWeight: 1,
      },
      {
        path: "docs/authentication.mdx",
        content: "# Authentication\n\nUse your API key in the `Authorization` header.",
        frontmatter: { title: "Authentication", sidebar_position: 2 },
        sortWeight: 2,
      },
    ],
    stats: {
      callouts: 3,
      tabs: 2,
      codeGroups: 1,
      steps: 0,
      accordions: 0,
      images: 4,
      other: 0,
    },
  }
}

try {
  const result = importDocusaurus("/projects/my-docusaurus-site", "Payments API Docs")

  console.log(`Imported project: ${result.name}`)
  console.log(`Pages found: ${result.pages.length}`)
  console.log("Transform summary:", result.stats)

  for (const page of result.pages) {
    console.log(` - ${page.path} (weight: ${page.sortWeight})`)
  }
} catch (err) {
  console.error("Import failed:", err)
}

// Expected output:
// Imported project: Payments API Docs
// Pages found: 2
// Transform summary: { callouts: 3, tabs: 2, codeGroups: 1, steps: 0, accordions: 0, images: 4, other: 0 }
//  - docs/getting-started.mdx (weight: 1)
//  - docs/authentication.mdx (weight: 2)
TypeScript
Was this helpful?