🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
CMS & Integrations••By Komal Nakrani

Astro TinaCMS Setup: Git-Backed Editing for Markdown

Set up Astro TinaCMS: run tinacms init, define a schema that matches your content collections, wire dev and build scripts, and deploy with TinaCloud or self-hosted.

#Astro#TinaCMS#Git-Based CMS#Markdown#MDX

TinaCMS is a Git-backed headless CMS that gives editors a web UI for the Markdown and MDX files in your repository. For an Astro TinaCMS setup, run npx @tinacms/cli@latest init, define collections in tina/config.ts that point at your content folders, run tinacms dev -c "astro dev" locally, and build with tinacms build && astro build. Astro keeps reading the files through content collections, so your pages don’t change.

This guide covers installing Tina in an Astro 7 project, matching its schema to your collections, querying content, deployment with TinaCloud or a self-hosted backend, and where Tina’s visual editing stands for Astro.

Key Takeaways

  • Tina stores content as files in Git but adds a GraphQL content API and an admin at /admin/.
  • Keep collection path values identical to your Astro glob() loader folders.
  • Wrap your dev and build commands with the Tina CLI so the admin and schema are generated.
  • Production editing needs TinaCloud or a self-hosted Tina backend; local editing needs neither.
  • Tina’s click-to-edit visual mode is React-based, so plan for React islands if you want it in Astro.

How TinaCMS works with Astro

Tina has three parts. The admin UI is a single-page app built into public/admin/. The content API indexes your Markdown, MDX and JSON files and serves them over GraphQL. And the backend handles authentication and commits edits to Git, either through TinaCloud (the hosted service) or a self-hosted setup.

Astro only cares about the files. When an editor saves a post, Tina commits the change, your host rebuilds, and Astro’s content collections pick up the new Markdown. That separation is why Tina works with Astro without a special integration package.

Part Where it runs Needed for
Admin UI (/admin/) Static files in public/admin/ All editing
Local content server Your machine during tinacms dev Local editing
TinaCloud or self-hosted backend Hosted service or your server Editing on the live site

If you’re still comparing Git-based options, the Keystatic vs TinaCMS vs Decap comparison covers the differences in storage, UI and cost.

Install TinaCMS in an Astro project

Run the init command from the project root:

npx @tinacms/cli@latest init

It asks which package manager you use and where your public folder is (public for Astro), installs tinacms and @tinacms/cli, and creates tina/config.ts. Then update package.json so the CLI wraps Astro:

{
  "scripts": {
    "dev": "tinacms dev -c \"astro dev\"",
    "build": "tinacms build && astro build",
    "preview": "astro preview"
  }
}

tinacms dev starts the local content server, then runs astro dev. Open http://localhost:4321/admin/index.html and you can edit files on disk with no account. Add tina/__generated__ to .gitignore if the init step didn’t, and commit tina/tina-lock.json, which TinaCloud uses to read your schema.

Define a schema that matches your content collections

Tina’s schema describes the fields editors see. Astro’s Zod schema validates the same files at build time. They need to agree, or editors will save content that fails the Astro build.

// tina/config.ts
import { defineConfig } from 'tinacms';

export default defineConfig({
  branch: process.env.GITHUB_BRANCH || process.env.HEAD || 'main',
  clientId: process.env.TINA_CLIENT_ID,
  token: process.env.TINA_TOKEN,
  build: { outputFolder: 'admin', publicFolder: 'public' },
  media: { tina: { mediaRoot: 'images', publicFolder: 'public' } },
  schema: {
    collections: [
      {
        name: 'post',
        label: 'Blog posts',
        path: 'src/content/blog',
        format: 'mdx',
        fields: [
          { type: 'string', name: 'title', label: 'Title', isTitle: true, required: true },
          { type: 'string', name: 'description', label: 'Description', ui: { component: 'textarea' } },
          { type: 'datetime', name: 'pubDate', label: 'Published', required: true },
          { type: 'image', name: 'heroImage', label: 'Hero image' },
          { type: 'string', name: 'tags', label: 'Tags', list: true },
          { type: 'boolean', name: 'draft', label: 'Draft' },
          { type: 'rich-text', name: 'body', label: 'Body', isBody: true },
        ],
      },
    ],
  },
});

The matching Astro collection:

// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';

const blog = defineCollection({
  loader: glob({ pattern: '**/*.mdx', base: './src/content/blog' }),
  schema: z.object({
    title: z.string(),
    description: z.string().optional(),
    pubDate: z.coerce.date(),
    heroImage: z.string().optional(),
    tags: z.array(z.string()).default([]),
    draft: z.boolean().default(false),
  }),
});

export const collections = { blog };

Two details matter here. Tina’s datetime field writes an ISO string, so use z.coerce.date(). And Tina media uploads land in public/images/ and are written as /images/file.jpg, which is a public path, so the Astro schema uses z.string() rather than the image() helper. If you want Astro to optimize those images, render them with <Image /> and explicit dimensions, or move media into src/assets/ and adjust paths. The Astro content collections docs explain the schema options.

Rich text and MDX components

Tina’s rich-text field edits the Markdown body. With format: 'mdx', you can also let editors insert components by declaring templates on the field:

// tina/config.ts (inside the body field)
{
  type: 'rich-text',
  name: 'body',
  label: 'Body',
  isBody: true,
  templates: [
    {
      name: 'Callout',
      label: 'Callout',
      fields: [
        { type: 'string', name: 'type', label: 'Type', options: ['info', 'tip', 'warning'] },
        { type: 'rich-text', name: 'children', label: 'Text' },
      ],
    },
  ],
}

Tina writes <Callout type="tip">...</Callout> into the MDX file. Astro renders it as long as the component is available, either by importing it in the file or passing it through the components prop of <Content />. Passing components globally is cleaner, because editors won’t add import lines:

---
// src/pages/blog/[slug].astro (excerpt)
import { render } from 'astro:content';
import Callout from '../../components/Callout.astro';
const { post } = Astro.props;
const { Content } = await render(post);
---
<Content components={{ Callout }} />

Query content: collections or the Tina client

You have two ways to read content in Astro.

Content collections (recommended). Read the files with the glob loader as shown above. You get Astro’s validation, render(), and no dependency on the Tina API at build time.

The generated Tina client. tinacms build generates a typed client in tina/__generated__/client. You can query it in page frontmatter:

---
// src/pages/blog/index.astro
import client from '../../../tina/__generated__/client';

const res = await client.queries.postConnection({ sort: 'pubDate', last: 20 });
const posts = res.data.postConnection.edges?.map((e) => e?.node) ?? [];
---
<ul>
  {posts.map((p) => p && <li>{p.title}</li>)}
</ul>

The client is useful when you need Tina-specific data, such as references between documents resolved in one query, or when you’re building visual editing. For a standard blog, collections are simpler.

Deploy TinaCMS with an Astro site

Locally, no account is required. On the live site, editors need authentication and something to commit their changes. Your options:

  1. TinaCloud. Create a project, connect your GitHub repository, and copy the client ID and a read-only token into TINA_CLIENT_ID and TINA_TOKEN on your host. Editors sign in at /admin/ and TinaCloud commits for them. Check TinaCloud’s pricing page for current plan limits.
  2. Self-hosted Tina backend. Tina provides a self-hosted option where you run the backend yourself with your own auth provider, a database adapter for the content index, and a Git provider. It avoids the hosted service but needs a server, so your Astro project needs an adapter or a separate backend deployment.

With TinaCloud, the Astro site itself can stay fully static. tinacms build writes the admin into public/admin/, Astro copies it to dist/, and any static host serves it. See deploying to static hosts for Netlify, Vercel and GitHub Pages notes. Keep TINA_TOKEN read-only; it’s used at build time to fetch the schema and content index.

Visual editing in Astro

Tina’s best-known feature is contextual editing: click on the page and edit text in place. That mode works by rendering pages with React and Tina’s useTina() hook, which updates the preview as the editor types. Astro pages are server-rendered .astro components with no client runtime, so they can’t do this by themselves.

In practice, Astro sites using Tina either rely on the sidebar form editor (which works everywhere) or render the editable parts of a page as React islands with client:tina style hydration patterns from Tina’s Astro starter. Check Tina’s current Astro documentation before committing to visual editing, because support has been evolving and the official starter shows the supported approach.

If click-to-edit is a hard requirement and you don’t want React islands, an API-based CMS with Astro-specific visual editing support may fit better. The headless CMS guide for Astro compares those.

Common problems

The admin shows a schema mismatch error. tina-lock.json is out of date or not committed. Run tinacms build locally and commit the lock file.

The Astro build fails after an edit. A field Tina saved doesn’t pass the Zod schema, often an empty required string or a date format. Align the two schemas and mark Tina fields required where Astro requires them.

Images 404 on the live site. mediaRoot and publicFolder don’t match where files end up. With the config above, uploads go to public/images/ and paths start with /images/.

Builds can’t reach TinaCloud. TINA_CLIENT_ID, TINA_TOKEN or the branch variable isn’t set on the host.

Is TinaCMS right for your Astro site

Tina suits teams whose editors want a richer editor than plain forms, with MDX components and Git history, while developers keep content as files. It’s heavier than Decap and asks more of your build, but its typed schema and query client give developers more to work with.

For a marketing or blog site, the editing UI matters less than having good templates to edit into. A Komal theme from the Astro themes catalog keeps posts in a standard content collection folder, so pointing Tina’s path at it is all the wiring needed. Official references: the TinaCMS docs and Astro’s CMS guides.

FAQ

Does TinaCMS work with Astro?

Yes. Tina edits Markdown, MDX and JSON files in your repository, and Astro reads those files with content collections. You wrap the Astro dev and build commands with the Tina CLI, and the admin is served from public/admin/.

Is TinaCMS free for Astro projects?

The Tina packages are open source and local editing is free. Editing on a live site needs TinaCloud, which has a free tier and paid plans, or a self-hosted backend that you run yourself. Check TinaCloud’s site for current limits.

Can I use TinaCMS with a static Astro site?

Yes, with TinaCloud. The admin is a set of static files built into public/admin/, and TinaCloud handles login and commits, so the site needs no adapter. A self-hosted Tina backend does need a server.

Does TinaCMS visual editing work in Astro?

Partly. Tina’s click-to-edit mode depends on React rendering with the useTina() hook, so in Astro it works only for parts rendered as React islands. The sidebar form editor works on any Astro page.

TinaCMS or Keystatic for Astro?

Choose Tina if editors want MDX components in a rich editor and you’re happy using TinaCloud. Choose Keystatic if you want a TypeScript config, simple local mode and GitHub storage without a hosted service.