From 0c2b7722a1546eb0b0c775bdf1f33b3a9b940f80 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Thu, 27 Oct 2022 21:11:51 +0800 Subject: [PATCH] cover --- layout/_partial/main/post_list/post_card.ejs | 37 +++++++++++--------- layout/index.ejs | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/layout/_partial/main/post_list/post_card.ejs b/layout/_partial/main/post_list/post_card.ejs index 53902d8..65468ce 100755 --- a/layout/_partial/main/post_list/post_card.ejs +++ b/layout/_partial/main/post_list/post_card.ejs @@ -1,16 +1,22 @@ <% +const obj = { + image: post['cover'], + title: post['cover-title'], + cat: post['cover-cat'], + subtitle: post['cover-subtitle'] +}; function div_default() { var el = ''; el += '
'; // 封面 - if (post.cover || theme.article.auto_cover) { + if (obj.image || theme.article.auto_cover) { var cover_url; - if (post.cover != undefined) { - if (post.cover.includes('/')) { - cover_url = post.cover; + if (obj.image != undefined) { + if (obj.image.includes('/')) { + cover_url = obj.image; } else { - cover_url = 'https://source.unsplash.com/1280x640/?' + post.cover; + cover_url = 'https://source.unsplash.com/1280x640/?' + obj.image; } } else { // 自动以 tags 作为关键词搜索封面 @@ -89,23 +95,22 @@ function div_default() { function div_photo() { var el = ''; el += '
'; - el += ''; - let info = post.cover_info; - if (info) { + el += ''; + if (obj.title || obj.cat || obj.subtitle) { el += '
'; + if (obj.cat) { + el += '
' + obj.cat + '
'; } - if (info.title) { - el += '
' + info.title + '
'; + if (obj.title) { + el += '
' + obj.title + '
'; } - if (info.subtitle) { - el += '
' + info.subtitle + '
'; + if (obj.subtitle) { + el += '
' + obj.subtitle + '
'; } el += '
'; @@ -114,7 +119,7 @@ function div_photo() { return el; } function div() { - if (post.cover && post.cover.length > 0 && post.cover_info != undefined) { + if (obj.image && obj.image.length > 0 && obj.title != undefined) { return div_photo(); } return div_default(); diff --git a/layout/index.ejs b/layout/index.ejs index b2e140a..0e46860 100755 --- a/layout/index.ejs +++ b/layout/index.ejs @@ -13,7 +13,7 @@ if (page.title && page.wiki) { function layout_post_card(layout, post, content) { var el = ''; var layout = layout; - if (layout == 'post' && post.cover != undefined && post.cover_info != undefined) { + if (layout == 'post' && post['cover'] != undefined && post['cover-title'] != undefined) { layout += ' photo'; } el += '';