[feat] related posts in first category
This commit is contained in:
parent
99a68840b4
commit
73fa403a24
|
@ -40,7 +40,7 @@ sidebar:
|
|||
others: search, recent, timeline # for 404 and ...
|
||||
#### 手动创建的页面 ####
|
||||
# 文章内页
|
||||
post: search_blog, toc, ghrepo, ghissues # for pages using 'layout:post'
|
||||
post: search_blog, toc, related, ghrepo, ghissues # for pages using 'layout:post'
|
||||
# 文档内页
|
||||
wiki: search, toc, ghissues, related # for pages using 'layout:wiki'
|
||||
# 其它 layout:page 的页面
|
||||
|
|
|
@ -24,6 +24,7 @@ meta:
|
|||
comment_title: Join the discussion
|
||||
back_to_top: Back to top
|
||||
more: 'More %s'
|
||||
posts_in_category: 'Category: %s'
|
||||
created_author: '%s posted on'
|
||||
created: 'Posted on'
|
||||
updated: 'Updated on'
|
||||
|
|
|
@ -24,6 +24,7 @@ meta:
|
|||
comment_title: 快来参与讨论吧
|
||||
back_to_top: 回到顶部
|
||||
more: '更多「%s」'
|
||||
posts_in_category: '专栏:%s'
|
||||
created_author: 本文由 %s 发布于
|
||||
created: 发布于
|
||||
updated: 更新于
|
||||
|
|
|
@ -24,6 +24,7 @@ meta:
|
|||
comment_title: 參與討論
|
||||
back_to_top: 回到頁首
|
||||
more: '更多「%s」'
|
||||
posts_in_category: '專欄:%s'
|
||||
created_author: 本文由 %s 發布於
|
||||
created: 發布於
|
||||
updated: 更新於
|
||||
|
|
|
@ -26,7 +26,7 @@ function generate_description() {
|
|||
if (theme.open_graph && theme.open_graph.enable) {
|
||||
return '';
|
||||
}
|
||||
if (page.layout == 'wiki' && page.wiki) {
|
||||
if (page.wiki) {
|
||||
let proj = theme.wiki.tree[page.wiki];
|
||||
if (proj && proj.description) {
|
||||
return '<meta name="description" content="' + proj.description + '">';
|
||||
|
|
|
@ -38,11 +38,7 @@ function layoutDiv() {
|
|||
}
|
||||
|
||||
var license = ''
|
||||
if (page.layout == 'post') {
|
||||
if (theme.article.license && (page.license != false)) {
|
||||
license = page.license || theme.article.license
|
||||
}
|
||||
} else if (page.layout == 'wiki' && page.wiki) {
|
||||
if (page.wiki) {
|
||||
let proj = theme.wiki.tree[page.wiki]
|
||||
if (page.license != null) {
|
||||
license = page.license || theme.article.license
|
||||
|
@ -53,6 +49,10 @@ function layoutDiv() {
|
|||
license = proj.license
|
||||
}
|
||||
}
|
||||
} else if (page.layout == 'post') {
|
||||
if (theme.article.license && (page.license != false)) {
|
||||
license = page.license || theme.article.license
|
||||
}
|
||||
}
|
||||
if (license.length > 0) {
|
||||
var author = null
|
||||
|
@ -75,15 +75,15 @@ function layoutDiv() {
|
|||
}
|
||||
|
||||
var showSharePlugin = false
|
||||
if (page.layout == 'post') {
|
||||
showSharePlugin = page.share != false
|
||||
} else if (page.layout == 'wiki' && page.wiki) {
|
||||
if (page.wiki) {
|
||||
let proj = theme.wiki.tree[page.wiki]
|
||||
if (page.share != null) {
|
||||
showSharePlugin = page.share == true
|
||||
} else if (proj != null) {
|
||||
showSharePlugin = proj.share == true
|
||||
}
|
||||
} else if (page.layout == 'post') {
|
||||
showSharePlugin = page.share != false
|
||||
}
|
||||
if (theme.article.share && showSharePlugin) {
|
||||
function socialButtons() {
|
||||
|
@ -101,8 +101,8 @@ function layoutDiv() {
|
|||
el += '&title=' + (page.seo_title || (page.title + ' - ' + config.title));
|
||||
if (page.layout == 'post' && page.cover) {
|
||||
el += '&pics=' + page.cover;
|
||||
} else if (page.layout == 'wiki' && page.logo && page.logo.src) {
|
||||
el += '&pics=' + page.logo.src;
|
||||
} else if (page.layout == 'wiki' && page.icon) {
|
||||
el += '&pics=' + page.icon;
|
||||
}
|
||||
el += '&summary=' + truncate(page.description || strip_html(page.excerpt || page.content), {length: 120});
|
||||
el += '"';
|
||||
|
|
|
@ -1,34 +1,59 @@
|
|||
<%
|
||||
function layoutDiv() {
|
||||
if (page.layout !== "wiki") {
|
||||
return '';
|
||||
function relatedPosts() {
|
||||
const { categories } = page;
|
||||
if (categories.length == 0) {
|
||||
return ''
|
||||
}
|
||||
let thisItemObject = theme.wiki.tree[page.wiki];
|
||||
const relatedItem = categories.data[0]
|
||||
var el = ''
|
||||
el += `<widget class="widget-wrapper recent">`
|
||||
el += `<div class="widget-header cap theme dis-select">`
|
||||
el += `<span class="name">${__('meta.posts_in_category', relatedItem.name)}</span>`
|
||||
el += `</div>`
|
||||
el += `<div class="widget-body related-posts">`
|
||||
relatedItem.posts.sort('date', -1).each(function(post) {
|
||||
el += `<a class="item${post.path == page.path ? ' active' : ''}" href="${url_for(post.path)}">`
|
||||
el += `<span class="title">${post.title}</span>`
|
||||
el += `</a>`
|
||||
})
|
||||
el += `</div>`
|
||||
el += `</widget>`
|
||||
return el
|
||||
}
|
||||
function relatedWiki() {
|
||||
let thisItemObject = theme.wiki.tree[page.wiki]
|
||||
if (thisItemObject == null) {
|
||||
return '';
|
||||
return ''
|
||||
}
|
||||
const relatedItems = thisItemObject.relatedItems;
|
||||
var el = '';
|
||||
const relatedItems = thisItemObject.relatedItems
|
||||
var el = ''
|
||||
for (let relatedItem of relatedItems) {
|
||||
el += '<widget class="widget-wrapper related">';
|
||||
el += '<div class="widget-header cap theme dis-select">';
|
||||
el += '<span class="name">' + __('meta.more', relatedItem.name) + '</span>';
|
||||
el += '</div>';
|
||||
el += '<div class="widget-body related-posts">';
|
||||
el += `<widget class="widget-wrapper related">`
|
||||
el += `<div class="widget-header cap theme dis-select">`
|
||||
el += `<span class="name">${__('meta.more', relatedItem.name)}</span>`
|
||||
el += `</div>`
|
||||
el += `<div class="widget-body related-posts">`
|
||||
for (let id of relatedItem.items) {
|
||||
// 同一个分组中的其它项目
|
||||
let item = theme.wiki.tree[id];
|
||||
el += '<a class="item wiki" href="' + url_for(item.homepage?.path) + '">';
|
||||
el += '<span class="title">' + item.title + '</span>';
|
||||
let item = theme.wiki.tree[id]
|
||||
el += `<a class="item wiki" href="${url_for(item.homepage?.path)}">`
|
||||
el += `<span class="title">${item.title}</span>`
|
||||
if (item.description && item.description.length > 0) {
|
||||
el += '<span class="excerpt">' + item.description + '</span>';
|
||||
el += `<span class="excerpt">${item.description}</span>`
|
||||
}
|
||||
el += '</a>';
|
||||
el += `</a>`
|
||||
}
|
||||
el += '</div>';
|
||||
el += '</widget>';
|
||||
el += `</div>`
|
||||
el += `</widget>`
|
||||
}
|
||||
return el
|
||||
}
|
||||
function layoutDiv() {
|
||||
if (page.layout == 'wiki') {
|
||||
return relatedWiki()
|
||||
} else if (page.layout == 'post') {
|
||||
return relatedPosts()
|
||||
}
|
||||
return el;
|
||||
}
|
||||
%>
|
||||
<%- layoutDiv() %>
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
<%
|
||||
let proj = theme.wiki.tree[page.wiki];
|
||||
|
||||
var hasTOC = false
|
||||
function layoutToc() {
|
||||
if (toc(page.content).length > 0) {
|
||||
hasTOC = true
|
||||
return toc(page.content, {
|
||||
list_number: item.list_number,
|
||||
min_depth: item.min_depth,
|
||||
max_depth: item.max_depth
|
||||
});
|
||||
}
|
||||
return '';
|
||||
hasTOC = false
|
||||
return ''
|
||||
}
|
||||
|
||||
function layoutTocHeader(title) {
|
||||
var el = '';
|
||||
el += '<div class="widget-header cap dis-select">';
|
||||
el += '<span class="name">' + (title || page.title || __("meta.toc")) + '</span>';
|
||||
el += '<span class="name">' + (title || __("meta.toc")) + '</span>';
|
||||
el += '</div>';
|
||||
return el;
|
||||
}
|
||||
|
@ -45,7 +47,7 @@ function layoutDocTree(pages) {
|
|||
}
|
||||
el += '</div>';
|
||||
}
|
||||
return el;
|
||||
return hasTOC ? el : ''
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,7 +104,7 @@ function layoutDiv(fallback) {
|
|||
} else if (item.fallback) {
|
||||
el += partial(item.fallback, {item: theme.data.widgets[item.fallback]});
|
||||
}
|
||||
return el;
|
||||
return hasTOC ? el : ''
|
||||
}
|
||||
|
||||
%>
|
||||
|
|
|
@ -45,6 +45,9 @@ article.md-text.content+.related-wrap
|
|||
-webkit-box-orient: vertical
|
||||
overflow: hidden
|
||||
-webkit-line-clamp: 2
|
||||
&.active
|
||||
.title
|
||||
border-bottom: 1px dashed $color-theme
|
||||
&:hover
|
||||
.title
|
||||
color: $color-hover
|
||||
|
|
Loading…
Reference in New Issue