PHPackages                             savvywombat/caxton - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. savvywombat/caxton

ActiveLibrary[Templating &amp; Views](/categories/templating)

savvywombat/caxton
==================

A static site generator written in PHP using Blade templates and markdown

0.4.1(2y ago)231MITPHPPHP ^8.1

Since Aug 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/SavvyWombat/caxton)[ Packagist](https://packagist.org/packages/savvywombat/caxton)[ RSS](/packages/savvywombat-caxton/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

Caxton
======

[](#caxton)

A static site generator written in PHP using Blade templates and Markdown.

Getting started
---------------

[](#getting-started)

### Installation

[](#installation)

Caxton is available through Composer:

```
composer require savvywombat\caxton --dev
```

### Environment and configuration

[](#environment-and-configuration)

Caxton looks for a `.env` file in your project's root directory. The following variables are used (with defaults defined):

- `BASE_URL` () - the base URL for your site
- `CONTENT_DIR` (/content) - the folder where your Blade templates are stored
- `CACHE_DIR` (/cache) - the folder under the build directory where Blade caches are stored
- `OUTPUT_DIR` (/dev) - the folder under the build directory where the final HTML is saved to

You can create different environment configurations, for example `.env.prod`.

The default environment when building is `dev`.

Caxton will also look for additional configuration in `caxton.json` and `caxton.{environment}.json`. The various options are covered in the relevant sections below.

### Building with Caxton

[](#building-with-caxton)

To build a site, you need at least one Blade template in your content directory. Then you can run:

```
vendor/bin/caxton
```

To build for specific environment:

```
vendor/bin/caxton -e prod
```

The default environment is `dev`, so any configuration targeting the `dev` environment will be used.

Assets (styles, scripts and images)
-----------------------------------

[](#assets-styles-scripts-and-images)

Common assets should be placed in your public directory. These will be copied to the build directory before your templates are built into HTML.

You can also put assets in your content directory alongside your templates to keep related assets and templates together.

Directory structure
-------------------

[](#directory-structure)

Caxton expects the following structure, but can be overridden with environment variables:

```
/project/dir/content
/project/dir/public

```

The content and public paths are configurable as ENV variables in `.env` files.

The public directory should contain common files like images and stylesheets.

The content directory is where you put your templates that Caxton will use to create your HTML. You can include assets (images, stylesheets, scripts, and so on) alongside your templates. These assets will then be included in the same output directory as the generated HTML.

Authoring
---------

[](#authoring)

### Blade PHP Templates

[](#blade-php-templates)

Caxton uses Laravel's Blade template system. Any files in the `content` directory that end with `.blade.php` will be converted into an HTML document with the same name.

### Markdown

[](#markdown)

Caxton also allows the use of Markdown within a Blade template. Files in the `content` directory that end with `.blade.md` will be passed through a Markdown parser before being saved as an HTML document.

Caxton supports the default CommonMark syntax using the [PHP League's](https://commonmark.thephpleague.com/) package, with one exception. The indentation syntax to format code blocks has been disabled, meaning code blocks must be wrapped in ``` delimiters.

### Front Matter

[](#front-matter)

Caxton supports front matter YAML at the start of any template file (PHP or Markdown). The values in the front matter are injected as view data, becoming available as PHP variables within the template.

### Example

[](#example)

#### index.blade.php

[](#indexbladephp)

```
---
title: Example document
---

@extends('_layouts.html')

@section('content')
  Hello World
@endsection
```

#### about.blade.md

[](#aboutblademd)

```
---
title: About Markdown
---

@extends('_layouts.html')

@section('content')

This is Markdown.

@endsection
```

#### \_layouts/html.blade.php

[](#_layoutshtmlbladephp)

```

    {{ $title }}

    @yield('section')

```

### Indexes (file collections)

[](#indexes-file-collections)

Generated files can be collected into an index by specification in the template's front matter:

```
---
index: blog
date: 2023-08-26
title: Some blog post
description: This is really interesting
---
```

This allows you to refer to a [Laravel Collection](https://laravel.com/docs/10.x/collections) for generating lists:

```

    @foreach ($site->index('blog')->slice(0, 3) as $post)

            {{ $post->data('title') }}

            {{ $post->data('date') }}

                {{ $post->data('description') }}

    @endforeach

```

#### Sorting

[](#sorting)

While you can use the Collection's sortBy method, this can be a bit verbose with Caxton pages:

```
@foreach ($site->index('blog')->sortByDesc(fn($post) => $post->data('date')) as $post)
```

You can define a default sort order in your `caxton.json` file:

```
{
  "output": {
    "index": {
      "blog": ["date", "desc"],
      "another": "title"
    }
  }
}
```

```
@foreach ($site->index('blog') as $page)
```

#### Paged indexes

[](#paged-indexes)

Coming soon.

Building
--------

[](#building)

```
vendor/bin/caxton
```

The default output directory is `/project/dir/public/dev`, but can be overridden via the environment switch:

```
vendor/bin/caxton -e prod
```

Caxton will first copy the contents of the `public` directory to the build output directory. It will then copy any asset files from the `content` directory, as well as build the HTML files from the templates there.

Files and directories that begin with a `.` or `_` will not be ignored.

### Include/exclude list

[](#includeexclude-list)

You can specify files for inclusion or exclusion in the `caxton.json` configuration file. File paths are relative to the working directory.

```
{
  "files": {
    "include": [
      "public/_redirects"
    ],
    "exclude": [
      "content/never-include-this-file"
    ],
  }
}
```

### Output mapping

[](#output-mapping)

By default, the output URLs will follow the same structure as the folder paths within your public and content directories.

If you like to organise your files differently, then you can use the `output.maps` configuration to map the URLs accordingly.

For example:

```
+ content
|-+ blog
  |-+ 2018
    |-+ 10-22-it-begins
      |-- index.blade.md
      |-- pretty-picture.png

```

To output this document as `/blog/2018-10-22/it-begins`, you can use this in your `caxton.json` file:

```
{
  "output": {
    "maps": [
      {
        "path": "/blog/*/*/",
        "url": "/blog/{{ date }}/{{ slug }}/"
      }
    ]
  }
}
```

`date` and `slug` are read from the front matter of the template file.

```
---
date: 2018-10-22
slug: it-begins
---
```

Caxton will then store an internal map for all output for paths starting with `/blog/2018/10-22-it-begins/` and rewrite them as `/blog/2018-10-22/it-begins`. This means that any resources related to the blog post (such as the `png` file) will be written to the same output URL.

### Sitemap

[](#sitemap)

Caxton will generate a `sitemap.xml` and add it to the root of your output directory. Only HTML files will be included, and the last modified time will be calculated based on the source/template file.

Publishing
----------

[](#publishing)

Caxton simply builds a directory of content that can be published. How you publish your content is up to you.

Why is this package called Caxton?
----------------------------------

[](#why-is-this-package-called-caxton)

William Caxton is thought to be the person who introduced the printing press to England, and so ushered in a great advance in the production of books and dispersal of knowledge.

Acknowledgements
----------------

[](#acknowledgements)

This package uses Laravel's Blade template engine, without requiring the full Laravel framework.

Matt Stauffer has a [GitHub repository](https://github.com/mattstauffer/Torch) which has various examples of how to use parts of the framework as standalone components. Specifically, the [view component](https://github.com/mattstauffer/Torch/tree/master/components/view) enables the use of Blade.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

5

Last Release

1007d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/949f4b63b47c6f037d6ddd22ad3c34e67950655eb51a31d2b1f1205eac7005d7?d=identicon)[SavvyWombat](/maintainers/SavvyWombat)

---

Top Contributors

[![horuskol](https://avatars.githubusercontent.com/u/290549?v=4)](https://github.com/horuskol "horuskol (33 commits)")

---

Tags

phpblademarkdowntemplatestatic-site-generatorstatic site builder

### Embed Badge

![Health badge](/badges/savvywombat-caxton/health.svg)

```
[![Health](https://phpackages.com/badges/savvywombat-caxton/health.svg)](https://phpackages.com/packages/savvywombat-caxton)
```

###  Alternatives

[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[eftec/bladeone

The standalone version Blade Template Engine from Laravel in a single php file

8208.4M87](/packages/eftec-bladeone)[eftec/bladeonehtml

The standalone version Blade Template Engine from Laravel in a single php file

1018.1k5](/packages/eftec-bladeonehtml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
