auto_cover
This commit is contained in:
parent
d5729f50f7
commit
dbc4eaa135
|
@ -50,6 +50,8 @@ sidebar:
|
||||||
|
|
||||||
######## Article ########
|
######## Article ########
|
||||||
article:
|
article:
|
||||||
|
# 如果没有指定封面,是否根据 tags 作为关键词搜索封面?
|
||||||
|
auto_cover: true # search from https://source.unsplash.com/
|
||||||
# 如果没有指定 excerpt 和 description,将自动取多长的内容作为文章摘要?
|
# 如果没有指定 excerpt 和 description,将自动取多长的内容作为文章摘要?
|
||||||
auto_excerpt: 200
|
auto_excerpt: 200
|
||||||
# 分类颜色
|
# 分类颜色
|
||||||
|
@ -64,6 +66,8 @@ article:
|
||||||
related_posts:
|
related_posts:
|
||||||
enable: false
|
enable: false
|
||||||
max_count: 5
|
max_count: 5
|
||||||
|
auto_cover: true # 如果没有封面就根据 tags 作为关键词搜索封面,开了此项将不会自动从文章中提取首张图片作为封面了。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
######## Comments ########
|
######## Comments ########
|
||||||
|
|
|
@ -1,55 +1,84 @@
|
||||||
<%
|
<%
|
||||||
let showCat = false;
|
function layoutDiv() {
|
||||||
if (post.categories && post.categories.length > 0) {
|
var el = '';
|
||||||
showCat = true;
|
// 封面
|
||||||
|
if (post.cover || theme.article.auto_cover) {
|
||||||
|
var cover_url;
|
||||||
|
if (post.cover !== undefined) {
|
||||||
|
if (post.cover.includes('/')) {
|
||||||
|
cover_url = post.cover;
|
||||||
|
} else {
|
||||||
|
cover_url = 'https://source.unsplash.com/1280x640/?' + post.cover;
|
||||||
}
|
}
|
||||||
%>
|
} else {
|
||||||
<% if (post.cover) { %>
|
// 自动以 tags 作为关键词搜索封面
|
||||||
<div class='post-cover'>
|
if (post.tags) {
|
||||||
<img src='<%- post.cover %>'/>
|
var params = '';
|
||||||
</div>
|
post.tags.reverse().forEach((tag, i) => {
|
||||||
<% } %>
|
if (i > 0) {
|
||||||
<h2 class="post-title">
|
params += ',';
|
||||||
<%- (post.title || post.seo_title) ? (post.title || post.seo_title) : date(post.date, config.date_format) %>
|
}
|
||||||
</h2>
|
params += tag.name;
|
||||||
<div class='excerpt'>
|
});
|
||||||
<% if (post.excerpt) { %>
|
cover_url = 'https://source.unsplash.com/1280x640/?' + params;
|
||||||
<p><%- strip_html(post.excerpt) %></p>
|
} else {
|
||||||
<% } else if (post.description) { %>
|
cover_url = 'https://source.unsplash.com/random/1280x640';
|
||||||
<p><%- post.description %></p>
|
}
|
||||||
<% } else if (post.content && theme.article.auto_excerpt > 0) { %>
|
}
|
||||||
<p><%- truncate(strip_html(post.content), {length: theme.article.auto_excerpt}) %></p>
|
if (cover_url) {
|
||||||
<% } %>
|
el += '<div class="post-cover">';
|
||||||
</div>
|
el += '<img src="' + cover_url + '"/>';
|
||||||
<div class='meta cap'>
|
el += '</div>';
|
||||||
<span class='cap' id='post-meta'>
|
}
|
||||||
<%- __('meta.created') %> <time datetime='<%- date_xml(post.date) %>'><%= date(post.date, config.date_format) %></time>
|
}
|
||||||
</span>
|
|
||||||
<% if (showCat) { %>
|
// 标题
|
||||||
<% if (post.layout == 'post' && post.categories && post.categories.length > 0) { %>
|
el += '<h2 class="post-title">';
|
||||||
<%
|
el += (post.title || post.seo_title) ? (post.title || post.seo_title) : date(post.date, config.date_format);
|
||||||
|
el += '</h2>';
|
||||||
|
|
||||||
|
// 摘要
|
||||||
|
el += '<div class="excerpt">';
|
||||||
|
el += '<p>';
|
||||||
|
if (post.excerpt) {
|
||||||
|
el += strip_html(post.excerpt);
|
||||||
|
} else if (post.description) {
|
||||||
|
el += post.description;
|
||||||
|
} else if (post.content && theme.article.auto_excerpt > 0) {
|
||||||
|
el += truncate(strip_html(post.content), {length: theme.article.auto_excerpt});
|
||||||
|
}
|
||||||
|
el += '</p>';
|
||||||
|
el += '</div>';
|
||||||
|
|
||||||
|
// meta
|
||||||
|
el += '<div class="meta cap">';
|
||||||
|
// time
|
||||||
|
el += '<span class="cap" id="post-meta">';
|
||||||
|
el += __("meta.created") + ' ' + '<time datetime="' + date_xml(post.date) + '">' + date(post.date, config.date_format) + '</time>';
|
||||||
|
el += '</span>';
|
||||||
|
// cat
|
||||||
|
if (post.categories && post.categories.length > 0) {
|
||||||
|
if (post.layout === 'post' && post.categories && post.categories.length > 0) {
|
||||||
var cats = [];
|
var cats = [];
|
||||||
if (post.categories) {
|
if (post.categories) {
|
||||||
post.categories.forEach((cat, i) => {
|
post.categories.forEach((cat, i) => {
|
||||||
cats.push(cat.name);
|
cats.push(cat.name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function layoutCats() {
|
|
||||||
if (cats.length > 0) {
|
if (cats.length > 0) {
|
||||||
let cat = cats.shift();
|
let cat = cats.shift();
|
||||||
var el = '<span class="cap breadcrumb"' + category_color(cat) + '>';
|
el += '<span class="cap breadcrumb"' + category_color(cat) + '>';
|
||||||
el += cat;
|
el += cat;
|
||||||
el += '</span>';
|
el += '</span>';
|
||||||
return el;
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (post.pin) {
|
||||||
|
el += '<span class="pin"><img src="https://cdn.jsdelivr.net/gh/cdn-x/placeholder@1.0.1/badge/3279dd441df8b.svg"/></span>';
|
||||||
|
}
|
||||||
|
el += '<div>';
|
||||||
|
|
||||||
|
return el;
|
||||||
|
}
|
||||||
%>
|
%>
|
||||||
<%- layoutCats() %>
|
<%- layoutDiv() %>
|
||||||
<% } %>
|
|
||||||
<% } %>
|
|
||||||
<% if (post.pin) { %>
|
|
||||||
<span class='pin'><img src='https://cdn.jsdelivr.net/gh/cdn-x/placeholder@1.0.1/badge/3279dd441df8b.svg'/></span>
|
|
||||||
<% } %>
|
|
||||||
</div>
|
|
||||||
|
|
|
@ -35,8 +35,23 @@ hexo.extend.helper.register('popular_posts_wrapper', function(args){
|
||||||
if (p && p.length > 0) {
|
if (p && p.length > 0) {
|
||||||
p = p.data[0];
|
p = p.data[0];
|
||||||
}
|
}
|
||||||
if (p && p.cover) {
|
if (p) {
|
||||||
|
if (p.cover) {
|
||||||
|
if (p.cover.includes('/')) {
|
||||||
list.img = p.cover;
|
list.img = p.cover;
|
||||||
|
} else {
|
||||||
|
list.img = 'https://source.unsplash.com/1280x640/?' + p.cover;
|
||||||
|
}
|
||||||
|
} else if (cfg.auto_cover && p.tags.length > 0) {
|
||||||
|
var params = '';
|
||||||
|
p.tags.reverse().forEach((tag, i) => {
|
||||||
|
if (i > 0) {
|
||||||
|
params += ',';
|
||||||
|
}
|
||||||
|
params += tag.name;
|
||||||
|
});
|
||||||
|
list.img = 'https://source.unsplash.com/1280x640/?' + params;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (hexo.theme.config.default.cover) {
|
if (hexo.theme.config.default.cover) {
|
||||||
el += '<div class="img">'
|
el += '<div class="img">'
|
||||||
|
|
Loading…
Reference in New Issue