forked from shuding/innsbruck-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththumbnail.js
48 lines (44 loc) · 1.26 KB
/
thumbnail.js
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
/**
* Created by shuding on 5/23/16.
*/
module.exports = {
db: null,
init: _db => {
this.db = _db;
},
render: (template, options) => {
let context = {};
if (['post-new', 'post-edit'].includes(template)) {
let thumbnail = (options.post && options.post.plugin ? options.post.plugin.thumbnail || '' : '');
context.editorArticleBottom = `
<p>Thumbnail (^upload): <input type="text" name="plugin.thumbnail" placeholder="/static/xxx.jpg" value="${thumbnail}" style="width: inherit"></p>
`;
}
if (template == 'posts') {
context.head = `
<style>
.thumbnail {
width: 100%;
height: 10vw;
max-height: 120px;
min-height: 80px;
background-size: cover;
background-position: center center;
cursor: pointer;
}
</style>
`;
context.postLiTitleBottom = post => {
if (post.plugin && post.plugin.thumbnail) {
let thumbnail = post.plugin.thumbnail;
if (thumbnail) {
return `<a href="/post/${post.link}" style="flex-basis: 100%"><div class="thumbnail" style="background-image: url('${thumbnail}')"></div></a>`;
}
}
return '';
}
}
return context;
}
};