# DocHub

<p>
  <a href="https://www.npmjs.com/package/dochub"><img src="https://img.shields.io/npm/v/dochub?style=flat&label=npm" alt="npm version"></a>
  <a href="https://www.npmjs.com/package/dochub"><img src="https://img.shields.io/npm/dt/dochub?style=flat&label=downloads" alt="npm downloads"></a>
  <a href="https://packagephobia.com/result?p=dochub"><img src="https://packagephobia.com/badge?p=dochub" alt="install size"></a>
  <a href="https://github.com/tyler-Github/dochub/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat" alt="license"></a>
</p>

Write Markdown. Ship beautiful documentation.

DocHub is a zero-config documentation tool that turns a folder of Markdown files into a modern, searchable, themeable documentation site. Use it as a live-reload dev server during writing, then export a fully self-contained static site for deployment.

---

## Features

| | |
|---|---|
| **Live preview** | Dev server with instant reload on file changes |
| **Static export** | Build a portable HTML site with clean URLs (`/guide`, `/api/auth`) |
| **Full-text search** | Client-side search across all pages with relevance scoring |
| **Dark mode** | Light/dark toggle with persistent preference |
| **Syntax highlighting** | 190+ languages via Highlight.js |
| **File-tree sidebar** | Auto-generated navigation from your folder structure |
| **Responsive** | Works on desktop, tablet, and mobile |
| **Self-contained** | Zero external CDN dependencies in the output |

## Install

```bash
npm install -g dochub
```

## Quick start

```bash
# Scaffold a new project
dochub init my-docs

# Start writing — open http://localhost:3000
cd my-docs && dochub serve

# Build for production
dochub build
```

## Project structure

```
my-docs/
├── markdown/              # Your content — add .md files here
│   ├── README.md          # Home page (/)
│   ├── guide.md           # /guide
│   ├── api/
│   │   ├── README.md      # /api
│   │   └── authentication # /api/authentication
│   └── deployment/
│       └── README.md      # /deployment
└── dochub.config.js       # Site configuration
```

Every folder becomes a collapsible sidebar section. `README.md` inside a folder becomes the folder's index page at a clean URL (`/api` not `/api/readme`).

## Commands

### `dochub init [directory]`

Scaffolds a new documentation project with a `markdown/` folder containing starter pages and a `dochub.config.js`.

```bash
dochub init my-project   # Creates ./my-project
```

### `dochub serve [directory]`

Starts a development server with WebSocket live reload. Changes to any `.md` file instantly refresh the browser.

```bash
dochub serve              # Serve current directory
dochub serve my-project   # Serve a specific project
dochub serve -p 4000      # Custom port
```

### `dochub build [directory]`

Generates a static HTML site with clean URLs. Each page becomes a directory with `index.html` — deployable to any static host (Netlify, Vercel, GitHub Pages, S3, etc.).

```bash
dochub build              # Build to ./dist
dochub build -o docs      # Build to ./docs
```

## Configuration

Edit `dochub.config.js` in your project root:

```js
module.exports = {
  title: 'My API Docs',
  description: 'Everything you need to build with our API',
};
```

The title appears in the browser tab, page header, and search metadata.

## Writing documentation

DocHub uses standard Markdown. All files go in `markdown/` and URLs are derived from the file path:

| File | URL |
|---|---|
| `markdown/README.md` | `/` |
| `markdown/guide.md` | `/guide` |
| `markdown/api/README.md` | `/api` |
| `markdown/api/authentication.md` | `/api/authentication` |

### Supported syntax

- Headers (h1–h6), bold, italic, strikethrough, inline code
- Fenced code blocks with syntax highlighting
- Ordered and unordered lists (nested too)
- Links, images, blockquotes, horizontal rules
- Tables with header alignment

## Deployment

The `build` command outputs a static `dist/` folder:

```
dist/
├── index.html
├── guide/
│   └── index.html
├── api/
│   └── index.html
├── folder/
│   └── index.html
└── 404.html
```

Deploy the entire `dist/` folder to any static file host:

<details>
<summary><b>Netlify</b></summary>

```bash
dochub build
# Drag dist/ onto Netlify Drop, or
npx netlify-cli deploy --dir=dist --prod
```
</details>

<details>
<summary><b>Vercel</b></summary>

```bash
dochub build
npx vercel dist --prod
```
</details>

<details>
<summary><b>GitHub Pages</b></summary>

```bash
dochub build
# Push dist/ contents to gh-pages branch, or
# use actions/upload-pages-artifact
```
</details>

<details>
<summary><b>Any static server</b></summary>

```bash
dochub build
npx serve dist
```
</details>

## Why DocHub?

There are many documentation tools. Here's where DocHub fits:

| | DocHub | Docusaurus | VitePress |
|---|---|---|---|
| Setup time | seconds | minutes | minutes |
| Language | Markdown | MDX + React | Markdown + Vue |
| Build output | ~20KB pages | ~200KB+ JS bundle | ~100KB+ JS bundle |
| Dependencies | 5 packages | 200+ packages | 100+ packages |
| Config | 5-line JS file | Full Docusaurus config | Full VitePress config |

DocHub is for teams that want to write Markdown and ship docs without learning a framework or managing hundreds of dependencies.

## License

MIT
