Your site changes when you push to its repository. If you, or the person who looks after the words on it, would rather edit pages in a browser, add Sveltia CMS. It is free and open source, and it lives on your site at /admin/.
Sveltia keeps no copy of your content anywhere else. Each time you save, it commits the change to your repository, our webhook sees the push, and your site rebuilds. Nothing on our side needs switching on.
You need a site that deploys from GitHub or GitLab with the webhook set up (see Deploy from GitHub or Deploy from GitLab).
Add two files
Sveltia is two files in a folder called admin, inside the folder your generator copies to the site unchanged. For Hugo that is static/admin/, for Astro public/admin/, and for Jekyll admin/ at the top of the repository.
index.html loads the editor:
<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex">
<title>Content Manager</title>
</head>
<body>
<script src="https://unpkg.com/@sveltia/cms/dist/sveltia-cms.js"></script>
</body>
</html>
That address always loads Sveltia’s newest release, and it is the one Sveltia’s own instructions use. On our own sites we put a version number in it (@sveltia/cms@0.208.1), because a new release now and then changes how something works, and we would rather choose the day. If you do the same, check Sveltia’s release notes before you raise the number.
config.yml tells Sveltia where your repository is and which files it may edit. This one is for a Hugo blog on GitLab:
backend:
name: gitlab
repo: your-group/your-site
branch: main
auth_type: pkce
app_id: YOUR_APPLICATION_ID
media_folder: static/images
public_folder: /images
collections:
- name: posts
label: Posts
label_singular: Post
folder: content/posts
create: true
fields:
- { label: Title, name: title, widget: string }
- { label: Date, name: date, widget: datetime }
- { label: Body, name: body, widget: richtext }
On GitHub, change name to github and leave out auth_type and app_id. Add a collection for each folder of pages you want to edit. Sveltia’s collections guide lists every kind of field.
Push both files. Once the site has rebuilt, open https://your-domain/admin/.
Signing in
Everyone who edits needs an account that can push to the branch in config.yml. If that branch is protected, check that their role is allowed to push to it, or every save will fail.
GitLab
Sign-in works with no server of your own. In GitLab, go to User settings > Applications and add an application:
- Redirect URI: your admin page,
https://your-domain/admin/ - Untick Confidential
- Scope: api
Copy the Application ID into app_id in config.yml. It is not a secret: the browser needs it, so it belongs in the file. Leave the secret GitLab shows you where it is; Sveltia never uses it. Editors then press Sign In with GitLab.
GitHub
The quickest way in is a token. In GitHub, create a fine-grained personal access token for the site’s repository with Contents: Read and write, then press Sign In with Token on the admin page and paste it. A Sign In with GitHub button needs a small sign-in service, because GitHub does not offer the method GitLab does. Sveltia’s GitHub guide covers the options.
On your own computer
If you have the site checked out, run it locally, open /admin/ and choose Work with Local Repository. Saves go straight into your files, and you commit and push them yourself. This needs Chrome, Edge or another Chromium browser.
Images
Images you upload go into media_folder and are committed with the page. Upload what you have: when we publish the site, any image wider or taller than 2560 pixels, or larger than 4 MB, is scaled down in place, with the same name and format.
Our content tools
If your site runs on Hugo, add our content tools to the editor. They start with a Table option: paste cells from Word or Excel and the table comes out with a caption and headings a screen reader can follow.