|
| 1 | +## How does it work? |
| 2 | + |
| 3 | +It uses Astro Content Collections just like we use `settings.yml`, `content.yml` and `faqs.yml`. |
| 4 | + |
| 5 | +This means every collection is treated as an entrypoint in the CMS. |
| 6 | + |
| 7 | +The necessary config to integrate this is done at `astro.config.mjs`. |
| 8 | + |
| 9 | +## How does config work? |
| 10 | + |
| 11 | +Inside `astro.config.mjs` at `export default defineConfig({ integrations: [...] )}` we need to set: |
| 12 | + |
| 13 | +``` |
| 14 | +NetlifyCMS({ |
| 15 | + config: { |
| 16 | + backend: { |
| 17 | + name: 'git-gateway', |
| 18 | + branch: 'master', |
| 19 | + }, |
| 20 | + collections: [ |
| 21 | + { |
| 22 | + name: 'Cities', |
| 23 | + label: 'Cities Content', |
| 24 | + folder: 'src/content/city', |
| 25 | + filter: {field: "filter", value: "city"}, |
| 26 | + create: true, |
| 27 | + delete: true, |
| 28 | + slug: "{{fields.name}}", |
| 29 | + fields: [ |
| 30 | + { name: 'name', widget: 'string', label: 'City Name' }, |
| 31 | + { name: 'language', widget: 'string', label: 'Language' }, |
| 32 | + { name: 'info', widget: 'markdown', label: 'City Info' } |
| 33 | + ], |
| 34 | + }, |
| 35 | + ], |
| 36 | + }, |
| 37 | + }), |
| 38 | +
|
| 39 | +``` |
| 40 | +We can see two main properties, backend and collections. We will take a look the options inside collecitons: |
| 41 | + |
| 42 | +The main options we have to consider are `create: true`, `delete: true` and `slug: "{{fields.name}}"`. Create and Delete properties allow us to enable/disable item creation inside the collection, and slug works just like field summary we have been using in `landings-cms > landing-* > config.json`. |
| 43 | + |
| 44 | +We have also set `filter: {field: "filter", value: "city"}` as a workaround to use nested content-collections which is not a possible option by default. By default we would have needed to set manually all possible collections. Let's see what nested collections can look like: |
| 45 | + |
| 46 | +``` |
| 47 | +├── public/ |
| 48 | +├── src/ |
| 49 | +│ ├── content/ |
| 50 | +│ ├── city/ |
| 51 | +│ └── en/ |
| 52 | +│ └── madrid.md |
| 53 | +│ └── fr/ |
| 54 | +│ └── paris.md |
| 55 | +``` |
| 56 | + |
| 57 | +Finally, fields property is an array of objects with the default NetlifyCMS options we know `name: ...`, `label: ...` ... |
| 58 | +Be careful to set the same name in fields config to the field in markdown. |
| 59 | + |
| 60 | +## How are new collections created? |
| 61 | + |
| 62 | +If `create: true`, users will be able to add new items inside a collection. |
| 63 | + |
| 64 | +By setting a slug just like mentioned before, we can set field value as file name. |
| 65 | + |
| 66 | +## How are changes made? |
| 67 | + |
| 68 | +This works as expected, the value from the modified field is updated. In workflow by default we have three options: |
| 69 | + |
| 70 | +``` |
| 71 | +- Publish now |
| 72 | +- Publish and create new |
| 73 | +- Publish and duplicate |
| 74 | +``` |
| 75 | + |
1 | 76 | # Astro Netlify-CMS Integration |
2 | 77 |
|
3 | 78 | Created with |
|
0 commit comments