Sample Blog with API-based CMS

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. After you set up your content repository we will show you how to configure the code and see your content in action.

Start a content repository

A content repository is where you define, edit and publish content.

Create Repository

Create a "blog's home" custom type

Custom types allow you to define and configure fields for your content.

This blog's homepage contains a title, a description and an image. Let's create a custom type with the corresponding fields. We will only need one instance for the homepage, so we will set it up as a Single Type.

In the repository you've just created, go to Custom Types, create a new type, select Single Type, and give it a name of Bloghome. prismic.io will automatically assign it the API ID of "bloghome". Once created, paste the following JSON into the type editor. Save.

Copy
      {
  "Main" : {
    "headline" : {
      "type" : "StructuredText",
      "config" : {
        "placeholder" : "Main title...",
        "single" : "heading1"
      }
    },
    "description" : {
      "type" : "StructuredText",
      "config" : {
        "placeholder" : "Sub-title",
        "single" : "heading2"
      }
    },
    "image" : {
      "type" : "Image"
    }
  }
}
    

Create a "blog post" custom type

In the designed blog post layout, we give the possibility to alternate paragraphs, quotes and images. Images can be displayed in full width with a nice overlay, or centered in the body with a caption below.

We use content slices to define this layout in the custom type. As an author you'll be able to freely compose your post's body by alternating those components.

We will need to be able to create more than one blog post, so this will fall into the category of repeatable type. Create a new type, select Repeatable Type, and give it the name Post. prismic.io will automatically assign it the API ID of "page". Once created, paste the following JSON into the type editor. Save.

Copy
      {
  "Blog Post" : {
    "uid" : {
      "type" : "UID",
      "config" : {
        "placeholder" : "unique-identifier-for-blog-post-url"
      }
    },
    "title": {
      "type": "Text",
      "config": {
        "label": "Title"
      }
    },
    "date" : {
      "fieldset" : "Post properties",
      "type" : "Date",
      "config" : {
        "label" : "Post date"
      }
    },
    "body" : {
      "fieldset" : "Post content",
      "type" : "Slices",
      "config" : {
        "labels" : {
          "image-with-caption" : [ {
            "name" : "emphasized",
            "display" : "Emphasized"
          }, {
            "name" : "image-full-width",
            "display" : "Full"
          } ]
        },
        "choices" : {
          "text" : {
            "type" : "StructuredText",
            "fieldset" : "Text",
            "config" : {
              "multi" : "paragraph, heading2, heading3, strong, em, hyperlink, ulist, list-item",
              "placeholder" : "Post text..."
            }
          },
          "quote" : {
            "type" : "StructuredText",
            "fieldset" : "Quote",
            "config" : {
              "placeholder" : "Post quote...",
              "single" : "paragraph"
            }
          },
          "image-with-caption" : {
            "type" : "Group",
            "fieldset" : "Post image and caption",
            "config" : {
              "fields" : {
                "illustration" : {
                  "type" : "Image",
                  "config" : {
                    "constraint" : {
                      "width" : 640
                    }
                  }
                },
                "caption" : {
                  "type" : "StructuredText",
                  "config" : {
                    "single" : "heading3",
                    "placeholder" : "Image caption..."
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
    

Write 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

Time to see thinks working! First, dowload the blog source code.

Download the Node.js Blog Code Download the PHP Blog Code

Point it to your content repository API

Let's modify the link in our configuration file to point to our repository's API endpoint.

Copy
      // In prismic-configuration.js
apiEndpoint: "http://your-repo-name.prismic.io/api",
    
Copy
      // In config.php
define("PRISMIC_URL", "https://your-repo-name.prismic.io/api");
    

Fire up a terminal (command prompt or similar on Windows), point it to your project location and run!

Copy
      npm install
npm install -g nodemon
nodemon
    
Copy
      composer install
./serve.sh
    

Deploy & go live!

An easy way to deploy your Node.js application is to use Heroku. Just follow these few simple steps once you have successfully signed up and installed the Heroku toolbelt:

Create a file with the name Procfile file at your application root. Put the following code in the Procfile file:

Copy
      web: node app.js
    
Copy
      web: vendor/bin/heroku-php-apache2 public
    

Create a new Heroku application

Copy
      $ heroku create
    

Initialize a new Git repository

Copy
      $ git init
$ heroku git:remote -a your-heroku-app-name
    

Commit your code to the Git repository and deploy it to Heroku

Copy
      $ git add .
$ git commit -am "make it better"
$ git push heroku master
    

Ensure you have at least one node running

Copy
      $ heroku ps:scale web=1
    

You can now browse your application online

Copy
      $ heroku open
    

Customize to your likings

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!

About prismic.io

prismic.io is content management made easy and fast with publishing benefits:

- Full versioning of your content
- A nice rich editor to create and edit your content
- Collaboration with other users you choose to add to your repository
- Performance and scalability for your content using a Content Delivery Network around the world