Storage

Setup different storages for your CMS

The function cms.storage() allows to register different storages to save the site data. When a storage is registered, it must have a name that will be used later in your documents, collections and uploads.

LumeCMS supports the following storages:

File system

Note: Lume automatically configure the src storage pointing to the src folder. So you don't need to setup a file system storage.

To register a filesystem storage, import the class and register it with a name. For example, let's register a file system storage under the name "my_files", pointing to the ./files folder:

import lumeCMS, { Fs } from "lume/cms.ts";

const cms = lumeCMS();
const root = Deno.cwd() + "/files";

cms.storage("my_files", new Fs({ root }));

export default cms;

The my_files storage is now available to read and write content by the CMS. Because the file system is the most common way to read and write data, the example above can be simplified as following:

import lumeCMS from "lume/cms.ts";

const cms = lumeCMS();

cms.storage("my_files", "files");

export default cms;

As you can see, if you define a string as the storage, LumeCMS assume it's a folder name, so the file system storage is used automatically. Note also that you don't need to prepend Deno.cwd() to the folder name, because the value of root option (which by default is Deno.cwd()) is used as the base path.

KV

Deno Kv is a key-value database built directly into the Deno runtime. LumeCMS can use a Kv instance to store content. For example:

import lumeCMS, { Kv } from "lume/cms.ts";

const cms = lumeCMS();
const kv = await Deno.openKv();

cms.storage("my_values", new Kv({ kv }));

export default cms;

GitHub

Allows to write and read values directly from a GitHub repository using the GitHub API. It's useful if you want to allow people without GitHub accounts or permission to edit the site data.

import lumeCMS, { GitHub } from "lume/cms.ts";
import { Octokit } from "npm:octokit";

const cms = lumeCMS();

const client = new Octokit({
  auth: "xxx", // A personal access token,
});

cms.storage(
  "gh",
  new GitHub({
    client,
    owner: "username",
    repo: "example",
  }),
);

export default cms;