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

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

Merged
merged 5 commits into from
Jan 17, 2023

Conversation

Skrubbadubba
Copy link
Contributor

@Skrubbadubba Skrubbadubba commented Jan 15, 2023

This is my attempt at clarifying the bundling docs. I tried to look at the code, but I didnt understand that much. My understanding of how things work (specifically with regards to loading the config), is mostly from trial and error. This means I might have just written a bunch of garbage, but I tried.

Although since I got bundling to work with Astro, I can say for sure that the provided example is valid.

This is my best attempt at providing more detailed instructions. I'm not entirely onboard with how the config is loaded using: `import config from './config'` and `CMS.init({config})`, which is why my description might not be accurate regarding how it actually works, but I documented my own understanding as best as possible.

I will be writing an example using Astro in another commit
@netlify
Copy link

netlify bot commented Jan 15, 2023

Deploy Preview for demo-staticjscms ready!

Name Link
🔨 Latest commit de324a6
🔍 Latest deploy log https://app.netlify.com/sites/demo-staticjscms/deploys/63c6dfe056eff90009c81b0d
😎 Deploy Preview https://deploy-preview-358--demo-staticjscms.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 15, 2023

Deploy Preview for staticjscms ready!

Name Link
🔨 Latest commit de324a6
🔍 Latest deploy log https://app.netlify.com/sites/staticjscms/deploys/63c6dfe091d5270008a1b5ea
😎 Deploy Preview https://deploy-preview-358--staticjscms.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@Skrubbadubba Skrubbadubba changed the title Update bundling documentation with an example using Astro docs: Update bundling documentation with an example using Astro Jan 15, 2023
@@ -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` or `config.js` file, via http, within the same path where the CMS resides (`/admin/config.<js/yml>`).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is right. This is how it looked to work to me after some trial and error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only tries to load config.yml.

@@ -12,17 +12,23 @@ 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@next
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will obviously be changed after 1.0.0 release, but I thought this should be added, as the docs should ideally only show working code.

CMS.registerPreviewTemplate('my-template', MyTemplate);
```

**Note**: Because `config.<js/yml>` is requested via http, make sure `<siteurl>/admin/config.<js/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 framework.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"framework" or "static site generator". Wasn't sure what was most appropriate

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static site generator

@@ -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` or `config.js` file, via http, within the same path where the CMS resides (`/admin/config.<js/yml>`).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only tries to load config.yml.


```js
import CMS from '@staticcms/core';
import config from './config.js';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Under most build systems the .js on the end is unnecessary.

Suggested change
import config from './config.js';
import config from './config';

CMS.registerPreviewTemplate('my-template', MyTemplate);
```

**Note**: Because `config.<js/yml>` is requested via http, make sure `<siteurl>/admin/config.<js/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 framework.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 framework. Check your framework's documentation for further details.

### Example using [Astro](https://astro.build)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now I would like to avoid having any framework/platform specific details in the guide. Having that in here makes this into a maintenance issue, due to having to keep up with the platform in question to ensure our docs are accurate. I do not have the time, nor is our community big enough yet, to support that.

@KaneFreeman KaneFreeman merged commit 10f17d9 into StaticJsCMS:main Jan 17, 2023
@Skrubbadubba Skrubbadubba deleted the 22-main branch January 18, 2023 15:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants