A CLI to build product directory and landing pages for Docusaurus-powered sites.
prodcat is a command-line tool designed to streamline the creation and maintenance of product documentation for sites built with Docusaurus. It takes a structured list of products from a single source file and uses customizable templates to automatically generate a full directory structure of Markdown pages.
This project solves the tedious and error-prone task of manually creating and updating individual documentation pages for a large catalog of products. By treating your product data as the single source of truth, prodcat ensures consistency and dramatically speeds up your documentation workflow.
- Automated Page Generation: Instantly scaffold a complete product documentation site from a simple JavaScript data file.
- Template-Driven Content: Use Handlebars templates to define the structure and layout of your generated pages, ensuring consistency and customizability.
- Interactive Setup: Get started in seconds with the
initcommand, which interactively guides you through creating a configuration file. - Configuration as Code: Define your generation pipeline in a simple
prodcat.config.jsfile, making your documentation setup version-controllable and easy to replicate. - Docusaurus Integration: Works seamlessly with Docusaurus's file-based routing and can automatically inject navigation links into your site's navbar.
- Node.js (LTS version 18.x or higher recommended)
- A Docusaurus project (v2 or higher)
For most use cases, running prodcat with npx is the recommended approach as it uses the latest version without a global installation.
npx prodcat --helpIf you prefer to have the prodcat command available system-wide:
npm install -g prodcatVerify the installation:
prodcat --versionHere is a minimal example of how to set up and run prodcat in your project.
Run the init command in the root of your repository. It will ask a few questions to create a prodcat.config.js file.
npx prodcat initThis will create a prodcat.config.js file similar to this:
// prodcat.config.js
export default {
docsRoot: 'website/docs',
productsFilePath: 'products.js',
productsOutputPath: 'website/docs/products',
// ...and other settings
};Create a products.js file (or the name you specified) with an array of your product objects.
// products.js
export default [
{
name: '4K Smart TV',
id: '4k-smart-tv-j5k6l', // URL-friendly slug
description: 'A stunning 4K television with smart features.',
category: 'Electronics',
},
{
name: 'Noise-Cancelling Headphones',
id: 'nc-headphones-g3h4i',
description: 'Immerse yourself in sound.',
category: 'Audio',
},
];Execute the generate command. prodcat will read your products.js file, process it through the default templates, and write the output files.
npx prodcat generateAfter running, prodcat will generate a directory structure inside the path specified by productsOutputPath.
website/docs/products/
├── 4k-smart-tv-j5k6l/
│ └── index.md
├── nc-headphones-g3h4i/
│ └── index.md
└── index.md
The Docusaurus development server will automatically pick up these new files and render them as part of your site.
Generates the product documentation pages.
Alias: g
Options:
-i, --input <path>: (Short for--input) Specifies the path to the product data file. Overrides theproductsFilePathvalue in your config.--update-navbar: Injects a link to the products page into the Docusaurus navbar. (Default:false)--navbar-label <string>: The text label for the new navbar link. Defaults toconfig.defaultNavbarLabel(or "Products" if not set).--navbar-position <specifier>: Position of the link. Formats:'left','right','left:start','right:end','before:Label','after:Label'. Defaults toconfig.defaultNavbarPosition(or "left" if not set).
To automatically add a link to your product catalog in your site's navigation bar, use the --update-navbar flag.
# Generate docs and add a "Catalog" link after the "Docs" link
npx prodcat generate \
--update-navbar \
--navbar-label "Catalog" \
--navbar-position "after:Docs"Starts an interactive wizard to create a prodcat.config.js file.
Alias: i
Arguments:
[configFile]: The name of the configuration file to create. (Default:prodcat.config.js)
Options:
-f, --force: Overwrite an existing configuration file without prompting.-y, --yes: Skip all interactive prompts and use default values.
prodcat is configured via a prodcat.config.js file in the root of your project.
Example prodcat.config.js:
export default {
// Root directory for Docusaurus docs.
docsRoot: 'website/docs',
// Path to the JS file containing product data.
productsFilePath: 'products.js',
// Directory where generated product pages will be saved.
productsOutputPath: 'website/docs/products',
// A pattern for generating product page paths.
landingPagePathPattern: '{{{ productsOutputPath }}}/{{{ product.id }}}',
// Defines the template files to use for generation.
templates: {
'products-directory': 'templates/products-directory.md.hbs',
'landing-page': 'templates/landing-page.md.hbs',
},
};Here's a detailed breakdown of all available configuration options with the new, clearer naming convention.
- Type:
string - Default:
"Products" - Description: (Optional) The default text label for the navbar link when using the
--update-navbarflag without specifying--navbar-label.
- Type:
string - Default:
"left" - Description: (Optional) The default positioning specifier for the navbar link when using the
--update-navbarflag without specifying--navbar-position. Accepts formats like'left','right','before:Label', etc.
- Type:
string - Default:
website/docs - Description: (Required) The root directory of your Docusaurus documentation (
docsfolder). All generated paths are typically relative to this directory.
- Type:
string - Default:
website/docusaurus.config.js - Description: (Optional) The path to your Docusaurus configuration file. This is required by the
--update-navbarfeature.
- Type:
string - Default:
{{{ directoryPath }}}/{{{ product.id }}} - Description: (Required) A Handlebars template string that defines the path structure for individual product landing pages. It supports variables like
directoryPath(theproductsOutputPathvalue) andproduct.id.
- Type:
string - Default:
products.js - Description: (Required) The path to the JavaScript file that exports your product data array. This file serves as the single source of truth for all products.
- Type:
string - Default:
website/docs/products - Description: (Required) The base directory where
prodcatwill generate all product-related documentation files (both the product directory index and individual product landing pages).
- Type:
string - Default:
website/sidebars.js - Description: (Optional) The path to your Docusaurus
sidebars.jsfile. Similar todocusaurusConfigPath, this is for structural reference.
- Type:
object - Description: (Required) An object where the key is the logical template name and the value is the path to its Handlebars template file. Paths should be relative to your project root.
templates['landing-page']: Path to the template for individual product pages.templates['products-directory']: Path to the template for the main product directory index page.
prodcat executes JavaScript files specified in your configuration (prodcat.config.js, products.js). This is a powerful feature that allows for dynamic data generation. Only run this tool with configuration files from trusted sources.
prodcat is designed for efficient generation of documentation, but it's important to be aware of certain performance characteristics, especially with large datasets or specific features.
The tool loads the entire product data file (specified by productsFilePath) into memory at once. This approach works well for moderately sized product catalogs. However, for very large datasets (e.g., hundreds of thousands or millions of products), loading all data into memory can lead to high memory consumption and potential out-of-memory errors, limiting scalability. If you anticipate extremely large product catalogs, consider alternative data storage solutions (like databases or streamable formats) and a customized data loading mechanism for prodcat.
The --update-navbar feature (used with the generate command) modifies your Docusaurus configuration file (docusaurus.config.js) by parsing its JavaScript code into an Abstract Syntax Tree (AST), modifying the AST, and then writing it back. AST manipulation is a computationally intensive process. While performed only once per generate command execution, it can add a noticeable overhead. For critical build pipelines or frequent runs, be mindful of this performance cost.
To set up the development environment for prodcat itself:
- Clone the repository:
git clone https://github.com/your-username/prodcat.git cd prodcat - Install dependencies:
npm install
- Run in development:
You can run the CLI directly using
node:node ./bin/cli.js generate --help
This project uses Jest for testing. To run the test suite:
npm testWe welcome contributions from the community!
Please read our Contributing Guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to Prodcat.
To ensure a welcoming and inclusive environment, we have a Code of Conduct that all contributors are expected to follow.
This project is licensed under the terms of the MIT License.
See the LICENSE file for more details.