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.
Craft static documentation sites from Markdown with minimal setup.
Docsmith is designed for package and project documentation where you want a fast build flow, a clean default UI, and zero frontend setup.
search-index.jsonsearch-index.json, sitemap.xml, and .nojekyll artifactscomposer require --dev mrpunyapal/docsmith
Create a build script (example: build-docs.php):
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Docsmith\Docsmith;
Docsmith::build(
source: __DIR__ . '/md',
title: 'My Package Docs',
description: 'Documentation generated by Docsmith.',
accentColor: '#ff2d20',
);
Run it:
php build-docs.php
This writes the generated site into docs by default.
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use Docsmith\Docsmith;
Docsmith::make()
->source(__DIR__ . '/md')
->output(__DIR__ . '/docs')
->title('My Package Docs')
->description('Documentation generated by Docsmith.')
->accentColor('#ff2d20')
->accentColorDark('#ff6b61')
->repositoryUrl('https://github.com/acme/package')
->siteUrl('https://acme.github.io/package')
->editBranch('main')
->rightSidebar()
->baseUrl('/')
->build();
You can change the accent color at build time. Docsmith derives the softer hover and focus colors from the accent, so hex colors give the best results.
If you need to apply ad-hoc overrides, you can append custom CSS during the build:
Docsmith::make()
->source(__DIR__ . '/md')
->output(__DIR__ . '/docs')
->customCss('body { background: #fff }') // raw CSS
->build();
Or pass a path to a CSS file which will be appended to assets/app.css:
Docsmith::make()
->source(__DIR__ . '/md')
->output(__DIR__ . '/docs')
->customCss(__DIR__ . '/my-overrides.css')
->build();
Docsmith ships two search experiences out of the box:
search-index.json and shows clickable results)The global search index is generated during each build and is static-hosting friendly.
Docsmith generates and links a default favicon for every built page. You can override it with a URL, data URI, or a path to a local image file:
Docsmith::make()
->source(__DIR__ . '/md')
->output(__DIR__ . '/docs')
->favicon('https://example.com/favicon.png')
->build();
Local favicons are copied into assets/ and linked with the correct relative path for each page.
Docsmith can emit og: and twitter: card tags and generate social preview images for you.
Generated images use Node with two packages: Playwright (browser) and capturist (capture runner). Install them once as devDependencies — you do not need to write or maintain a capturist config; Docsmith writes it during the docs build.
npm install -D playwright capturist@^0.1.3
npx playwright install chromium
Requires capturist ≥ 0.1.3 for incremental capture (skip unchanged cards). If Open Graph generation is enabled and these tools (or the Chromium browser) are missing, the docs build fails with the same install instructions.
In CI, install Node deps and Chromium before a docs build that runs capture (or use runCapturist(false) and capture in a later step).
Docsmith::make()
->source(__DIR__ . '/md')
->title('My Package Docs')
->ogGeneratedAll()
->build();
This renders one preview card, captures it to docs/og/cover.png, and points every page at it.
Docsmith::make()
->source(__DIR__ . '/md')
->title('My Package Docs')
->ogGeneratedPerPage()
->build();
Each page gets its own preview at og/<page>.png.
Pass a file path or raw HTML snippet. The tokens {site_title}, {title}, and {description} are replaced per page:
Docsmith::make()
->source(__DIR__ . '/md')
->ogTemplate(__DIR__ . '/og-card.html', scope: 'per-page')
->build();
The template is rendered inside a 1200×630 shell, so you only need the card markup.
Docsmith::make()
->source(__DIR__ . '/md')
->ogLink('https://example.com/og/cover.png')
->build();
The link can be an absolute URL or a root-relative path.
If you prefer, the structured ogImage(...) method exposes every option:
Docsmith::make()
->source(__DIR__ . '/md')
->ogImage(
type: 'generated',
scope: 'per-page',
template: __DIR__ . '/og-card.html',
scale: 2,
viewport: ['width' => 1200, 'height' => 630],
)
->build();
Individual pages can override the image, title, or description used in their OG tags:
---
og_image: /assets/page-og.png
og_title: Custom Social Title
og_description: A custom description for social shares.
---
# Page Title
By default, enabling a generated OG mode runs capture during build().
Capture is incremental via capturist’s built-in cache. Docsmith writes cache into capturist.config.json (manifest at og/.capturist-cache.json). Unchanged preview HTML skips Playwright; rebuilds print Open Graph images up to date.
Force a full regenerate by deleting og/*.png and/or og/.capturist-cache.json, or run capturist with --force.
Skip the capture step (e.g. CI that installs Playwright later):
Docsmith::make()
->ogGeneratedAll()
->captureOg(false)
->build();
Force a full recapture (ignore cache):
Docsmith::make()
->ogGeneratedAll()
->forceOg()
->build();
HTML card previews and capturist.config.json are still written under the output directory so a later capture step can use them.
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm install
- run: npx playwright install chromium --with-deps
- run: php build-docs.php
For repositories that maintain docs links in README sections, you can import that structure directly.
Docsmith::make()
->readmeIndex(__DIR__ . '/README.md')
->readmeSkipSections(['Contributing', 'Author', 'Notes'])
->title('Repository Docs')
->description('Generated from README index.')
->build();
Supported list styles include patterns used by:
Multiple versions of one documentation set. Pages get v1/v2/v3 pill buttons; no dropdown.
Docsmith::make()
->source(__DIR__ . '/md')
->output(__DIR__ . '/dist')
->versions([
['slug' => 'v1', 'label' => 'v1.0', 'default' => true],
['slug' => 'v2', 'label' => 'v2.0'],
])
->build();
Each version reads md/{slug}/; the default version mounts at the site root, siblings under /{slug}/. See Versioned Docs.
Several independent documentation sets in one site, one sidebar dropdown to switch between them.
Docsmith::make()
->output(__DIR__ . '/dist')
->hub([
'package-a' => ['label' => 'Package A', 'source' => __DIR__ . '/md/a'],
'package-b' => ['label' => 'Package B', 'source' => __DIR__ . '/md/b'],
])
->build();
Each entry gets one dropdown option mounted at /{slug}/; a hub entry may embed its own versions list for pills on its pages. See Docs Hub.
Pull Markdown from other Git repositories into your build — no git binary, no provider APIs, no clones. DocSmith speaks standard Git smart-HTTPS directly and works with any host.
// docsmith.sources.php
return [
[
'repository' => 'https://github.com/laravel/framework.git',
'ref' => '12.x',
'path' => 'docs',
'target' => 'laravel', // materialized to md/laravel
],
];
php bin/docsmith sync # fetch remote sources
php bin/docsmith build --sync # or fetch + build in one step
Plain builds never touch the network; without a docsmith.sources.php, nothing changes. Synced sources are plain local directories afterward — they work with a normal build, a versioned build, or a hub equally. See Remote Sources for caching, safety limits, and programmatic usage.
If there is no index.md in the source, Docsmith generates a landing page automatically.
Because the default output path is docs, a typical package workflow is:
composer test
composer docs:build
Contributions are welcome. Feel free to open issues and pull requests.
The MIT License (MIT). See LICENSE for details.
How can I help you explore Laravel packages today?