[opt] wiki

This commit is contained in:
xaoxuu 2023-12-17 19:39:23 +08:00
parent 1080ca7d04
commit 091dd14eb6
8 changed files with 51 additions and 43 deletions

View File

@ -23,7 +23,7 @@ meta:
related_posts: 您可能感兴趣的文章 related_posts: 您可能感兴趣的文章
comment_title: 快来参与讨论吧 comment_title: 快来参与讨论吧
back_to_top: 回到顶部 back_to_top: 回到顶部
more: '更多%s' more: '更多%s'
created: 发布于 created: 发布于
updated: 更新于 updated: 更新于
license: 许可协议 license: 许可协议

View File

@ -23,7 +23,7 @@ meta:
related_posts: 您可能感興趣的文章 related_posts: 您可能感興趣的文章
comment_title: 參與討論 comment_title: 參與討論
back_to_top: 回到頁首 back_to_top: 回到頁首
more: '更多%s' more: '更多%s'
created: 發布於 created: 發布於
updated: 更新於 updated: 更新於
license: 授權條款 license: 授權條款

View File

@ -13,8 +13,11 @@ function layoutDiv() {
} }
el += '<div class="excerpt">'; el += '<div class="excerpt">';
if (proj.tags && proj.tags.length > 0) { if (proj.tags && proj.tags.length > 0) {
let tag = proj.tags[0]; el += '<div>';
el += '<div class="cap breadcrumb"' + category_color(tag) + '>' + tag + '</div>'; for (let tag of proj.tags) {
el += '<span class="cap breadcrumb"' + category_color(tag) + '>' + tag + '</span>';
}
el += '</div>';
} }
el += '<h2 class="post-title">' + (proj.title || proj.name) + '</h2>'; el += '<h2 class="post-title">' + (proj.title || proj.name) + '</h2>';
if (proj.description) { if (proj.description) {

View File

@ -3,34 +3,25 @@ function layoutDiv() {
if (page.layout !== "wiki") { if (page.layout !== "wiki") {
return ''; return '';
} }
var related = []; let thisItemObject = theme.wiki.tree[page.wiki];
const { shelf, tree } = theme.wiki; if (thisItemObject == null) {
let proj = tree[page.wiki]; return '';
if (proj?.related?.length > 0) {
proj.related.filter(pid => shelf.includes(pid)).forEach((pid, i) => {
let p = tree[pid];
if (p && p.title !== proj?.title && p.homepage) {
related.push(p);
}
});
} }
const relatedItems = thisItemObject.relatedItems;
var el = ''; var el = '';
if (related.length > 0) { for (let relatedItem of relatedItems) {
el += '<widget class="widget-wrapper related">'; el += '<widget class="widget-wrapper related">';
el += '<div class="widget-header cap theme dis-select">'; el += '<div class="widget-header cap theme dis-select">';
var title = __('btn.wiki'); el += '<span class="name">' + __('meta.more', relatedItem.name) + '</span>';
if (proj.tags && proj.tags[0]) {
title = proj.tags[0];
}
el += '<span class="name">' + __('meta.more', title) + '</span>';
el += '</div>'; el += '</div>';
el += '<div class="widget-body related-posts">'; el += '<div class="widget-body related-posts">';
for (let p of related) { for (let id of relatedItem.items) {
// 同一个分组中的其它项目 // 同一个分组中的其它项目
el += '<a class="item wiki" href="' + url_for(p.homepage?.path) + '">'; let item = theme.wiki.tree[id];
el += '<span class="title">' + p.title + '</span>'; el += '<a class="item wiki" href="' + url_for(item.homepage?.path) + '">';
if (p.description && p.description.length > 0) { el += '<span class="title">' + item.title + '</span>';
el += '<span class="excerpt">' + p.description + '</span>'; if (item.description && item.description.length > 0) {
el += '<span class="excerpt">' + item.description + '</span>';
} }
el += '</a>'; el += '</a>';
} }

View File

@ -22,7 +22,7 @@ function layout_post_card(layout, post, content) {
return el; return el;
} }
function layout_posts(partial) { function layout_post_list(partial) {
var el = ''; var el = '';
el += '<div class="post-list post">'; el += '<div class="post-list post">';
if (is_home()) { if (is_home()) {
@ -48,9 +48,8 @@ function layout_posts(partial) {
return el; return el;
} }
function layout_wikis(partial) { function layout_wiki_list(partial) {
var el = ''; var el = '';
var wikis = [];
const { shelf, tree } = theme.wiki; const { shelf, tree } = theme.wiki;
for (let pid of shelf) { for (let pid of shelf) {
let proj = tree[pid]; let proj = tree[pid];
@ -61,12 +60,12 @@ function layout_wikis(partial) {
continue; continue;
} }
if (page.filter === false) { if (page.filter === false) {
// all wikis // wikiList
el += '<div class="post-list wiki">'; el += '<div class="post-list wiki">';
el += layout_post_card('wiki', proj.homepage, partial(proj)); el += layout_post_card('wiki', proj.homepage, partial(proj));
el += '</div>'; el += '</div>';
} else if (proj.tags && proj.tags.includes(page.tagName) === true) { } else if (proj.tags && proj.tags.includes(page.tagName) === true) {
// filtered wikis // filtered wikiList
el += '<div class="post-list wiki filter">'; el += '<div class="post-list wiki filter">';
el += layout_post_card('wiki', proj.homepage, partial(proj)); el += layout_post_card('wiki', proj.homepage, partial(proj));
el += '</div>'; el += '</div>';
@ -78,13 +77,13 @@ function layout_wikis(partial) {
<% if (page.menu_id === 'post') { %> <% if (page.menu_id === 'post') { %>
<%- partial('_partial/main/navbar/list_post') %> <%- partial('_partial/main/navbar/list_post') %>
<%- layout_posts(function(post){ <%- layout_post_list(function(post){
return partial('_partial/main/post_list/post_card', {post: post}) return partial('_partial/main/post_list/post_card', {post: post})
}) %> }) %>
<%- partial('_partial/main/post_list/paginator') %> <%- partial('_partial/main/post_list/paginator') %>
<% } else if (page.menu_id === 'wiki') { %> <% } else if (page.menu_id === 'wiki') { %>
<%- partial('_partial/main/navbar/list_wiki') %> <%- partial('_partial/main/navbar/list_wiki') %>
<%- layout_wikis(function(proj){ <%- layout_wiki_list(function(proj){
return partial('_partial/main/post_list/wiki_card', {proj: proj}) return partial('_partial/main/post_list/wiki_card', {proj: proj})
}) %> }) %>
<% } %> <% } %>

View File

@ -58,6 +58,8 @@ module.exports = ctx => {
// wiki 所有页面 // wiki 所有页面
const wiki_pages = pages.filter(p => (p.layout === 'wiki')).map(p => new WikiPage(p)) const wiki_pages = pages.filter(p => (p.layout === 'wiki')).map(p => new WikiPage(p))
const wiki_list = Object.keys(wiki.tree) const wiki_list = Object.keys(wiki.tree)
// 上架的项目列表
wiki.shelf = ctx.locals.get('data').wiki
// 数据整合:项目标签 // 数据整合:项目标签
var all_tag_name = [] var all_tag_name = []
@ -158,17 +160,25 @@ module.exports = ctx => {
// 全站所有的项目标签 // 全站所有的项目标签
var all_tags = {} var all_tags = {}
all_tag_name.forEach((tag_name, i) => { all_tag_name.forEach((tag_name, i) => {
var subs = [] var items = []
for (let id of wiki_list) { for (let id of wiki_list) {
let item = wiki.tree[id] let item = wiki.tree[id]
if (item.tags && item.tags.includes(tag_name) === true && subs.includes(tag_name) === false) { // 过滤掉找不到页面的项目
subs.push(item.id) if (item.homepage == null) {
continue
}
// 过滤掉未上架的项目
if (!wiki.shelf.includes(item.id)) {
continue
}
if (item.tags && item.tags.includes(tag_name) === true && items.includes(tag_name) === false) {
items.push(item.id)
} }
} }
all_tags[tag_name] = { all_tags[tag_name] = {
name: tag_name, name: tag_name,
path: (ctx.config.wiki_dir || 'wiki') + '/tags/' + tag_name + '/index.html', path: (ctx.config.wiki_dir || 'wiki') + '/tags/' + tag_name + '/index.html',
items: subs items: items
} }
}) })
@ -176,13 +186,17 @@ module.exports = ctx => {
for (let id of wiki_list) { for (let id of wiki_list) {
let item = wiki.tree[id] let item = wiki.tree[id]
if (item.tags) { if (item.tags) {
var related = [] var relatedItems = []
item.tags.forEach((tag_name, i) => { item.tags.forEach((tag_name, i) => {
let tagObj = all_tags[tag_name] let relatedOtherItems = all_tags[tag_name].items.filter(name => name != item.id)
related = related.concat(tagObj.items) if (relatedOtherItems.length > 0) {
related = [...new Set(related)] relatedItems.push({
name: tag_name,
items: relatedOtherItems
}) })
item.related = related }
})
item.relatedItems = relatedItems
} }
} }

View File

@ -164,3 +164,5 @@
word-wrap: break-word word-wrap: break-word
p:last-child p:last-child
margin-bottom: 0 margin-bottom: 0
.cap+.cap
margin-left: 4px

View File

@ -323,7 +323,6 @@ if (stellar.plugins.fancybox) {
var needFancybox = document.querySelectorAll(selector).length !== 0; var needFancybox = document.querySelectorAll(selector).length !== 0;
if (!needFancybox) { if (!needFancybox) {
const els = document.getElementsByClassName('stellar-memos-api'); const els = document.getElementsByClassName('stellar-memos-api');
console.log('els', els);
if (els != undefined && els.length > 0) { if (els != undefined && els.length > 0) {
needFancybox = true; needFancybox = true;
} }