Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
docs: Update bundling documentation with an example using Astro (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skrubbadubba authored Jan 17, 2023
1 parent 9801b61 commit 10f17d9
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions packages/docs/content/docs/add-to-your-site-bundling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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

Expand Down

0 comments on commit 10f17d9

Please sign in to comment.