johannschopplich / cacao-kit-frontend

🍫 Best practice Nuxt and KQL starter for your headless Kirby CMS
https://cacao-kit.byjohann.dev
MIT License
30 stars 3 forks source link
nuxt nuxt-i18n nuxt-starter nuxt-template nuxt-theme

Cacao Kit Frontend

Cacao Kit (Frontend)

[!TIP] If internationalization is not a requirement for your project, you can check out the 🧱 branch without i18n.

If this is your first time building an application with Nuxt, I recommend taking a look into the πŸ’š Kirby Nuxt Starterkit first to get a basic understanding of this tech-stack. It is a port of the Kirby starter kit, built with Nuxt and KQL.

This repository provides a minimal but feature-rich Nuxt 3 starter kit. It fetches content from the 🍫 Cacao Kit backend, a headless Kirby instance. It is the evolved version of the Kirby Nuxt Starterkit and my best practice solution to build a Nuxt based frontend on top of Kirby CMS.

You can harness every feature Nuxt provides to build a server-side rendered application or even pre-render the content using Nuxt's static generation.

Key design decisions is a block-first approach. Meaning, you can use Kirby's page structure as the source of truth and don't have to replicate the page structure in Nuxt. All pages are rendered by the catch-all route. Of course, you don't have to stick with the block-first architecture. If it doesn't speak to you or if you need custom Kirby page blueprints with custom fields, you can always create Nuxt pages and query the content using KQL. See the pages/about.vue page for an example.

Key Features

[!NOTE] If i18n is not a requirement for your project, you can check out the 🧱 branch without i18n.

Usage

Prerequisites

  1. Enable Corepack using corepack enable
  2. Install dependencies using pnpm install
  3. Adapt the relevant environment variables:
# Base URL of the Kirby backend
KIRBY_BASE_URL=
# Token for bearer authentication
# See https://github.com/johannschopplich/cacao-kit-backend#bearer-token
KIRBY_API_TOKEN=

Development

  1. Start the development server using pnpm run dev
  2. Visit localhost:3000

Production

Build the application for production with pnpm run build.

Check out the deployment documentation.

Cookbook

Static Hosting

You can use Nuxt's static generation to pre-render the content. This is especially useful if you want to host the application on a CDN or a static hosting service like Netlify.

How to Add a New Block

Given you have created the block in the Kirby backend, you can add it to the frontend by following these steps:

For example, let's say you have created a new block called NoteHeader and want to render it with the KirbyBlocks component:

<script setup lang="ts">
import {
+  LazyKirbyBlockNoteHeader,
} from '#components'

const blockComponents: Partial<Record<string, new () => ComponentPublicInstance>> = {
  // Custom blocks
+  'note-header': LazyKirbyBlockNoteHeader,
}
</script>

How to Bring Your Own Styling

This kit is written in semantic HTML and styled by the class-less CSS framework new.css. It is only used for the demo content. You can remove the framework by deleting the <Link /> tag in the app.vue component and start over with your own styling.

Deployment

Just like any other Nuxt application, the Cacao Kit can be deployed on a Node.js server, pre-rendered for static hosting, or deployed to serverless or edge (CDN) environments. Follow the deployment documentation to learn more.

This repository includes a netlify.toml file to deploy the application to Netlify. The recommended deployment provider is Cloudflare Pages, which doesn't require any additional configuration.

Deployment Previews

What's Kirby?

License

MIT License Β© 2023-PRESENT Johann Schopplich