From d7ee5702d384d7bb94c1a0c6de285e9ab2e2ec97 Mon Sep 17 00:00:00 2001 From: NEFORCEO Date: Sat, 28 Feb 2026 12:47:25 +0700 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9E=96=20Added=20cli=20commands=20`build?= =?UTF-8?q?`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mkpy/cli.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/mkpy/cli.py b/mkpy/cli.py index 35324ed..837059c 100644 --- a/mkpy/cli.py +++ b/mkpy/cli.py @@ -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__ From c5fb7f0e011ece167b4ce11fb991e7ffed2b41e9 Mon Sep 17 00:00:00 2001 From: NEFORCEO Date: Sat, 28 Feb 2026 12:47:47 +0700 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9E=96=20Edit=20documentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- documentation/cli.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/documentation/cli.md b/documentation/cli.md index f06579f..227e279 100644 --- a/documentation/cli.md +++ b/documentation/cli.md @@ -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. @@ -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