Skip to content

Instantly share code, notes, and snippets.

@jpotts
Created November 2, 2014 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpotts/73689bc751d2ada51f9e to your computer and use it in GitHub Desktop.
Save jpotts/73689bc751d2ada51f9e to your computer and use it in GitHub Desktop.
Using the Prismic.io API to fetch the doc linked to a bookmark
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);
var id = api.bookmarks['dealOfTheWeek'];
console.log('id: ' + id);
api.form('everything').ref(api.master()).query('[[:d = at(document.id, "' + id + '")]]').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('lede:');
var sections = entry.fragments['article.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('--------');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment