This page covers how to use Prismic + Gatsby Blog Starter with Prismic.
- Demo: Open live demo
- Learn more about Prismic and Gatsby: Prismic Gatsby Documentation
To start a new project using this starter, run the following command in your terminal:
npx prismic-cli@latest theme --theme-url https://github.com/prismicio-community/gatsby-starter-prismic-blog --conf sm.json
The command will do the following:
- Start a new Gatsby project using this starter.
- Ask you to log in to Prismic or create an account.
- Create a new Prismic content repository with sample content.
When you're ready to start your project, run the following command:
npm run dev
To learn more about working with Prismic, see the Prismic docs.
To get started after creating your new project, go to prismic.io/dashboard, click on the repository for this website, and start editing.
To create a new article, click on the green pencil icon in the top-right corner of the screen, then select Article. After adding some content, click Save and then Publish.
Your article will appear in the homepage feed.
To create a page, click on the green pencil icon, then select Page.
Your new page will be accessible by its URL, but it won't appear on the website automatically. To let users discover it, add it to the navigation.
To add a page to your navigation menu, go to the document list and open the Navigation document. In the Links group, click Add a new element in Links. Select the page to add and fill in a label.
In your repository, go to Settings > Previews. Under Create a New Preview, fill in the three fields:
- a name (like Development or Production)
- the domain where your app is running (like http://localhost:3000 or https://www.yoursite.com)
/api/preview
for the Link Resolver
Now, go to a draft document and click the eye icon in the top-right corner.
To learn more about how to configure previews, read Preview Drafts in Gatsby in the Prismic documentation.
This website is preconfigured with Prismic. It has three Prismic packages installed:
@prismicio/react
provides React components for rendering content from Prismicgatsby-source-prismic
pulls content from Prismic into your Gatsby appgatsby-plugin-prismic-previews
provides Prismic preview support
These packages are already integrated and employed in this app. Take a look at the code to see how they're used.
There are two steps to rendering content from Prismic in your Gatsby project:
- Fetch content from the Prismic API using
@prismicio/client
. - Template the content using components from
@prismicio/react
.
Here are some of the files in your project that you can edit:
gatsby-config.js
- This file includes configuration for your Gatsby app and how it pulls in content from Prismic.src/pages/index.js
- This is the app homepage.src/pages/{PrismicPage.url}.js
- This is the page component, which queries and renders a page document from your Prismic repository based on the UID.src/pages/{PrismicArticle.url}.js
- This is the article page component, which queries and renders an article document from your Prismic repository based on the UID.src/api/contact.js
- This is the API endpoint for your contact form. To use the contact form, send a POST request to a back end from this endpoint.src/api/sign-up.js
- This is the API endpoint for your newsletter form. To allow signups, send a POST request to a newsletter service like Mailchimp.src/slices/\*/index.js
- Each Slice in your project has an index.js file that renders the Slice component. Edit this file to customize your Slices.
These are important files that you should leave as-is:
src/slices/
- This directory contains Slice components, which are generated programmatically by Slice Machine. To customize a Slice template, you can edit the Slice's index.js file. To add Slices, delete Slices, or edit Slice models, use Slice Machine (more info below).
Learn more about how to edit your components with Query Data with Gatsby and Template Content in Gatsby.
Styling in this project is implemented with Tailwind CSS. See the Tailwind docs for more info.
To put your project online, see Deploy your Gatsby App.
This project includes an application called Slice Machine, which generates models for your Custom Types and Slices. Slice Machine stores the models locally in your codebase, so you can save and version them. It also syncs your models to Prismic. To learn how to use Slice Machine, read What is Slice Machine?.
If you change or add to your Custom Types, you'll need to update your route handling to match. To learn how to do that, read Define Routes with Gatsby.
For the official Prismic documentation, see Prismic's guide for Gatsby or the technical references for the installed Prismic packages.