A Kirby 3 plugin to synchronize your content from a source (usually the server) to your local development environment.
This plugin requires Kirby 3, Kirby 3 CLI and PHP 8 or higher to work.
The recommended way of installing is by using Composer.
composer require zephir/kirby-contentsync
Download and copy this repository to /site/plugins/kirby-contentsync
.
git submodule add https://github.com/zephir/kirby-contentsync.git site/plugins/kirby-contentsync
After installation, you need to add the plugin options to your config.
Option | Type | Default | Required | Description |
---|---|---|---|---|
source | string | null | ✅ | Source of the content, normally the staging / prod server. URL of the host (e.g. https://getkirby.com) |
token | string | null | ✅ | The authentication token, make sure this token is not accessible by the public. Either use an env file/variable or use a private git repository. |
enabledRoots | array | see below | ❌ | The authentication token, make sure this token is not accessible by the public. Either use an env file/variable or use a private git repository. |
The plugin supports synchronizing the accounts' and
content' folders. To support different types of folder structures we use the kirby()->roots()
function (hence the name of the option). You can enable/disable either the accounts
or content
roots.
Default:
[
'accounts' => true,
'content' => true
]
'zephir.contentsync' => [
'source' => 'https://getkirby.com',
'token' => 'abc123',
'enabledRoots' => [ // Default, not required
'accounts' => true,
'content' => true
]
]
After installing, setting up options, and deploying the changes to the server, you can simply run the kirby command:
kirby content:sync
The plugin creates 2 endpoints (routes):
/contentsync/files
: Returns a list of all files in the enabled roots./contentsync/file/:fileId
: Returns the contents of the requested file.
If you don't set-up a token the endpoints won't work.
Each file returned by files
has an ID (sha1 hash of root name + path), a path (relative to kirby root), kirby root name and a checksum of the file contents.
The plugin compares the retrieved file list with a file list of local files. It automatically deletes local files that aren't in the server list, creates the ones that aren't local but in the server list, and updates the ones with different checksums.
It doesn't sync files that haven't changed.
- Since we download each file individually, it is possible that a WAF / Firewall will block the requests. You can add an exception for the endpoints.
- Generating the checksum can put a bit of load on the server, especially for large files. But for "normal" websites it should be fine - even if you have several gigabytes of data / many files.
MIT