forked from zutrinken/attila
-
Notifications
You must be signed in to change notification settings - Fork 1
/
page-douban.hbs
222 lines (210 loc) · 9.36 KB
/
page-douban.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
{{!< default}} {{! Everything inside the #post tags pulls data from the post }} {{#post}} <header class="post-header">
<div class="inner">
<h1 class="post-title">{{{title}}}</h1>
</div>
</header>
<main class="content" role="main">
<article class="{{post_class}}" >
<div class="inner">
<section class="post-content">
{{content}}
<style>
.gFnzgG,.gFnzgG *{box-sizing:border-box}
.fIuTG{display:flex;flex-wrap:wrap;margin:0 -2%;background:0 0;line-height:100%;justify-content: center;}
.dfdORB{width:150px;margin:0 2% 30px;padding:0;font-size:15px}
.dfdORB a{text-decoration:none}
.kMthTr{margin-top:12px;line-height:1.3;max-height:2.6rem;overflow:hidden}
.eysHZq{display:flex;-webkit-box-align:center;align-items:center;margin-top:5px;min-height:16px;line-height:1;-webkit-box-align: center;}
.HPRth{position:relative;min-height:87px;overflow:hidden;color:transparent;width: 150px;height: 230px;}
.HPRth:hover{box-shadow:rgb(48 55 66 / 30%) 0 1rem 2.1rem}
.jcTaHb{display:flex;-webkit-box-align:center;align-items:center}
.lhtmRw{margin-right:1px;width:12px;height:12px;color:#fccd59}
.gaztka{margin-right:1px;width:12px;height:12px;color:#eee}
.iibjPt{margin-left:5px;color:#555;font-size:14px}
.jvCTkj{margin-bottom:10px}
.kEoOHR{display:inline-block;margin-right:15px;text-decoration:none;color:#157efb}
.dvtjjf{display:inline-block;color:#555;text-decoration:none;padding:0 5px}
.dvtjjf.active{background:rgba(85,85,85,.1)}
.hide{display:none}
.sort-by{text-align:right;margin-top:-15px}
.sort-by-item{margin-left:10px;padding:0 5px;line-height:20px;text-decoration: none;color: var(--color-content-secondary);}
.sort-by-item.active{background:rgba(85,85,85,.1)}
.sort-by-item svg{margin-right:5px}
.sc-hKFxyN img{max-width:100%!important;height:100%!important;display:block!important;vertical-align:middle!important;margin: 0;padding: 0;}
.lazyload-wrapper {height: 100%;}
@media(min-width:1024px){
.lg\:col-span-6{grid-column:span 6/span 6!important}
.lg\:col-start-2{grid-column-start:2!important}
}
@media (max-width:550px){
.jcTaHb,.sc-bdnxRM{display:none}
}
</style>
<script type="text/javascript">
function search(e) {
document.querySelectorAll('.dfdORB').forEach(item => item.classList.add('hide'));
document.querySelector(`.dvtjjf.active[data-search="${e.target.dataset.search}"]`)?.classList.remove('active');
if(e.target.dataset.value) {
e.target.classList.add('active');
}
const searchItems = document.querySelectorAll('.dvtjjf.active');
const attributes = Array.from(searchItems, searchItem => {
const property = `data-${searchItem.dataset.search}`;
const logic = searchItem.dataset.method === 'contain' ? '*' : '^';
const value = searchItem.dataset.method === 'contain' ? `${searchItem.dataset.value}` : searchItem.dataset.value;
return `[${property}${logic}='${value}']`;
});
const selector = `.dfdORB${attributes.join('')}`;
document.querySelectorAll(selector).forEach(item => item.classList.remove('hide'));
}
window.addEventListener('click', function(e) {
if(e.target.classList.contains('sc-gtsrHT')) {
e.preventDefault();
search(e);
}
});
function sort(e) {
const sortBy = e.target.dataset.order;
const style = document.createElement('style');
style.classList.add('sort-order-style');
document.querySelector('style.sort-order-style')?.remove();
document.querySelector('.sort-by-item.active')?.classList.remove('active');
e.target.classList.add('active');
if(sortBy === 'rating') {
const movies = Array.from(document.querySelectorAll('.dfdORB'));
movies.sort((movieA, movieB) => {
const ratingA = parseFloat(movieA.dataset.rating) || 0;
const ratingB = parseFloat(movieB.dataset.rating) || 0;
if(ratingA === ratingB) {
return 0;
}
return ratingA > ratingB ? -1 : 1;
});
const stylesheet = movies.map((movie, idx) => `.dfdORB[data-rating="${movie.dataset.rating}"] { order: ${idx}; }`).join('\r\n');
style.innerHTML = stylesheet;
document.body.appendChild(style);
}
}
window.addEventListener('click', function(e) {
if(e.target.classList.contains('sort-by-item')) {
e.preventDefault();
sort(e);
}
});
</script>
<div class="lg:col-start-2 lg:col-span-6">
<div class="sc-ksluID gFnzgG">
<div class="sc-bdnxRM genres">
</div>
<div class="sc-bdnxRM fyear">
</div>
<div class="sc-bdnxRM">
<a href="javascript:void 0;" class="sc-gtsrHT kEoOHR" data-search="star" data-method="equal" data-value="">全部</a>
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="star" data-method="equal" data-value="5">五星</a>
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="star" data-method="equal" data-value="4">四星</a>
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="star" data-method="equal" data-value="3">三星</a>
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="star" data-method="equal" data-value="2">二星</a>
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="star" data-method="equal" data-value="1">一星</a>
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="star" data-method="equal" data-value="0">零星</a>
</div>
<div class="jvCTkj sort-by">
<a href="javascript:void 0;" class="sort-by-item active" data-order="time">时间排序</a>
<a href="javascript:void 0;" class="sort-by-item" data-order="rating">评分排序</a>
</div>
<div class="sc-dIsUp fIuTG movies">
</div>
</div>
</div>
</section>
</div>
</article>
</main>
{{/post}}
<script type="text/x-tmpl" id="tmpl-movies">
{% for (var i=0; i<o.movies.length; i++) { %}
<div
class="sc-gKAaRy dfdORB hint--top hint--medium"
data-year="{%= typeof(o.movies[i].pubdate) == "undefined" ? "":o.movies[i].pubdate.substring(0,4) %}"
data-star="{%= o.movies[i].star %}"
data-rating="{%= o.movies[i].rating %}"
data-genres="{%= o.movies[i].genres %}"
aria-label="{%= o.movies[i].comment %}"
>
<a rel="link" href="{%= o.movies[i].url %}" target="_blank">
<div class="sc-hKFxyN HPRth">
<div class="lazyload-wrapper ">
<img class="avatar" src="{%= o.movies[i].poster %}" referrer-policy="no-referrer" loading="lazy" alt="{%= o.movies[i].title %}" width="150" height="220">
</div>
</div>
<div class="sc-iCoGMd kMthTr">{%= o.movies[i].title %}</div>
<div class="sc-fujyAs eysHZq">
<span class="sc-jSFjdj jcTaHb">
{% for (var b=0; b<5; b++) { %}
<svg viewBox="0 0 24 24" width="24" height="24" class="sc-dlnjwi {% if (b < o.movies[i].star) { %} lhtmRw {% }else{ %} gaztka {% } %} ">
<path fill="none" d="M0 0h24v24H0z"></path>
<path fill="currentColor" d="M12 18.26l-7.053 3.948 1.575-7.928L.587 8.792l8.027-.952L12 .5l3.386 7.34 8.027.952-5.935 5.488 1.575 7.928z"></path>
</svg>
{% } %}
</span>
<span class="sc-pNWdM iibjPt">{%= o.movies[i].rating %}</span>
</div>
</a>
</div>
{% } %}
</script>
<script type="text/x-tmpl" id="tmpl-genres">
<a href="javascript:void 0;" class="sc-gtsrHT kEoOHR" data-search="genres" data-method="contain" data-value="">全部</a>
{% for (var i=0; i<o.length; i++) { %}
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="genres" data-method="contain" data-value="{%= o[i] %}">{%= o[i] %}</a>
{% } %}
</script>
<script type="text/x-tmpl" id="tmpl-fyear">
<a href="javascript:void 0;" class="sc-gtsrHT kEoOHR" data-search="year" data-method="equal" data-value="">全部</a>
{% for (var i=0; i<o.length; i++) { %}
<a href="javascript:void 0;" class="sc-gtsrHT dvtjjf" data-search="year" data-method="equal" data-value="{%= o[i] %}">{%= o[i] %}</a>
{% } %}
</script>
{{#contentFor "scripts"}}
{{#if @custom.douban_movie }}
<script>
$(document).ready(function () {
var temp = { movies : [] }
$.getJSON('{{ @custom.douban_movie }}',function(r){
$(r).each(function(){
temp.movies.push({id : this.id,
title : this.subject.title,
subtitle : this.subject.card_subtitle,
poster: this.subject.pic.large,
pubdate: this.subject.pubdate[0],
url: this.subject.url,
rating: this.subject.rating.value,
genres: this.subject.genres.join(','),
star: this.subject.rating.star_count,
comment: this.comment,
tags: this.tags.join(','),
star_time: this.create_time
})
})
$('.movies').html(tmpl('tmpl-movies', temp))
var gtemp = [];
var gyear = [];
$(temp.movies).each(function(){
t = this.genres.split(',');
if(t.length > 0){
$(t).each(function(i,d){
if(gtemp.indexOf(d) == -1){ gtemp.push(d) }
});
}else{
gtemp.push(this.genres) }
var tyear = this.subtitle.substring(0,4);
if(gyear.indexOf(tyear) == -1 ){
gyear.push(tyear)
}
});
$('.genres').html(tmpl('tmpl-genres', gtemp))
$('.fyear').html(tmpl('tmpl-fyear', gyear.sort(function(a,b){ return b-a } )))
})
});
</script>
{{/if }}
{{/contentFor}}