DeaJae
Hero image for DecapCMS with 11ty

DecapCMS with 11ty

Integrating DecapCMS into an 11ty project

I decided I needed some sanity, so I looked into a cheap-to-run localhost-based Content Management System.

Coming from a WordPress system after many years, I feel a bit of distrust when I see most Content Management Features, and then the prices of cloud versions put me off too.

I considered using WordPress.com and pulling posts via API, but that option is likely rate-limited or unavailable for lower-tier plans.

The Setup

Installing DecapCMS via their Documents was easy, but configuring the environment is not. Lots of information then gets confused with itself (for example there are path parameters which show item: “string” and item: string). I Decided to keep my install local to stop Github being bothered by anything finding/crawling the admin directory.

Configuration

Here’s what I needed to change, hopefully, it’ll make sense to people needing that bit of help who’ve already seen the mess of documentation and GitHub issues.

# when using the default proxy server port
local_backend: true

backend:
 # name: git-gateway
  name: github
  repo: YourGithubUser/ProjectRepo
  # optional, defaults to master
  # branch: main

site_url: https://Yoursite.domain
#site_url: http://localhost:8080/ # for testing
publish_mode: editorial_workflow
media_folder: "/assets/images/" #Your main image source if not in /posts.
#public_folder: 'images' # defaults to media_folder if not present.

collections: # A list of collections the CMS should be able to edit
  - name: 'posts' # Used in routes, ie.: /admin/collections/:slug/edit
    label: 'Posts' # Used in the UI
    label_singular: 'Post' # Used in the UI, ie: "New Post"
    description: >
      The description is a great place for tone setting, high level information, and editing
      guidelines that are specific to a collection.
    folder: 'posts' # must match folder where Posts are.
   # slug: '---'
    slug: ''
    summary: 'DecapCMS with 11ty -- //'
    create: true # Allow users to create new documents in this collection
    path: ''
    editor:
      visualEditing: true
    view_filters:
      - label: Posts With Index
        field: title
        pattern: 'This is post #'
      - label: Posts Without Index
        field: title
        pattern: front matter post
      - label: Drafts
        field: draft
        pattern: true
    view_groups:
      - label: Year
        field: date
        pattern: \d{4}
      - label: Drafts
        field: draft
     
    fields: # The fields each document in this collection have
      - { label: 'Title', name: 'title', widget: 'string', tagname: 'h1' }
      - { label: 'Draft', name: 'draft', widget: 'boolean', default: false }
      - {
          label: 'Publish Date',
          name: 'date',
          widget: 'datetime',
          format: 'YYYY-MM-DD', # removed HH:MM:SS as my 11ty setup didn't like it. also causes issues with sorting in /admin
          default: '',
        }
      - { label: "Permalink", name: "permalink", widget: "string" }
      - label: 'Cover Image',
        name: 'hero', #name of frontmatter item to match
        widget: 'image',
        media_folder: '/assets/images',
        public_folder: '/assets/images',
        required: false
        tagname: ''
      
      - { label: 'Body', name: 'body', widget: 'markdown', hint: 'Main content goes here.' }

I also had to fix up pages with a new section.

- name: "pages"
    label: "Page"
    folder: "pages"
    create: false # Change to true to allow editors to create new pages
    slug: ""
    fields:
      - { label: "Title", name: "title", widget: "string", tag: "h1" }
      - { label: "Publish Date", name: "date", widget: "datetime" }
      - { label: "Permalink", name: "permalink", widget: "string" }
      - label: "Navigation" # https://www.11ty.dev/docs/plugins/navigation/
        name: "eleventyNavigation"
        widget: "object"
        fields:
          - { label: "Key", name: "key", widget: "string" }
          - { label: "Order", name: "order", widget: "number", default: 0 }
      - { label: "Body", name: "body", widget: "markdown" }

And likely to add another for Projects when I have new ones to put up.

Security

I’ve decided to keep this localhost for the time being, adding the /admin folder to .gitignore so it doesn’t appear on the live site.

There are still some oddities, despite the repo being private, people can attempt to pull/write to branches once they know fork locations.

I Just have to remember to run ‘Decap-server’ as well as ‘11ty build’ in separate terminals.

Found Issues

Information To add:

Tags:
  • ,
  • ,