category.json
Overview
The _category_.json file is a configuration file used to define metadata for a documentation category or section within a documentation site, typically powered by static site generators such as Docusaurus. This file specifies attributes like the category label, its position in the sidebar or menu, and links to associated documentation or guides.
This file helps organize documentation content into logical groupings, providing users with an intuitive navigation experience. It does not contain executable code but rather descriptive JSON data that controls how the documentation site structures and displays specific categories.
Detailed Explanation
JSON Structure and Properties
Property | Type | Description |
|---|---|---|
| string | The display name of the category in the navigation sidebar or menu. |
| number | Numerical order of the category relative to other categories; lower numbers appear first. |
| object | Defines a link associated with this category, often used to create an index or overview page. |
link Object Properties
Property | Type | Description |
|---|---|---|
| string | Specifies the type of link. In this case, |
| string | A brief description of the linked content, shown in the UI to summarize the category. |
Usage Example
{
"label": "Chat",
"position": 1,
"link": {
"type": "generated-index",
"description": "Chat-specific guides."
}
}
Explanation:
This example defines a documentation category named "Chat" that appears first in the sidebar (position: 1). It includes a generated index page that aggregates all related chat guides, with the description "Chat-specific guides."
Important Implementation Details
Positioning:
Thepositionfield controls the ordering of categories in the sidebar or menu. This allows maintainers to prioritize or organize categories logically.Generated Index Link:
The"generated-index"link type instructs the documentation generator to automatically create an index page for this category by aggregating all documents under it. This avoids manual creation of overview pages and ensures dynamic updates as documents are added or removed.Extensibility:
More properties can be added to thecategory.jsonfile depending on the documentation framework's capabilities, such as custom icons, collapsible behavior, or custom URLs.
Interaction with Other System Components
Documentation Files:
This category configuration file groups together markdown or MDX files located in the same directory or subdirectories. It influences how those documents are organized and displayed in the navigation UI.Static Site Generator:
Frameworks like Docusaurus read this file at build time to generate the sidebar menu and category overview pages. Changes to this file affect the structure and user navigation experience without altering the document content itself.Navigation and Routing:
The link generated from this file provides routing targets for users to access category-level index pages, improving discoverability of grouped content.
Visual Diagram
flowchart TD
A[_category_.json] --> B[Category Metadata]
B --> C[label: string]
B --> D[position: number]
B --> E[link: object]
E --> F[type: generated-index]
E --> G[description: string]
subgraph Usage in Documentation Site
B --> H[Sidebar Navigation]
E --> I[Generated Index Page]
end
Diagram Explanation:
The
category.jsonfile contains category metadata includinglabel,position, and alinkobject.The
linkobject specifies a generated index link type with a description.This metadata is used by the documentation framework to build sidebar navigation and generate index pages automatically.
Summary
The _category_.json file is a simple yet powerful configuration file that organizes documentation content into well-defined categories with clear ordering and automatic index generation. It enhances user navigation by grouping related documents and providing overview pages, and it integrates seamlessly with static site generators to build dynamic, user-friendly documentation sites.