forked from TryGhost/London
-
Notifications
You must be signed in to change notification settings - Fork 0
/
book.hbs
181 lines (170 loc) · 9.14 KB
/
book.hbs
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
{{!< default}}
{{#page}}
<article class="post-content book {{page_class}} no-image{{!--
--}}{{#has tag="#preorder"}} preorder{{else has tag="#comingsoon"}} comingsoon{{/has}}">
<header class="post-content-header">
<h2 class="post-content-title">{{title}}</h2>
</header>
<div class="post-content-body">
<div class="row">
<div class="col info">
{{content}}
<hr />
<p id="book-details" style="font-size:.75em;">
<b>Publisher:</b>
{{#has tag="#sgp"}}
Savant-Garde Press
{{else}}
Jetpack Wanderer Press
{{/has}}<br />
<b>Available in:</b>
{{#has tag="#paperback"}}
Paperback{{#has tag="#ebook, #audiobook"}}, {{/has}}
{{/has}}
{{#has tag="#ebook"}}
eBook{{#has tag="#audiobook"}}, {{/has}}
{{/has}}
{{#has tag="#audiobook"}}
Audiobook
{{/has}}<br />
<b id="pubDateLabel">{{#has tag="#preorder"}}
Pre-Order Now
{{else has tag="#comingsoon"}}
Coming Soon
{{else}}
Publish Date:
{{/has}}
</b> <span id="pubDate">
{{#has tag="#comingsoon, #preorder"}}
{{else}}
{{date published_at format="MMMM YYYY"}}
{{/has}}
</span>
</p>
</div>
<div class="col-4 links">
<div class="book-container-3d">
<div class="book">
<img alt="{{title}} by Matthew Rasnake" src="{{img_url feature_image size="book-cover"}}" />
</div>
</div>
<h4 class="price">${{date published_at format="H"}}.{{#has tag="#paperback"}}99{{else}}95{{/has}}</h4>
<h6 class="direct">Direct From the Author</h6>
<ul class="direct actions fit stacked{{#has tag="#outofstock"}} outofstock{{/has}}">
</ul>
<h6 class="indirect">Elsewhere</h6>
<ul class="indirect actions fit stacked">
</ul>
<h6 class="book-love">Book Love</h6>
<ul class="book-love actions special">
</ul>
</div>
</div>
</div>
<div class="modal-content overdrive">
<p><em>{{title}}</em> may be available to borrow from your local library via the digital lending service OverDrive.</p>
<p class="center"><a href="https://www.overdrive.com/" id="odLink">Check Availability »</a></p>
<p>If not already available, search for <em>{{title}}</em> in <a href="https://www.overdrive.com/libraries">your local library's digital collection</a> and recommend it!</p>
<p>Though it can take time to become available, OverDrive and your local library are great ways to read my stories for free, and I think it'll be worth your wait!</p>
</div>
</article>
{{/page}}
{{!-- The #contentFor helper here will send everything inside it up to the matching #block helper found in default.hbs --}}
{{#contentFor "scripts"}}
<script data-swup-reload-script>
var images = document.querySelectorAll('.kg-gallery-image img');
images.forEach(function (image) {
var container = image.closest('.kg-gallery-image');
var width = image.attributes.width.value;
var height = image.attributes.height.value;
var ratio = width / height;
container.style.flex = ratio + ' 1 0%';
})
// Format these so we're just working with the DATE, not the TIME
var preOrderDate = Date.parse('{{date published_at format="LL"}}');
var pubDate = preOrderDate;
var today = Date.parse(new Date().toDateString());
// We assume the post is published on the book's publication date
var comingsoon, preorder = false;
$(document).ready(
function() {
// The book's publication date
if (!!bookData.pubDate) {
pubDate = Date.parse(bookData.pubDate)
$('#pubDate').html(new Intl.DateTimeFormat(undefined, {month: 'long', year: 'numeric'}).format(pubDate));
}
// The book's pre-order date
if (!!bookData.preOrderDate) {
preOrderDate = Date.parse(bookData.preOrderDate)
}
// The book hasn't been published yet
if (today < pubDate) {
// Is it available for pre-order?
preorder = (preOrderDate <= today);
// If not, it's coming soon
comingsoon = !preorder
var pubDateLabel = (preorder) ? "Pre-Order Until" : ((comingsoon) ? "Coming" : null);
if (!!pubDateLabel) {
$('#pubDateLabel').html(`${pubDateLabel}:`);
}
}
// The book's primary retail price
if (!!bookData.price) {
$('div.links').find('.price').html('$'+bookData.price);
}
// The book's primary ISBN
if (!!bookData.isbn) {
$('#book-details').append('<br /><b>ISBN:</b> ' + bookData.isbn);
}
if (comingsoon) {
$('h6.direct').html("Coming Soon!").show();
} else {
// Show BUY buttons if book is available for sale or pre-order
if (!!bookData.payhip) {
$('h6.direct').show();
const $directActions = $('ul.actions.direct');
if (!!bookData.payhip.print) {
if ($directActions.hasClass('outofstock')) {
$directActions.append('<li><a href="https://matthewrasnake.com/waitlist/'+bookData.isbn.replace(/\-/g,'')+'" class="button primary fit">Join Waitlist!</a></li>');
} else {
$directActions.append('<li><a href="https://payhip.com/b/'+bookData.payhip.print+'" class="button primary fit payhip-buy-button" data-theme="none" data-product="'+bookData.payhip.print+'">'+(preorder ? 'Preorder' : 'Buy')+' Print</a></li>');
}
}
if (!!bookData.payhip.ebook) {
$directActions.append('<li><a href="https://payhip.com/b/'+bookData.payhip.ebook+'" class="button primary fit payhip-buy-button" data-theme="none" data-product="'+bookData.payhip.ebook+'">'+(preorder ? 'Preorder' : 'Buy')+' eBook</a></li>');
}
$('body').append('<scr'+'ipt type="text/javascript" src="https://payhip.com/payhip.js?v=24u69003"></scr'+'ipt>');
}
if (!!bookData.bookshop || !!bookData.overdrive || !!bookData.b2r) {
$('h6.indirect').show();
const $indirectActions = $('ul.actions.indirect');
if (!!bookData.bookshop) {
$indirectActions.append('<li><a href="https://bookshop.org/a/16912/'+bookData.bookshop+'" class="button fit" title="Find your local bookshop on bookshop.org">Your Local Bookshop</a></li>');
}
if (!!bookData.overdrive) {
$indirectActions
.append('<li><a href="https://www.overdrive.com/media/'+bookData.overdrive+'" class="button fit overdrive" title="Borrow from your local library">Your Local Library</a></li>')
.find('.button.overdrive').click(function(e) {
e.preventDefault();
$('#odLink').attr("href",this.href);
showModal('Library Availability', $('div.modal-content.overdrive').html());
})
}
if (!!bookData.b2r) {
$indirectActions.append('<li><a href="https://books2read.com/'+bookData.b2r+'" class="button fit" title="Choose your favorite online retailer.">The Big Guys</a></li>');
}
}
if (!!bookData.goodreads || !!bookData.bookBub) {
$('h6.book-love').show();
if (!!bookData.goodreads) {
$('ul.actions.book-love').append('<li><a href="https://www.goodreads.com/book/show/'+bookData.goodreads+'" target="_blank"><img src="https://s.gr-assets.com/assets/badge/goodreads-badge-add-plus-71eae69ca0307d077df66a58ec068898.png" height="41" /></a></li>');
}
if (!!bookData.bookBub) {
$('ul.actions.book-love').append('<li><a href="https://www.bookbub.com/books/'+bookData.bookBub+'"><img src="https://images.matthewrasnake.com/logo_BookBub.jpg" height="41" /></a></li>');
}
}
}
}
)
</script>
{{/contentFor}}