docs: Update bundling documentation with an example using Astro (#358)

This commit is contained in:
Skrubbadubba 2023-01-17 19:10:09 +01:00 committed by Daniel Lautzenheiser
parent 57083375b7
commit d4b88fb39e

View File

@ -12,13 +12,19 @@ To get started you need to install Static CMS via a package manager and save it
```bash
// npm
npm install @staticcms/core
npm install @staticcms/core@latest
// yarn
yarn add @staticcms/core
yarn add @staticcms/core@latest
```
Then import it (assuming your project has tooling for imports):
Then create a new route for your project (for instance at `/admin`), and import Static CMS:
```js
import CMS from '@staticcms/core';
```
The default export is a _CMS_ object, which has an `init` method that takes an object with a `config` attribute. The `config` attribute is an object representing the [configuration options](docs/configuration-options). You can use destructuring assigment syntax as shorthand:
```js
import CMS from '@staticcms/core';
@ -32,9 +38,24 @@ CMS.registerPreviewTemplate('my-template', MyTemplate);
**Note**: Wherever you initialize Static CMS (via `CMS.init()`), it takes over the current page. Make sure you only run the initialization code on your CMS page.
If the CMS object is initialized without being passed an object with a valid config attribute, it will try to fetch and read a `config.yml` file, via http, within the same path where the CMS resides (`/admin/config.yml`).
```js
import CMS from '@staticcms/core';
// Initialize the CMS object
CMS.init();
// Now the registry is available via the CMS object.
CMS.registerPreviewTemplate('my-template', MyTemplate);
```
**Note**: Because `config.yml` is requested via http, make sure `<siteurl>/admin/config.yml` exists as an endpoint on your build. If the file is not placed in the public folder, this might not be the default behaviour for your static site generator.
Make sure the file containing the CMS object will be built as a page, with `@staticcms/core` bundled, and the code including `CMS.init()` being run inside a script tag. This is what might take some time, as it will be done differently based on your static site generator. Check your static site generators's documentation for further details.
## Configuration
Configuration is different for every site, so we'll break it down into parts. Add all the code snippets in this section to your `admin/config.js` file (which is passed into the `CMS.init({ config })` call). Alternatively, you can use a yaml file (`admin/config.yml`) instead of a javascript file.
Configuration is different for every site, so we'll break it down into parts. Add all the code snippets in this section to your `admin/config.js` file (which is passed into the `CMS.init({ config })` call).
### Backend