Skip to content

Instantly share code, notes, and snippets.

View prismicdeveloper's full-sized avatar

prismicdeveloper

View GitHub Profile
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
// You can use the Api object inside this block
console.log("References: ", Api.data.refs);
});
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
// This will fail because the token is invalid, but this is how to access a private API
}, "MC5-XXXXXXX-vRfvv70");
var previewToken = 'MC5VbDdXQmtuTTB6Z0hNWHF3.c--_vVbvv73vv73vv73vv71EA--_vS_vv73vv70T77-9Ke-_ve-_vWfvv70ebO-_ve-_ve-_vQN377-9ce-_vRfvv70';
Prismic.Api('https://lesbonneschoses.prismic.io/api', function (err, Api) {
var stPatrickRef = Api.ref("St-Patrick specials");
// Now we'll use this reference for all our calls
Api.form('everything')
.ref(stPatrickRef)
.query(Prismic.Predicates.at("document.type", "product")).submit(function (err, response) {
if (err) {
console.log(err);
done();
// Accessing image fields
var image = doc.getImage("product.image");
// Most of the time you will be using the "main" view
var url = image.main.url;
var Predicates = Prismic.Predicates;
// Date and Timestamp predicates
var dateBefore = Predicates.dateBefore("my.product.releaseDate", new Date(2014, 6, 1));
var dateAfter = Predicates.dateAfter("my.product.releaseDate", new Date(2014, 1, 1));
var dateBetween = Predicates.dateBetween("my.product.releaseDate", new Date(2014, 1, 1), new Date(2014, 6, 1));
var dayOfMonth = Predicates.dayOfMonth("my.product.releaseDate", 14);
var dayOfMonthAfter = Predicates.dayOfMonthAfter("my.product.releaseDate", 14);
var dayOfMonthBefore = Predicates.dayOfMonthBefore("my.product.releaseDate", 14);
var dayOfWeek = Predicates.dayOfWeek("my.product.releaseDate", "Tuesday");
var dayOfWeekAfter = Predicates.dayOfWeekAfter("my.product.releaseDate", "Wednesday");
var htmlSerializer = function (element, content) {
// Don't wrap images in a <p> tag
if (element.type == "image") {
return '<img src="' + element.url + '" alt="' + element.alt + '">';
}
// Add a class to hyperlinks
if (element.type == "hyperlink") {
return '<a class="some-link" href="' + element.url + '">' + content + '</a>';
}
var video = doc.get("article.video");
// Html is the code to include to embed the object, and depends on the embedded service
var html = video ? video.asHtml() : "";