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 30
/
detail.html
93 lines (74 loc) · 3.21 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
<!DOCTYPE html>
<html>
<head>
<title>JavaScript starter</title>
<link href="css/main.css" media="all" rel="stylesheet" type="text/css">
<script src="vendor/jquery-2.0.3.min.js"></script>
<script src="scripts/fragments.js"></script>
<script src="scripts/api.js"></script>
<script src="scripts/prismic-configuration.js"></script>
<script src="scripts/prismic-helpers.js"></script>
</head>
<body class="loading">
<header>
<script type="text/template">
<a href="index.html?ref=<%= ref %>">
<h1>Your prismic.io project</h1>
</a>
</script>
</header>
<article>
<script type="text/template">
<%= doc %>
</script>
</article>
<footer>
<script type="text/template">
<% if(!$.prismic.oauth().hasPrivilegedAccess) { %>
<hr><a href="signin.html">Sign in to preview changes</a>
<% } %>
</script>
</footer>
<!-- Logic -->
<script type="text/javascript">
$(function() {
// Retrieve the prismic API
$.prismic.api().then(
function(api) {
// Retrieve the ref from the QueryString or use the Master ref
var ref = $.prismic.queryString['ref'] || api.data.master.ref;
// Links resolver
var linkResolver = $.prismic.linkResolver(api, ref);
// Retrieve the document
var id = $.prismic.queryString['id'],
slug = $.prismic.queryString['slug'];
return api.forms("everything").ref(ref).query('[[:d = at(document.id, "' + id + '")]]').submit().then(function(docs) {
var doc = docs[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, footer').render({
doc: doc,
ref: ref == api.data.master.ref ? '' : ref,
linkResolver: linkResolver
});
});
}
).then(function() {
$(document.body).removeClass('loading')
});
});
</script>
</body>
</html>