Skip to content

Latest commit

 

History

History
159 lines (121 loc) · 6.64 KB

decap-cms.mdx

File metadata and controls

159 lines (121 loc) · 6.64 KB
title description type stub service i18nReady
Decap CMS & Astro
Add content to your Astro project using Decap as a CMS
cms
true
Decap CMS
true

import Grid from '/components/FluidGrid.astro'; import Card from '/components/ShowcaseCard.astro'; import { Steps } from '@astrojs/starlight/components'; import { FileTree } from '@astrojs/starlight/components'; import PackageManagerTabs from '~/components/tabs/PackageManagerTabs.astro';

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

There are two options for adding Decap to Astro:

  1. Install Decap via a package manager with the following command:

    ```shell npm install decap-cms-app ``` ```shell pnpm add decap-cms-app ``` ```shell yarn add decap-cms-app ```
  2. Import the package into a <script> tag in your page <body>

    <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

1. Create a static admin folder at `public/admin/`
  1. Add config.yml to public/admin/:

    • public
      • admin
        • config.yml
  2. To add support for content collections, configure each schema in config.yml. The following example configures a blog collection, defining a label for each entry's frontmatter property:

    collections:
      - name: "blog" # Used in routes, e.g., /admin/collections/blog
        label: "Blog" # Used in the UI
        folder: "src/content/blog" # The path to the folder where the documents are stored
        create: true # Allow users to create new documents in this collection
        fields: # 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" }
  3. Add the admin route for your React app. This file can be either public/admin/index.html alongside your config.yml or, if you prefer to use an Astro route, src/pages/admin.astro.

    • public
      • admin
        • config.yml
        • index.html
    ```html title="/public/admin/index.html" {7, 11} <title>Content Manager</title> <script src="https://unpkg.com/decap-cms@^3.1.2/dist/decap-cms.js"></script> ```
  4. To enable media uploads to a specific folder via the Decap editor, add an appropriate path:

    media_folder: "src/assets/images" # Location where files will be stored in the repo 
    public_folder: "src/assets/images" # The src attribute for uploaded media

See the the Decap CMS configuration documentation for full instructions and options.

Usage

Navigate to yoursite.com/admin/ to use the Decap CMS editor.

Authentication

Decap CMS with Netlify Identity

Decap CMS was originally developed by Netlify and has first class support for Netlify Identity.

When deploying to netlify, configure Identity for your project via the Netlify dashboard and include the Netlify Identity Widget on the admin route of your project. Optionally include the Identity Widget on the homepage of your site if you plan to invite new users via email.

Decap CMS with External OAuth Clients

When deploying to hosting providers other than Netlify, you must create your own OAuth routes.

In Astro, this can be done with on-demand rendered routes in your project configured with server or hybrid output enabled.

See Decap's OAuth Docs for a list of compatible community-maintained OAuth clients.

Community Resources

Production Sites

The following sites use Astro + Decap CMS in production:

Themes