Decap CMS & Astro
Este conteúdo não está disponível em sua língua ainda.
Decap CMS (formerly Netlify CMS) is an open-source, Git-based content management system.
Decap allows you to take full advantage of all of Astro’s features, including image optimization and content collections.
Decap adds a route (typically /admin) to your project that will load a React app to allow authorized users to manage content directly from the deployed website. Decap will commit changes directly to your Astro project’s source repository.
Installing DecapCMS
Section titled “Installing DecapCMS”There are two options for adding Decap to Astro:
-
Install Decap via a package manager with the following command:
Terminal window npm install decap-cms-appTerminal window pnpm add decap-cms-appTerminal window yarn add decap-cms-app -
Import the package into a
<script>tag in your page<body>/admin <body><!-- Include the script that builds the page and powers Decap CMS --><script src="https://unpkg.com/decap-cms@^3.1.2/dist/decap-cms.js"></script></body>
Configuration
Section titled “Configuration”-
Create a static admin folder at
public/admin/ -
Add
config.ymltopublic/admin/:Directorypublic
Directoryadmin
- config.yml
-
To add support for content collections, configure each schema in
config.yml. The following example configures ablogcollection, defining alabelfor each entry’s frontmatter property:/public/admin/config.yml collections:- name: "blog" # Used in routes, e.g., /admin/collections/bloglabel: "Blog" # Used in the UIfolder: "src/content/blog" # The path to the folder where the documents are storedcreate: true # Allow users to create new documents in this collectionfields: # The fields for each document, usually in frontmatter- { label: "Layout", name: "layout", widget: "hidden", default: "blog" }- { label: "Title", name: "title", widget: "string" }- { label: "Publish Date", name: "date", widget: "datetime" }- { label: "Featured Image", name: "thumbnail", widget: "image" }- { label: "Rating (scale of 1-5)", name: "rating", widget: "number" }- { label: "Body", name: "body", widget: "markdown" } -
Add the
adminroute for your React app insrc/pages/admin.html.Directorypublic
Directoryadmin
- config.yml
Directorysrc
Directorypages
- admin.html
/src/pages/admin.html <!doctype html><html lang="en"><head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="robots" content="noindex" /><link href="/admin/config.yml" type="text/yaml" rel="cms-config-url" /><title>Content Manager</title></head><body><script src="https://unpkg.com/decap-cms@^3.1.2/dist/decap-cms.js"></script></body></html>Content Manager