Nuxt Content

repository·main·Indexed 25 days ago

https://github.com/nuxt/content

A content management engine for Nuxt 3 that transforms files in a content/ directory (.md, .yml, .csv, .json) into a queryable data layer. It features MDC syntax for rendering Vue components within Markdown, a SQLite-powered query builder, and support for typed collections via defineContentConfig. The ecosystem includes Docus for documentation sites and Nuxt Studio for a self-hosted content management experience with Git integration and real-time previews.

Tokens
52.8K
Snippets
180
Records
310
Agent score
87%

What's inside @nuxt/content

  1. Overview of Nuxt Studio features

    main

    Nuxt Studio is a self-hosted, open-source content management solution that runs alongside your Nuxt Content website. Key features include:

    • TipTap Visual Editor: A Notion-like Markdown editor with MDC component support, slash commands, and real-time MDC syntax conversion.
    • Form-Based Editor: Automatically generated schema-based forms for frontmatter, YAML, and JSON files based on your collection definitions.
    • File Operations: Full CRUD (Create, Read, Update, Delete) capabilities for the content/ directory, including draft management.
    • Media Management: A centralized library for assets in the public/ directory.
    • Git Integration: Direct commits to GitHub or GitLab with conflict detection and custom commit messages.
    • Real-time Preview: Side-by-side live preview of draft changes on your website.
    • Authentication: Supports GitHub OAuth, GitLab OAuth, Google OAuth, or custom authentication flows.
  2. Overview of Nuxt Studio Alpha features

    main

    The Nuxt Studio alpha release provides a self-hosted, open-source content management experience directly within your Nuxt application. Key features include:

    • Monaco Code Editor: An IDE-like experience with syntax highlighting for Markdown, YAML, and JSON, including MDC support and a split-screen diff viewer.
    • File Operations: Full CRUD capabilities (Create, Read, Update, Delete) for the content/ directory, including renaming and moving files.
    • Media Management: A centralized library for managing assets in the public/ directory (upload, organize, preview).
    • Git Integration: Direct commits to GitHub via OAuth with conflict detection and author attribution.
    • Real-time Preview: Live preview of draft changes on your production website with instant updates.
  3. Overview of Nuxt Content

    main
    Nuxt Content creates a powerful data layer for your application by reading the content/ directory in your project. It parses .md, .yml, .csv, or .json files and allows you to use Vue components directly within Markdown using MDC syntax.
  4. Introduction to Nuxt Content v3

    main
    Nuxt Content v3 is a Git-based CMS designed for Nuxt developers. It uses Content Collections to manage large datasets with structured data, type-safe queries, and automatic validation. In production, it utilizes an adapter-based SQL storage system to improve performance and scalability across server, serverless, and static deployments without requiring manual configuration.
  5. Understand the Nuxt Content v3 SQLite storage architecture

    main

    Nuxt Content v3 uses a SQLite-based storage layer instead of the file-based system used in v2. This architecture improves performance and scalability by moving away from parsing individual cache files during runtime.

    The workflow consists of three stages:

    1. Generation: Content is parsed into an Abstract Syntax Tree (AST) and inserted into collection-specific tables based on your defined schema. This data is saved into a database dump file.
    2. Restoration: On the first query during runtime (cold start), the module restores the dump into the target database. It uses an integrity check to ensure the database is up-to-date and to prevent duplicate imports.
    3. Client-side execution: For client-side navigation, the module downloads the dump from the server and initializes a local SQLite database in the browser using WASM. Subsequent queries are executed locally, enabling high responsiveness and offline capabilities.
  6. Key features of Nuxt Content

    main

    Nuxt Content provides several core capabilities for content-driven applications:

    • Nuxt 3 Support: Built specifically for the Nuxt 3 ecosystem.
    • Edge Ready: Works in serverless and edge environments like Cloudflare Workers.
    • MDC Syntax: Render Vue components inside Markdown files.
    • Typed Data: Fully typed collections and queries.
    • Navigation: Automatic generation of navigation structures.
    • Fast Development: Blazing fast hot module replacement (HMR).
    • Code Highlighting: Uses Shiki for high-quality syntax highlighting.
    • Query Builder: A powerful query builder powered by a SQLite database.
  7. Authentication methods in Nuxt Studio

    main

    Nuxt Studio supports two authentication methods:

    1. GitHub: Provides full access, including the ability to create new projects.
    2. Google: Allows editing existing projects, but Google users cannot create new projects. To edit projects with a Google account, the user must be invited to join an existing team.
  8. Inspect the Nuxt Content SQLite database with VS Code

    main

    Nuxt Content uses an SQLite database located at .data/content/contents.sqlite to store and query content. You can inspect this database using the SQLite extension by alexcvzz in Visual Studio Code.

    Setup Steps

    1. Install the SQLite extension in VS Code.
    2. Ensure your Nuxt app is running (npx nuxi dev) so the .data/content/contents.sqlite file is generated.
    3. Right-click contents.sqlite in your file explorer and select "Open Database".
    4. Use the Database Explorer panel to view tables and data.
    npx nuxi dev
  9. Use Zod v3 for collection schemas

    main

    You can use Zod v3 to define collection schemas for data consistency and type-safety. When using Zod v3, you must install both zod and zod-to-json-schema.

    Note: Do not use the deprecated z re-export from @nuxt/content. Instead, import z directly from zod or zod/v3.

    pnpm add -D zod zod-to-json-schema
    # or
    npm i -D zod zod-to-json-schema
    import { defineContentConfig, defineCollection, property } from '@nuxt/content'
    import { z } from 'zod'
    
    export default defineContentConfig({
      collections: {
        blog: defineCollection({
          type: 'page',
          source: 'blog/*.md',
          schema: z.object({
            title: z.string(),
            description: z.string().optional(),
            date: z.date(),
            draft: z.boolean().default(false),
            tags: z.array(z.string()).optional(),
            image: z.object({
              src: property(z.string()).editor({ input: 'media' }),
              alt: z.string()
            })
          })
        })
      }
    })
  10. Customize Nuxt Studio forms with Zod schemas

    main

    Nuxt Studio forms are dynamically generated based on the collection schema defined in your content.config.ts. By using zod to define your collection schema, you provide both type-safety for your content and instructions for how the Studio editor should render form inputs.

    To define a schema, add the schema property to a collection within defineContentConfig using the z object provided by @nuxt/content.

    export default defineContentConfig({
      collections: {
        posts: defineCollection({
          type: 'page',
          source: 'blog/*.md',
          schema: z.object({
            draft: z.boolean().default(false),
            category: z.enum(['Alps', 'Himalaya', 'Pyrenees']).optional(),
            date: z.date(),
            image: z.object({
              src: z.string().editor({ input: 'media' }),
              alt: z.string(),
            }),
            slug: z.string().editor({ hidden: true }),
            icon: z.string().optional().editor({ input: 'icon' }),
            authors: z.array(z.object({
              slug: z.string(),
              username: z.string(),
              name: z.string(),
              to: z.string(),
              avatar: z.object({
                src: z.string(),
                alt: z.string(),
              }),
            })),
          }),
        }),
      },
    })
  11. Pass Props to MDC Components

    main

    There are two primary ways to pass props to components in MDC:

    1. Inline Method

    Use the {} identifier with a key=value syntax. Multiple props are separated by spaces.

    ::alert{type="warning" icon="exclamation-circle"}
    Oops! An error occurred
    ::

    To pass arrays or objects, use a JSON string and prefix the key with a colon (:) to automatically decode it:

    ::dropdown{:items='["Nuxt", "Vue", "React"]'}
    ::

    You can also use the : shorthand to bind a prop to a value defined in the document's frontmatter:

    ::alert{:type="type"}
    Your warning
    ::

    2. YAML Method

    For better readability, use a YAML block inside the component identifier:

    ::icon-card
    ---
    icon: IconNuxt
    description: Harness the full power of Nuxt.
    title: Nuxt Architecture.
    ---
    ::