Created
November 2, 2014 03:27
-
-
Save jpotts/23c44c15f44cc4429c38 to your computer and use it in GitHub Desktop.
Use the prismic.io API to fetch blog posts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Prismic = require('prismic.io').Prismic; | |
var testRepo = 'https://your-repo.prismic.io/api'; | |
Prismic.Api(testRepo, function(err, api) { | |
if (err) console.log(err); | |
api.form('blogPosts').ref(api.master()).submit(function(err, docs) { | |
if (err) console.log(err); | |
for (var i = 0; i < docs.results.length; i++) { | |
var entry = docs.results[i]; | |
console.log('id: ' + entry.id); | |
console.log('lede:'); | |
var sections = entry.fragments['blog.shortlede'].value; | |
// assumes text but could be other types of sections | |
for (var j = 0; j < sections.length; j++) { | |
console.log(sections[j].text); | |
} | |
console.log('post:'); | |
var postSections = entry.fragments['blog.body'].value; | |
for (var j = 0; j < postSections.length; j++) { | |
console.log(postSections[j].text); | |
} | |
console.log('--------') | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment