sanity-template-astro-clean
sanity-template-astro-clean copied to clipboard
Clean starter template with Astro
A minimal Astro site with Sanity Studio
This starter uses Astro for the front end and Sanity to handle its content.
Featuring
- How to fetch content as data from the Sanity Content Lake
- How to render block content with Portable Text
- A Sanity Studio to create and edit content
- How to crop and render images with Sanity Image URLs
Prerequisites
- Node.js (v16.12 or later)
Getting started
Run the following commands
-
npm installto install dependencies -
npx sanity@latest init --env, this will:- ask you to select or create a Sanity project and dataset
- output a
.envfile with appropriate variables - (or use
sanity init --envif you have the CLI installed)
-
Rename the variables in the .env file:
- ~~SANITY_STUDIO_PROJECT_ID~~ → PUBLIC_SANITY_STUDIO_PROJECT_ID
- ~~SANITY_STUDIO_DATASET~~ → PUBLIC_SANITY_STUDIO_DATASET
-
npm run devto start the development server
Your Astro app should now be running on http://localhost:4321/ and Studio on http://localhost:4321/admin.
Add content
- Visit the Studio and create and publish a new
Postdocument - Visit the homepage and refresh the page to see your content rendered on the page
The schema for the Post document is defined in the /schema folder. You can add more document types to the Studio to suit your needs.
Removing TypeScript
If you do not wish to use TypeScript, we've included a remove-typescript.mjs file in the root of this repository. You can run this file with node remove-typescript.mjs to strip all types from this project. Please run this before tampering with any code to ensure that all types are properly removed.
If you intend to use TypeScript, you can safely remove the remove-typescript.mjs file.
Removing the embedded Studio
If you wish to manage and host the Studio separately, you remove the studioBasePath property for the sanity configuration in astro.config.mjs. You can also remove the following dependencies:
outputinastro.config.mjs…- …and
adapterinastro.config.mjs
- …and
react()inastro.config.mjs@sanity/visionreactreact-dom@types/react@types/react-domfrompackage.jsonschemafolder (you might want to copy this to the new Studio location)sanity.config.ts(you might want to copy this to the new Studio location)
Deployments
Feel free to deploy the App to whichever hosting provider you prefer (Vercel, Netlify, Cloudflare, etc). Remember to change the adapter in the astro.config.mjs file to match your hosting provider.
Deploying the Studio on *.sanity.studio
You can also deploy the Sanity Studio on its own URL by running npx sanity deploy, provided you have added a sanity.cli.ts configuration file:
// sanity.cli.ts
import { defineCliConfig } from "sanity/cli";
export default defineCliConfig({
api: {
projectId: "<your-project-id>",
dataset: "<your-dataset-name>",
},
});