Too busy to start from scratch, but excited to start learning how to use an API-based CMS? Get a blog up and running in minutes. Modify and adapt it to your liking, it's all yours!
For this project, we provide you with all the source code you need to get your blog up and running. We will also walk you through setting up a new Prismic project from your terminal using the 'prismic-cli' tool, which will not only copy all the required code for you to get started right away but also setup the required content repository for you in a few simple steps.
Setting up a Prismic project from a sample
We're going to kickstart our project by using the command line tool
prismic theme which takes care of every step of your initial setup in a streamlined manner.
The first step will be to install the 'prismic-cli' package. Launch a terminal instance, from where you will run the command to globally install the package.
npm install -g prismic-cli
Once it's been installed, you just need to navigate to where you want to create your new project folder and run the following command. This will create a new Prismic content repository, setup the custom types, and install the project code:
prismic theme --theme-url https://github.com/prismicio/nextjs-blog
(MAKE SURE YOU'RE USING THE LATEST VERSION OF THE CLI)
The interface will guide you through creating a local folder for your project and creating a new Prismic account or logging into your existing account if you already have one.
Navigate to the folder you have just created, and open
Confirm that the name you have chosen for your content repository has been setup as the API endpoint that the web application will use to fetch the content you create in Prismic.
Write some content
Visit the repository you have just created in your browser. It will show in your Prismic Dashboard, just like any other repositories you create. Select your master language and it's time to create some content! Start by filling in your photo, your name, and a headline for your blog's home.
Go to "Content" and hit "New", choose the Blog's home type and fill it with your own content. Save and publish!
Now, write a few blog posts. Make sure to fill the mandatory UID field that is used for your post's URL. Save and publish!
Run the blog
Now that we have some content to show off, let's check back on the code that will run your blog. Open your project folder once more in the terminal and run the development command.
npm run dev
This will launch a local development server at http://localhost:3000.
Getting ready to deploy to a serverless platform
If you want other people to view your new blog site, then you need to publish it on a public platform. For this purpose, we will be using Now, by the same development team that works on Next.js, so it's not surprising that they're made for each other.
We'll be taking advantage of the serverless feature that deploying Next.js apps in Now provides.
But why just read about it, when we can follow a couple of steps to actually try it out. You can follow the official recommendation and install Now globally with Now Desktop, or just use locally the Now package we have included with this project. No need to be concerned, whichever method you use, the end result will be the same for your site.
Deploy and go live!
You only have to navigate to your project's folder in the terminal and run the command
now if you've installed Now globally, or the following command if you want to use the included package instead.
npm run deploy
Follow the steps to either login or sign up to a Now account. The build process will begin now, with the configuration files and custom routing having been already been set up for you. After your project has been built on the cloud, a web address will be assigned automatically and copied to your clipboard.
That's it! You can now view your new blog from any browser.
Customize to your liking
You should easily find what to modify in the code to customize the blog: just edit the stylesheets and the templates to fit your design! And if you're wondering about how the web app works or wish to learn more about expanding this project into a bigger, more personal project, feel free to contact us and we'll be happy to help you in getting your Next.js project with Prismic off the ground.