Sitemap and RSS Feeds

You can leverage your blog sitemap to maximize search engine crawling + indexation and your RSS/ATOM feeds to syndicate your content out to your social media profiles and content networks.

RSS, Atom, and Sitemap for your Blog

Butter generates RSS, Atom, and sitemap XML markup. To use these on your blog, return the generated XML from the Butter API with the proper content type headers.

Here's what an example request looks like for getting your blog's RSS feed:

curl -X GET 'https://api.buttercms.com/v2/feeds/rss?auth_token=your_api_token'

And the response:

{
  "data": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n \n  <url><loc>http://www.example.com/blog/this-is-a-blog-post</loc></url>\n \n</urlset>"
}

See our API reference for more information about fetching RSS, Atom, and sitemap XML.

Building your own Sitemap for Pages and Other Content

Unlike blog posts, your individual Pages in Butter don't have a preset schema. Additionally, although your Page content is stored in Butter, the URL patterns associated with each page are decided by your app. For example, a single user-created Page Type, e.g., Case Study, might feed into multiple URL patterns:

  • a /case-study/ route that fetches all your Butter Case Study Pages and pipes a small piece of data from each to a card on a list view page.
  • a /case-study/slug/ route that connects to a Case Study Detail view, where your app feeds data from a single Butter Case Study Page into a template about a single case study
  • a /case-study/tag/tag-slug/ route that fetches and lists all your Butter Case Study Pages that also have a reference field, Tag, whose `slug` value matches a specific `tag-slug` string

It's also possible that the sitemap Butter autogenerates for your blog might not fit your exact needs - e.g., maybe you need to also have routes for blog tags and categories, or you intend to use a URL scheme that specifies the author before the blog post slug, such as www.myblog.com/blog/author/post-slug/.

Butter can't know all the possible URL routes you're using in your app, but it does return content in a format that makes creating your own sitemap easy, as you'll see below.

How to Build a Sitemap with Dynamic Content from Butter

Most Butter users will have apps that consist of a combination of static and dynamic URL patterns.

For example, let's say you have a Page Type created in Butter, Customer Case Study, as well as two main views: a Case Study List View, which displays information from all of your Case Studies at once, and a Case Study Detail View, which displays information about a single Case Study. In your app, you have likely defined these two URL patterns differently. The List View most likely uses a static URL pattern without any dynamic variables, such as "https://YourExampleApp.com/case-studies/". Static links like these can just be included in your sitemap as-is.

However, it's likely that your Detail View is set up with something like /case-studies/<slug>, with the expected behavior being that your app dynamically fetches the appropriate Page from Butter using the slug whenever the URL is navigated to. Although there is no hard-coded list of links to pull from, building your sitemap from Butter content is still simple and quick!

Step 1: Fetch content from Butter.

There are a number of ways to fetch your content from Butter, including SDKs for C#, Dart, Go, Java, Javascript, PHP, Python, Ruby, and Swift. Or, you can fetch your content via a simple API call to the Pages API endpoint using the URL pattern: https://api.buttercms.com/v2/pages/<page_type>/?auth_token=your_api_token.

Note that you can set the page_size or limit parameters to determine how many results you want returned. You could also set any field in your page model as a parameter using fields.key, in case you want to filter by user-created fields for items like tags/categories, etc. See our API docs for more details.

If you've fetched your content from one of our SDKs, it will be returned to you in the data structure most easily consumed by that language. For API calls, your Butter content will be returned in a JSON object, like the one below: 

{
  "meta": {
    "previous_page": null,
    "next_page": null,
    "count": 2
  },
  "data": [
    {
      "slug": "case-study-1",
      "name": "Case Study One",
      "page_type": "customer_case_study",
      "created": "2019-11-12T17:23:53.109696Z",
"published": "2019-11-12T17:23:53.109696Z",       "updated": "2020-10-22T20:07:52.965850Z", "fields": { "seo": { "description": "SEO Description", }, # ... more content here } }, { "slug": "case-study-2, "name": "Case Study Two", "page_type": "customer_case_study",
"created": "2019-11-12T17:23:53.109696Z",      "published": "2019-11-12T17:23:53.109696Z", "updated": "2020-10-22T20:07:52.965850Z", "fields": { "seo": { "description": "SEO Description", },
# ... more content here } } ]

Step Two: Write Sitemap

As you can see, the json response returned includes two pieces of information you'll need for your sitemap; inside of the data array, we get a listing for each page that includes the slug of the page and the last updated datetime of the page.

You can now use this information and your dynamic URL pattern to write these entries to your sitemap XML file using a fairly simple template like the below pseudocode. (Note that api_response here refers to the json structure above.) 

<?xml version="1.0" encoding="UTF-8"?> 
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
for entry in api_response.data:   
<url>       
<loc>https://www.YourExampleApp.com/case-studies/{{ entry.slug }}</loc>
if entry.updated:
              <lastmod>{{ entry.updated }}</lastmod>
else:
<lastmod>{{ entry.published }}</lastmod>   
</url>
</urlset>

You can use a similar approach for blog posts by using the appropriate blog post API endpoint. You can even fetch all your single Pages not associated with a specific Page Type; for Single Pages, if you want to build your sitemap dynamically, we recommended adding a short text field called "canonical url" that you can then pipe into your template.

That's it! You now understand how to generate sitemaps for any part of your app!

Syndicating to Facebook

To post your live blog posts to your Facebook account automatically, you can connect your blog RSS feed to your Facebook account to do this. https://www.lifewire.com/set-up-rss-feed-on-facebook-3486528

Still have a question?

Our Customer Success team is standing by to help.