Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions documentation/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ mkpy serve
mkpy serve --folder docs --theme dark --port 3000
```

### mkpy build

Генерирует статический сайт из markdown файлов.

```bash
mkpy build
```

С параметрами:

```bash
mkpy build --folder docs --output site --theme dark
```

### mkpy version

Показывает версию mkpy.
Expand All @@ -43,8 +57,34 @@ mkpy version
| `--port` | `-p` | Порт сервера | 8000 |
| `--no-nav` | | Отключить навигацию | false |

## Опции build

| Опция | Кратко | Описание | По умолчанию |
|-------|--------|----------|--------------|
| `--folder` | `-f` | Папка с markdown файлами | docs |
| `--output` | `-o` | Выходная папка для HTML | project |
| `--title` | `-t` | Заголовок документации | MKPY |
| `--theme` | | Тема: light или dark | light |
| `--no-nav` | | Отключить навигацию | false |

## Примеры

### Генерация статического сайта

```bash
# Базовое использование - создаст папку project с HTML файлами
mkpy build

# С указанием папки и вывода
mkpy build --folder docs --output mysite

# С темной темой
mkpy build --theme dark

# Всё вместе
mkpy build --folder docs --output site --theme dark --title "My Docs"
```

### Запуск с параметрами

```bash
Expand Down
93 changes: 93 additions & 0 deletions mkpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,99 @@ def serve(
docs.run()


@app.command()
def build(
folder: Annotated[
str,
typer.Option("--folder", "-f", help="Path to folder containing markdown files"),
] = "docs",
output: Annotated[
str,
typer.Option("--output", "-o", help="Output directory for static files"),
] = "project",
title: Annotated[
str,
typer.Option("--title", "-t", help="Documentation title"),
] = "MKPY",
theme: Annotated[
str,
typer.Option("--theme", help="Theme: light or dark"),
] = "light",
no_nav: Annotated[
bool,
typer.Option("--no-nav", help="Disable navigation menu"),
] = False,
) -> None:
from rich.console import Console
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn
from rich.table import Table
from rich.panel import Panel
from rich import box

console = Console()

os.makedirs(output, exist_ok=True)
docs = Docs(
folder=folder,
title=title,
theme=theme,
show_nav=not no_nav,
)

routes = list(docs.routes.items())
total = len(routes)

console.print(Panel.fit(
f"[bold cyan]MKPY Build[/bold cyan]\n"
f"Converting [yellow]{total}[/yellow] markdown files to HTML",
border_style="cyan",
))

table = Table(box=box.ROUNDED, show_header=True, header_style="bold magenta")
table.add_column("Status", style="green", width=8)
table.add_column("Source", style="cyan")
table.add_column("Output", style="yellow")

with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TaskProgressColumn(),
console=console,
) as progress:
task = progress.add_task("[cyan]Building...", total=total)

for route, md_path in routes:
html_content = docs.render(md_path)

if route == "/":
html_filename = "index.html"
else:
html_filename = f"{route.lstrip('/')}.html"

output_path = os.path.join(output, html_filename)

os.makedirs(os.path.dirname(output_path), exist_ok=True)

with open(output_path, "w", encoding="utf-8") as f:
f.write(html_content)
relative_md = os.path.relpath(md_path, folder)
table.add_row("✓", relative_md, html_filename)

progress.advance(task)

console.print()
console.print(table)

console.print()
console.print(Panel.fit(
f"[bold green]✓ Build complete![/bold green]\n"
f"Output directory: [yellow]{os.path.abspath(output)}[/yellow]\n"
f"Files created: [cyan]{total}[/cyan]",
border_style="green",
))


@app.command()
def version() -> None:
from . import __version__
Expand Down