mrpunyapal/docsmith
Docsmith builds static documentation sites from Markdown with zero frontend setup. It offers searchable sidebar navigation, syntax-highlighted code with copy buttons, an optional table of contents, and generated search index, sitemap, and .nojekyll files for GitHub Pages.
Installation:
composer require mrpunyapal/docsmith
Publish the package assets (if needed):
php artisan vendor:publish --provider="MrPunyapal\DocSmith\DocSmithServiceProvider" --tag="public"
Basic Configuration:
Edit config/docsmith.php to define your documentation source directory (default: resources/docs):
'source' => resource_path('docs'),
'output' => public_path('docs'),
'theme' => 'default', // or a custom theme path
First Use Case:
Create a Markdown file (resources/docs/getting-started.md) with frontmatter:
---
title: Getting Started
order: 1
---
# Welcome to DocSmith!
Write your documentation here in Markdown.
Generate the site:
php artisan docsmith:generate
Access the output at /docs/getting-started.html.
Local Development:
php artisan docsmith:watch to auto-generate on file changes.// vite.config.js
import { defineConfig } from 'vite';
import { docsmithPlugin } from 'mrpunyapal/docsmith/vite';
export default defineConfig({
plugins: [docsmithPlugin()],
});
CI/CD Pipeline:
# .github/workflows/deploy.yml
- run: composer require mrpunyapal/docsmith
- run: php artisan docsmith:generate --force
Multi-Language Docs:
---
lang: es
---
generate command with a --lang flag (customize via service provider).Laravel Blade Integration: Embed docs in Blade templates:
@docsmith('getting-started', ['theme' => 'custom-theme'])
Requires registering the Blade directive in AppServiceProvider.
API Documentation:
Combine with spatie/laravel-api-docs for OpenAPI specs:
// config/docsmith.php
'api_docs' => [
'spec' => 'api/openapi.yaml',
'output' => 'api-docs',
],
Versioning: Use symbolic links or Git tags to manage versions:
# Generate for v1.0
php artisan docsmith:generate --version=v1.0
Frontmatter Parsing:
Theme Conflicts:
base.html and styles.css in their directory.partials/nav.html) by placing them in your theme folder.Asset Pipeline:
docsmith:generate runs after assets are compiled:
// mix.js
mix.js('resources/js/app.js', 'public/js')
.then(() => run('docsmith:generate'));
Caching:
php artisan cache:clear
php artisan view:clear
php artisan docsmith:generate --verbose
php artisan docsmith:generate --dry-run
Lists files that would be processed without writing.Custom Processors:
Extend DocSmith\Processors\ProcessorInterface to handle custom Markdown:
// app/Processors/CustomProcessor.php
namespace App\Processors;
use DocSmith\Processors\ProcessorInterface;
class CustomProcessor implements ProcessorInterface {
public function process(string $content): string {
return str_replace('{{CUSTOM}}', 'Replaced!', $content);
}
}
Register in config/docsmith.php:
'processors' => [
\App\Processors\CustomProcessor::class,
],
Event Listeners:
Listen for docsmith.generated events to post-process output:
// app/Listeners/PostProcessDocs.php
namespace App\Listeners;
use DocSmith\Events\DocsGenerated;
class PostProcessDocs {
public function handle(DocsGenerated $event) {
// Example: Minify generated HTML
foreach ($event->files as $file) {
file_put_contents($file, $this->minify($file));
}
}
}
Register in EventServiceProvider.
CLI Customization:
Override commands in AppServiceProvider:
public function boot() {
$this->app->singleton(\DocSmith\Console\GenerateCommand::class, function () {
return new \App\Console\CustomGenerateCommand();
});
}
How can I help you explore Laravel packages today?