Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Documentarian Laravel Package

mpociot/documentarian

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require mpociot/documentarian
    

    Publish the configuration and assets:

    php artisan vendor:publish --provider="Mpociot\Documentarian\DocumentarianServiceProvider"
    
  2. Configuration: Update config/documentarian.php to define your API documentation paths:

    'paths' => [
        'documentation' => resource_path('docs'),
        'assets' => public_path('docs/assets'),
    ],
    
  3. First Use Case: Create a README.md in resource_path('docs') with basic API structure:

    # API Documentation
    
    ## Introduction
    Welcome to our API!
    
    ## Endpoints
    ### GET /users
    ```json
    {
        "users": [...]
    }
    
    Run `php artisan documentarian:serve` to preview locally at `http://localhost:8000/docs`.
    
    

Implementation Patterns

Workflow Integration

  1. Markdown-Based Documentation:

    • Store API specs in Markdown files (e.g., resource_path('docs/endpoints/users.md')).
    • Use YAML frontmatter for metadata (e.g., endpoint paths, HTTP methods):
      ---
      endpoint: /users
      method: GET
      ---
      # Users Endpoint
      Fetch all users.
      
  2. Laravel Route Integration: Add a route in routes/web.php:

    Route::get('/docs', function () {
        return Documentarian::render();
    });
    
  3. Asset Management:

    • Place static assets (CSS, JS, images) in public_path('docs/assets').
    • Override default assets by publishing the package’s assets:
      php artisan vendor:publish --tag=documentarian-assets
      
  4. Custom Templates: Extend the default theme by copying vendor/mpociot/documentarian/resources/views to resources/views/vendor/documentarian and modifying as needed.


Daily Usage Patterns

  • Edit and Preview:

    php artisan documentarian:serve
    

    Auto-reloads changes during development.

  • Generate Static Files:

    php artisan documentarian:build
    

    Compiles assets and generates static HTML for production.

  • Versioning: Use subdirectories (e.g., resource_path('docs/v1')) for API versioning and include version-specific routes.


Gotchas and Tips

Pitfalls

  1. Asset Paths:

    • Ensure public_path('docs/assets') is writable. Permissions issues may break asset compilation.
    • Clear cached views if assets fail to load:
      php artisan view:clear
      
  2. Markdown Parsing:

  3. Laravel Caching:

    • Disable caching during development if changes aren’t reflecting:
      // config/documentarian.php
      'cache' => env('APP_ENV') !== 'local',
      
  4. Route Conflicts:

    • Ensure /docs doesn’t conflict with existing routes. Use middleware to restrict access:
      Route::get('/docs', function () {
          return Documentarian::render();
      })->middleware('auth');
      

Debugging Tips

  1. Check Logs: Run with verbose output:

    php artisan documentarian:serve --verbose
    
  2. Validate Markdown: Use a Markdown linter (e.g., Markdown Lint) to catch syntax errors.

  3. Frontmatter Validation: Test YAML frontmatter with:

    composer require --dev symfony/yaml
    

    Then validate in PHP:

    use Symfony\Component\Yaml\Yaml;
    $yaml = Yaml::parse(file_get_contents('path/to/file.md'));
    

Extension Points

  1. Custom Renderers: Extend Mpociot\Documentarian\Renderers\RendererInterface to support additional formats (e.g., JSON schemas).

  2. Hooks: Override the DocumentarianServiceProvider to add middleware or filters:

    public function boot()
    {
        Documentarian::extend(function ($renderer) {
            // Modify renderer behavior
        });
    }
    
  3. API Blueprints: Integrate with tools like API Blueprint by converting blueprints to Markdown before processing.


Pro Tips

  • CI/CD Integration: Automate builds in GitHub Actions:
    - name: Build Documentation
      run: php artisan documentarian:build
    
  • Search Functionality: Use Lunr.js for client-side search by including it in resources/views/vendor/documentarian/layouts/master.blade.php.
  • Dark Mode: Add a CSS toggle for dark/light themes by extending the default stylesheet.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
thomas-0816/doctrine-dbal-duckdb
moyisoft/laravel-admin
oxygen/mod-pages
oxygen/mod-import-export
oxygen/mod-media
ksoft/laravel-contentbuilderjs
ourgoldpackages/exchange
mikkimike/laravel-exchange1c
wandesnet/mercadopago-laravel
tsfcorp/email
larafony/core
laravel-enso/currencies
tartan/laravel-online-payment
wedevbr/celcoin-laravel
surazdott/nepali-date
devsquad-cockpit/laravel
coding-socks/laravel-upload-handler
artisanbarista/laravel-shield
instance-code/repository
flooris/prestashop-models