Skip to content
Vellum

Core on its own

Use Vellum's content engine without its routes and layout.

Vellum is three Composer packages, released together under one version:

  • jimmyverburgt/vellum is the docs site: routes, layout, theme, search dialog, the API playground, and the vellum:install and vellum:export commands.
  • jimmyverburgt/vellum-core is the engine under it. It reads the docs folder and handles frontmatter, navigation, versions, gating, Markdown, the compiled cache, search and the changelog.
  • jimmyverburgt/vellum-openapi is the API reference: pages written from an OpenAPI spec, which core stores beside the docs' own.

Installing jimmyverburgt/vellum includes the other two, and that is what most apps want. Require core on its own when you render the docs yourself, for example in an Inertia or Livewire front end, or when a package of yours reads the docs:

Terminal
composer require jimmyverburgt/vellum-core

For the API reference too, require it beside core. It works without the site, and the playground, which sends requests from the page, is the site's:

Terminal
composer require jimmyverburgt/vellum-openapi

What core provides

  • config/vellum.php, published with php artisan vendor:publish --tag=vellum-config. Core reads path, versions, route, components, search, checks, changelog and cache, the last for where compiled pages go. route.prefix is the start of every link core builds. The other keys, such as layout, theme and export, belong to the site and do nothing without it. The openapi block does nothing without jimmyverburgt/vellum-openapi, and vellum:build says so when it is switched on without that package.
  • vellum:build, vellum:index and vellum:clear, which work as described in Commands.
  • No routes, controllers, layout, styles or scripts.

Pages

ContentRepository is the entry point. It finds pages by slug, compiles them when they changed, and checks them against the reader's access. Resolve it from the container, or type-hint it in a controller method:

php
use Vellum\Content\ContentRepository;

$docs = app(ContentRepository::class);
$page = $docs->find('getting-started/installation');

if ($page === null || ! $docs->allows($page)) {
    abort(404);
}

$page->title;               // frontmatter, the first heading, or the file name
$page->description;
$page->headings;            // for a table of contents
$docs->render($page);       // the page's HTML, components included
$docs->navigation();        // the sidebar tree this reader may see
$docs->adjacent($page->slug); // previous and next pages, each with its section when that differs

The container builds one repository per request and shares it, so the sidebar it loads for one call serves the next. ContentRepository::fromConfig() still works, and builds a new repository from the config as it is at that moment.

Everything core reads from config/vellum.php arrives through a Vellum\Site, built from config by core's service provider. To build a repository for docs that config does not describe, pass it a site of its own:

php
use Vellum\Content\ContentRepository;
use Vellum\Site;

$handbook = new ContentRepository(Site::fromArray([
    'path' => resource_path('handbook'),
    'route' => ['prefix' => 'handbook'],
    'cache' => ['path' => storage_path('framework/handbook')],
]));

Site::fromArray() takes the same keys as config/vellum.php, with the same defaults for any you leave out.

Use render() rather than $page->html. The stored HTML holds a placeholder for each Blade component in the page, and render() puts the rendered components in their place.

Markup

The HTML uses vellum-* classes and data-vellum-* attributes and carries no styles. Style it with your own CSS, or start from the site's resources/css/vellum.css.

A few parts need a script to work:

  • Code blocks have a copy button marked data-vellum-copy-code, inside the block's data-vellum-code element. Its data-vellum-code-kind is file, terminal or snippet, and in a terminal each command line has the class vellum-code-command, for a prompt drawn with CSS.
  • Headings have a copy-link button marked data-vellum-heading-copy.
  • Table cells carry their column's heading in data-label, for laying rows out as blocks on a narrow screen, and an image alone in its paragraph is marked data-vellum-image-block.
  • Tabs follow the WAI-ARIA tabs pattern, with the first panel open and the others hidden.

To change the markup of a component, see Change a built-in's markup.

vellum:build writes a search index for each version. To query it for the current reader:

php
use Vellum\Answers\AnswersQuery;
use Vellum\Answers\Ranker;

$query = new AnswersQuery;
$index = $query->index($docs, version: null);
$visible = $index->forAccess($query->allowed($index));

$results = (new Ranker($visible))->search('deploy', 10);

Each result's record has the page, heading, URL and a passage of text. This is the same ranking the site's search endpoint uses. See Search.

Generated pages

Pages nobody wrote as Markdown, such as the API reference built from a spec, come from a page source. A source implements Vellum\Content\PageSource: it names itself, returns its pages as Documents with slugs only it writes, says which slugs are its own, gives a signature that changes when its pages must be rebuilt, and returns its pages as one sidebar folder. The repository stores those pages beside the written ones, so search, links, access and the build treat them the same way.

To add one, register a Vellum\Content\PageSourceFactory in the container with the vellum.page-sources tag. The factory is given each site and returns that site's source, or null when the site has none:

php
use Vellum\Content\PageSource;
use Vellum\Content\PageSourceFactory;
use Vellum\Site;

final class ChangelogArchive implements PageSourceFactory
{
    public function forSite(Site $site): ?PageSource
    {
        return new ArchivePages($site);
    }
}

// In a service provider's register():
$this->app->tag([ChangelogArchive::class], 'vellum.page-sources');

A source's pages belong to the latest version. A source whose separate() returns true gets a sidebar of its own, with a switch to it at the top of the docs' sidebar.