This repository has been archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
detail.html
94 lines (75 loc) · 3.12 KB
/
detail.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<!DOCTYPE html>
<html>
<head>
<title>Your prismic.io project</title>
<script src="js/vendor/jquery-2.1.1.min.js"></script>
<script src="js/vendor/prismic.io-1.0.28.min.js"></script>
<script src="js/prismic-configuration.js"></script>
<script src="js/prismic-helpers.js"></script>
<script src="js/prismic-templates.js"></script>
</head>
<body class="loading">
<header>
<script type="text/template">
<a href="index.html?<%= ctx.maybeRefParam %>">
<h1>Your prismic.io project</h1>
</a>
</script>
</header>
<article>
<script type="text/template">
<%= doc.asHtml(ctx) %>
</script>
</article>
<aside>
<script type="text/template">
<% if(doc.linkedDocuments.length > 0) { %>
<hr>
<h2>Linked documents:</h2>
<ul>
<% for(var i=0; i<doc.linkedDocuments.length; i++) { %>
<li>
<a href="detail.html?id=<%= doc.linkedDocuments[i].id %>&slug=<%= doc.linkedDocuments[i].slug %>">
<%= doc.linkedDocuments[i].slug %>
</a>
</li>
<% } %>
</ul>
<% } %>
</script>
</aside>
<script src="//static.cdn.prismic.io/prismic.js"></script>
<!-- Logic -->
<script type="text/javascript">
$(function() {
Helpers.withPrismic(function(ctx) {
// Retrieve the document
var id = Helpers.queryString['id'],
slug = Helpers.queryString['slug'];
ctx.api.form("everything").ref(ctx.ref).query('[[:d = at(document.id, "' + id + '")]]').submit(function(err, docs) {
if (err) { Configuration.onPrismicError(err); return; }
var doc = docs.results[0];
// If there is no documents for this id
if(!doc) {
document.location = 'notfound.html';
}
// If the slug doesn't match
if(doc.slug != slug) {
// If this is an old valid slug, redirect
if(doc.slugs.indexOf(slug) > -1) {
document.location = 'detail.html?id=' + doc.id + '&slug=' + doc.slug + '&ref=' + ref;
} else {
document.location = 'notfound.html';
}
}
// Feed the templates
$('header, article, aside, footer').render({
doc: doc,
ctx: ctx
});
});
});
});
</script>
</body>
</html>