Saltearse al contenido

Comienza aquí

Para empezar a usar StudioCMS, necesitarás:

  • Un proyecto de Astro
  • Un proveedor libSQL o un servidor libSQL autoalojado
  • La integración StudioCMS

StudioCMS usa @astrojs/db para conectarse a tu base de datos libSQL. Puedes usar cualquier proveedor libSQL o un servidor libSQL autoalojado.

Si estás usando la CLI de StudioCMS, puedes omitir este paso y usar la CLI para crear una nueva base de datos si tienes la CLI de Turso instalada.

Para más información sobre las variables de entorno requeridas, consulta URL de la base de datos y token para @astrojs/db
  1. Instala la CLI de Turso ^

  2. Inicia sesión o regístrate ^ en Turso.

  3. Crea una nueva base de datos.

    Ventana de terminal
    turso db create studiocms
  4. Obtén y configura ASTRO_DB_REMOTE_URL

    4a. Ejecuta el comando show para ver información sobre la base de datos recién creada:

    Ventana de terminal
    turso db show studiocms

    4b. Copia el valor de la URL y configúralo como el valor de ASTRO_DB_REMOTE_URL.

    .env
    ASTRO_DB_REMOTE_URL=libsql://studiocms-tunombre.turso.io
  5. Obtén y configura ASTRO_DB_APP_TOKEN

    5a. Crea un nuevo token para autenticar las solicitudes a la base de datos:

    Ventana de terminal
    turso db tokens create studiocms

    5b. Copia la salida del comando y configúrala como el valor de ASTRO_DB_APP_TOKEN.

    .env
    ASTRO_DB_APP_TOKEN=eyJhbGciOiJF...3ahJpTkKDw

¡Ahora estás listo para continuar con la configuración de tu proyecto StudioCMS!

libSQL admite tanto HTTP como WebSockets como protocolo de transporte para un servidor remoto. También admite el uso de un archivo local o una base de datos en memoria.

Para más información sobre las variables de entorno requeridas, consulta URL de la base de datos y token para @astrojs/db
Para más información sobre todas las opciones potenciales de libSQL (incluidos los archivos locales), consulta Astro Docs: Remote URL configuration options^
  1. Creando un proyecto StudioCMS usando el comando create

    Para crear un nuevo proyecto Astro con StudioCMS usando una de nuestras plantillas predefinidas, simplemente ejecuta el siguiente comando en tu terminal:

    Ventana de terminal
    npm create studiocms@latest

    Después de ejecutar el comando, se te pedirá que respondas algunas preguntas sobre tu proyecto. Una vez completado, la CLI creará un nuevo proyecto Astro con StudioCMS en el directorio especificado.

    Luego, se te pedirá que sigas los siguientes pasos, que incluyen asegurarte de que tus variables de entorno estén configuradas correctamente y ejecutar el proyecto para completar la configuración.

  2. Después de ejecutar la CLI, asegúrate de que tu archivo astro.config.mjs esté configurado correctamente:

    astro.config.mjs
    import {
    function defineConfig<const TLocales extends Locales = never, const TDriver extends SessionDriverName = never>(config: AstroUserConfig<TLocales, TDriver>): AstroUserConfig<TLocales, TDriver>

    See the full Astro Configuration API Documentation https://astro.build/config

    defineConfig
    } from 'astro/config';
    import
    function db(): AstroIntegration[]
    db
    from '@astrojs/db';
    import
    function node(userOptions: UserOptions): AstroIntegration
    node
    from '@astrojs/node';
    import
    const studioCMS: (options?: {
    dbStartPage?: boolean | undefined;
    rendererConfig?: {
    studiocms?: false | {
    callouts?: false | {
    theme?: "github" | "obsidian" | "vitepress" | undefined;
    } | undefined;
    autoLinkHeadings?: boolean | undefined;
    discordSubtext?: boolean | undefined;
    sanitize?: {
    allowElements?: string[] | undefined;
    blockElements?: string[] | undefined;
    dropElements?: string[] | undefined;
    allowAttributes?: Record<string, string[]> | undefined;
    dropAttributes?: Record<string, string[]> | undefined;
    allowComponents?: boolean | undefined;
    allowCustomElements?: boolean | undefined;
    allowComments?: boolean | undefined;
    } | undefined;
    } | undefined;
    renderer?: "studiocms" | CustomRenderer | "astro" | "markdoc" | "mdx" | undefined;
    markdocConfig?: {
    renderType?: "html" | MarkdocRenderer | "react-static" | undefined;
    argParse?: {
    file?: string | undefined;
    slots?: boolean | undefined;
    location?: boolean | undefined;
    } | undefined;
    transformConfig?: {
    tags?: Record<string, {}> | undefined;
    validation?: {
    parents?: any[] | undefined;
    validateFunctions?: boolean | undefined;
    environment?: string | undefined;
    } | undefined;
    nodes ...

    StudioCMS Integration

    A CMS built for Astro by the Astro Community for the Astro Community.

    @seeThe GitHub Repo: withstudiocms/studiocms for more information on how to contribute to StudioCMS.

    @seeThe StudioCMS Docs for more information on how to use StudioCMS.

    studioCMS
    from 'studiocms';
    export default
    defineConfig<never, never>(config: AstroUserConfig<never, never>): AstroUserConfig<never, never>

    See the full Astro Configuration API Documentation https://astro.build/config

    defineConfig
    ({
    AstroUserConfig<TLocales extends Locales = never, TSession extends SessionDriverName = never>.site?: string

    @namesite

    @type{string}

    @description

    Your final, deployed URL. Astro uses this full URL to generate your sitemap and canonical URLs in your final build. It is strongly recommended that you set this configuration to get the most out of Astro.

    {
    site: 'https://www.my-site.dev'
    }

    site
    : 'https://demo.studiocms.dev/',
    AstroUserConfig<TLocales extends Locales = never, TSession extends SessionDriverName = never>.output?: "server" | "static"

    @nameoutput

    @type{('static' | 'server')}

    @default'static'

    @seeadapter *

    @description

    Specifies the output target for builds.

    • 'static' - Prerender all your pages by default, outputting a completely static site if none of your pages opt out of prerendering.
    • 'server' - Use server-side rendering (SSR) for all pages by default, always outputting a server-rendered site.
    import { defineConfig } from 'astro/config';
    export default defineConfig({
    output: 'static'
    })

    output
    : 'server',
    AstroUserConfig<TLocales extends Locales = never, TSession extends SessionDriverName = never>.adapter?: AstroIntegration

    @nameadapter

    @seeoutput *

    @description

    Deploy to your favorite server, serverless, or edge host with build adapters. Import one of our first-party adapters for Netlify, Vercel, and more to engage Astro SSR.

    See our On-demand Rendering guide for more on SSR, and our deployment guides for a complete list of hosts.

    import netlify from '@astrojs/netlify';
    {
    // Example: Build for Netlify serverless deployment
    adapter: netlify(),
    }

    adapter
    :
    function node(userOptions: UserOptions): AstroIntegration
    node
    ({
    UserOptions.mode: "standalone" | "middleware"

    Specifies the mode that the adapter builds to.

    • 'middleware' - Build to middleware, to be used within another Node.js server, such as Express.
    • 'standalone' - Build to a standalone server. The server starts up just by running the built script.

    mode
    : "standalone" }),
    AstroUserConfig<TLocales extends Locales = never, TSession extends SessionDriverName = never>.integrations?: (false | AstroIntegration | (false | AstroIntegration | null | undefined)[] | null | undefined)[]

    @nameintegrations

    @description

    Extend Astro with custom integrations. Integrations are your one-stop-shop for adding framework support (like Solid.js), new features (like sitemaps), and new libraries (like Partytown).

    Read our Integrations Guide for help getting started with Astro Integrations.

    import react from '@astrojs/react';
    import mdx from '@astrojs/mdx';
    {
    // Example: Add React + MDX support to Astro
    integrations: [react(), mdx()]
    }

    integrations
    : [
    function db(): AstroIntegration[]
    db
    (),
    function studioCMS(options?: {
    dbStartPage?: boolean | undefined;
    rendererConfig?: {
    studiocms?: false | {
    callouts?: false | {
    theme?: "github" | "obsidian" | "vitepress" | undefined;
    } | undefined;
    autoLinkHeadings?: boolean | undefined;
    discordSubtext?: boolean | undefined;
    sanitize?: {
    allowElements?: string[] | undefined;
    blockElements?: string[] | undefined;
    dropElements?: string[] | undefined;
    allowAttributes?: Record<string, string[]> | undefined;
    dropAttributes?: Record<string, string[]> | undefined;
    allowComponents?: boolean | undefined;
    allowCustomElements?: boolean | undefined;
    allowComments?: boolean | undefined;
    } | undefined;
    } | undefined;
    renderer?: "studiocms" | CustomRenderer | "astro" | "markdoc" | "mdx" | undefined;
    markdocConfig?: {
    renderType?: "html" | MarkdocRenderer | "react-static" | undefined;
    argParse?: {
    file?: string | undefined;
    slots?: boolean | undefined;
    location?: boolean | undefined;
    } | undefined;
    transformConfig?: {
    tags?: Record<string, {}> | undefined;
    validation?: {
    parents?: any[] | undefined;
    validateFunctions?: boolean | undefined;
    environment?: string | undefined;
    } | undefined;
    nodes ...

    StudioCMS Integration

    A CMS built for Astro by the Astro Community for the Astro Community.

    @seeThe GitHub Repo: withstudiocms/studiocms for more information on how to contribute to StudioCMS.

    @seeThe StudioCMS Docs for more information on how to use StudioCMS.

    studioCMS
    (),
    ],
    });

Ten en cuenta que la opción site en el archivo astro.config.mjs es necesaria para que StudioCMS funcione correctamente. Puedes configurarla con la URL de tu sitio o una URL de marcador de posición. (es decir, https://demo.studiocms.xyz/ o http://localhost:4321/)

StudioCMS Auth requiere al menos la Clave de Cifrado para ser configurada en tu archivo .env.

Las siguientes variables de entorno son necesarias para la autenticación de StudioCMS:

.env
# clave de cifrado para la autenticación de nombre de usuario y contraseña
CMS_ENCRYPTION_KEY="wqR+w...sRcg=="

Puedes generar una clave de cifrado segura usando el siguiente comando:

Ventana de terminal
openssl rand --base64 16

Y configurar la salida como el valor de CMS_ENCRYPTION_KEY.

Para más información sobre todas las variables de entorno disponibles para la autenticación, consulta la página de Variables de entorno.

StudioCMS admite autenticación oAuth con GitHub, Discord, Google y Auth0. Para configurar la autenticación oAuth, necesitarás configurar las variables de entorno requeridas en tu archivo .env, y asegurarte de que el proveedor esté habilitado en tu configuración.

Para configurar los proveedores oAuth, requieren una URL de callback. La URL de callback es la ruta donde el proveedor redirigirá al usuario después de la autenticación.

La URL de callback debe configurarse en una de las siguientes rutas según tu entorno:

EntornoURL de Callback
Producciónhttps://tu-dominio.tld/studiocms_api/auth/<provider>/callback
Pruebas & Devhttp://localhost:4321/studiocms_api/auth/<provider>/callback

Las siguientes rutas son ejemplos de la URL de callback para cada proveedor:

ProveedorPATH de Callback
GitHub/studiocms_api/auth/github/callback
Discord/studiocms_api/auth/discord/callback
Google/studiocms_api/auth/google/callback
Auth0/studiocms_api/auth/auth0/callback

Configura los scripts de tu package.json para incluir la bandera --remote para build, y opcionalmente para dev. (También puedes ejecutar el comando dev como se muestra en la sección “Ejecutando tu proyecto StudioCMS”)

package.json
{
"name": "my-studiocms-project",
"scripts": {
"dev": "astro dev --remote",
"build": "astro check & astro build --remote",
"astro": "astro"
}
}

Gracias al poder de Astro, ejecutar StudioCMS es tan fácil como ejecutar el comando dev para la vista previa local, o construir y desplegar en tu servidor. Para lo básico de cómo usarlo localmente sin construir, esto es lo que necesitas hacer.

Configuración inicial (o durante actualizaciones si se actualiza el esquema de tablas)

'Read the “', Configuración inicial (o durante actualizaciones si se actualiza el esquema de tablas), '” section'

Para iniciar tu proyecto Astro, ejecuta los siguientes comandos en tu terminal:

Ventana de terminal
npx astro db push --remote
Ventana de terminal
npm run dev --remote

Después de ejecutar los comandos, deberías ver un mensaje indicando que tu proyecto está ejecutándose en localhost:4321. Al configurar StudioCMS por primera vez, se te pedirá que termines de configurar StudioCMS en http://localhost:4321/start

Para iniciar tu proyecto Astro, ejecuta el siguiente comando en tu terminal:

Ventana de terminal
npm run dev --remote

Después de ejecutar el comando, deberías ver un mensaje indicando que tu proyecto está ejecutándose en localhost:4321. Abre tu navegador y navega a http://localhost:4321 para ver tu proyecto Astro en acción.

¡Felicidades! 🥳 Ahora tienes StudioCMS instalado en tu proyecto Astro.

StudioCMS es un CMS sin cabeza de Astro, lo que significa que debes proporcionar tu propio frontend para mostrar el contenido. Si estás buscando un frontend ya construido, puedes consultar nuestros plugins en el Catálogo de Paquetes.

Si estás buscando configurar un blog, puedes usar el plugin @studiocms/blog para comenzar.

Para instalar y configurar el plugin de blog, ejecuta el siguiente comando en tu terminal:

Ventana de terminal
npm install @studiocms/blog

Después de instalar el plugin, necesitarás agregar el plugin a tu archivo studiocms.config.mjs:

studiocms.config.mjs
import {
function defineStudioCMSConfig(config: StudioCMSOptions): {
dbStartPage?: boolean | undefined;
rendererConfig?: {
studiocms?: false | {
callouts?: false | {
theme?: "github" | "obsidian" | "vitepress" | undefined;
} | undefined;
autoLinkHeadings?: boolean | undefined;
discordSubtext?: boolean | undefined;
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
} | undefined;
renderer?: "studiocms" | CustomRenderer | "astro" | "markdoc" | "mdx" | undefined;
markdocConfig?: {
renderType?: "html" | MarkdocRenderer | "react-static" | undefined;
argParse?: {
file?: string | undefined;
slots?: boolean | undefined;
location?: boolean | undefined;
} | undefined;
transformConfig?: {
tags?: Record<string, {}> | undefined;
validation?: {
parents?: any[] | undefined;
validateFunctions?: boolean | undefined;
environment?: string | undefined;
} | undefined;
...

A utility function to define the StudioCMS config object. This function is used to define the optional StudioCMS config object in the Astro project root. The expected file name is studiocms.config.mjs. And it should be adjacent to the Astro project's astro.config.mjs file.

StudioCMS will attempt to import this file and use the default export as the StudioCMS config object automatically if it exists.

Using this function is optional, but it can be useful for IDEs to provide better intellisense and type checking.

@example

// studiocms.config.mjs
import { defineStudioCMSConfig } from 'studiocms';
export default defineStudioCMSConfig({
dbStartPage: true,
contentRenderer: 'marked',
verbose: true,
dateLocale: 'en-us',
// ...Other Options
})

defineStudioCMSConfig
} from 'studiocms/config';
import
function blog(options?: StudioCMSBlogOptions): StudioCMSPlugin

Creates and configures the StudioCMS Blog plugin.

@paramoptions - Optional configuration options for the blog plugin.

@returnsThe configured StudioCMS plugin.

@example

const blogPlugin = studioCMSBlogPlugin({
blog: {
title: 'My Blog',
enableRSS: true,
route: '/my-blog'
},
sitemap: true,
injectRoutes: true
});

@paramoptions.blog - Blog-specific options.

@paramoptions.blog.title - The title of the blog. Defaults to 'Blog'.

@paramoptions.blog.enableRSS - Whether to enable RSS feed. Defaults to true.

@paramoptions.blog.route - The route for the blog. Defaults to '/blog'.

@paramoptions.sitemap - Whether to trigger sitemap generation. Defaults to true.

@paramoptions.injectRoutes - Whether to inject routes for the blog. Defaults to true.

blog
from '@studiocms/blog';
export default
function defineStudioCMSConfig(config: StudioCMSOptions): {
dbStartPage?: boolean | undefined;
rendererConfig?: {
studiocms?: false | {
callouts?: false | {
theme?: "github" | "obsidian" | "vitepress" | undefined;
} | undefined;
autoLinkHeadings?: boolean | undefined;
discordSubtext?: boolean | undefined;
sanitize?: {
allowElements?: string[] | undefined;
blockElements?: string[] | undefined;
dropElements?: string[] | undefined;
allowAttributes?: Record<string, string[]> | undefined;
dropAttributes?: Record<string, string[]> | undefined;
allowComponents?: boolean | undefined;
allowCustomElements?: boolean | undefined;
allowComments?: boolean | undefined;
} | undefined;
} | undefined;
renderer?: "studiocms" | CustomRenderer | "astro" | "markdoc" | "mdx" | undefined;
markdocConfig?: {
renderType?: "html" | MarkdocRenderer | "react-static" | undefined;
argParse?: {
file?: string | undefined;
slots?: boolean | undefined;
location?: boolean | undefined;
} | undefined;
transformConfig?: {
tags?: Record<string, {}> | undefined;
validation?: {
parents?: any[] | undefined;
validateFunctions?: boolean | undefined;
environment?: string | undefined;
} | undefined;
...

A utility function to define the StudioCMS config object. This function is used to define the optional StudioCMS config object in the Astro project root. The expected file name is studiocms.config.mjs. And it should be adjacent to the Astro project's astro.config.mjs file.

StudioCMS will attempt to import this file and use the default export as the StudioCMS config object automatically if it exists.

Using this function is optional, but it can be useful for IDEs to provide better intellisense and type checking.

@example

// studiocms.config.mjs
import { defineStudioCMSConfig } from 'studiocms';
export default defineStudioCMSConfig({
dbStartPage: true,
contentRenderer: 'marked',
verbose: true,
dateLocale: 'en-us',
// ...Other Options
})

defineStudioCMSConfig
({
dbStartPage?: boolean | undefined
dbStartPage
: false,
plugins?: StudioCMSPlugin[] | undefined
plugins
: [
function blog(options?: StudioCMSBlogOptions): StudioCMSPlugin

Creates and configures the StudioCMS Blog plugin.

@paramoptions - Optional configuration options for the blog plugin.

@returnsThe configured StudioCMS plugin.

@example

const blogPlugin = studioCMSBlogPlugin({
blog: {
title: 'My Blog',
enableRSS: true,
route: '/my-blog'
},
sitemap: true,
injectRoutes: true
});

@paramoptions.blog - Blog-specific options.

@paramoptions.blog.title - The title of the blog. Defaults to 'Blog'.

@paramoptions.blog.enableRSS - Whether to enable RSS feed. Defaults to true.

@paramoptions.blog.route - The route for the blog. Defaults to '/blog'.

@paramoptions.sitemap - Whether to trigger sitemap generation. Defaults to true.

@paramoptions.injectRoutes - Whether to inject routes for the blog. Defaults to true.

blog
(),
],
});

Después de ejecutar los pasos de configuración inicial, deberías construir y desplegar tu proyecto StudioCMS en tu servidor.

Por defecto, el panel de control de StudioCMS está disponible en http://tu-dominio.tld/dashboard.

Este panel de control estará disponible para que administres tu contenido y configuraciones en modo de desarrollo y en modo de producción.

Se recomienda usar StudioCMS solo en modo de producción, ya que el panel de control está destinado a ser utilizado por el proyecto construido. (Puedes ver algunos problemas/errores en modo de desarrollo, como un error de dependencia de Vite.)

Consulta cómo configurar Variables de Entorno en StudioCMS.

Consulta el Catálogo de Paquetes para encontrar y usar plugins con StudioCMS.

Aprende más sobre las opciones de configuración de StudioCMS usando las páginas de Referencia de StudioCMS.