From d4b88fb39e9b41498458587b7ffb6bf3009667ff Mon Sep 17 00:00:00 2001 From: Skrubbadubba <75796723+Skrubbadubba@users.noreply.github.com> Date: Tue, 17 Jan 2023 19:10:09 +0100 Subject: [PATCH] docs: Update bundling documentation with an example using Astro (#358) --- .../docs/add-to-your-site-bundling.mdx | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/docs/content/docs/add-to-your-site-bundling.mdx b/packages/docs/content/docs/add-to-your-site-bundling.mdx index e0bb262b..0e41a8f3 100644 --- a/packages/docs/content/docs/add-to-your-site-bundling.mdx +++ b/packages/docs/content/docs/add-to-your-site-bundling.mdx @@ -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 `/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