[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: 您可能感兴趣的文章
comment_title: 快来参与讨论吧
back_to_top: 回到顶部
more: '更多%s'
more: '更多%s'
created: 发布于
updated: 更新于
license: 许可协议

View File

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

View File

@ -13,8 +13,11 @@ function layoutDiv() {
}
el += '<div class="excerpt">';
if (proj.tags && proj.tags.length > 0) {
let tag = proj.tags[0];
el += '<div class="cap breadcrumb"' + category_color(tag) + '>' + tag + '</div>';
el += '<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>';
if (proj.description) {

View File

@ -3,34 +3,25 @@ function layoutDiv() {
if (page.layout !== "wiki") {
return '';
}
var related = [];
const { shelf, tree } = theme.wiki;
let proj = tree[page.wiki];
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);
}
});
let thisItemObject = theme.wiki.tree[page.wiki];
if (thisItemObject == null) {
return '';
}
const relatedItems = thisItemObject.relatedItems;
var el = '';
if (related.length > 0) {
for (let relatedItem of relatedItems) {
el += '<widget class="widget-wrapper related">';
el += '<div class="widget-header cap theme dis-select">';
var title = __('btn.wiki');
if (proj.tags && proj.tags[0]) {
title = proj.tags[0];
}
el += '<span class="name">' + __('meta.more', title) + '</span>';
el += '<span class="name">' + __('meta.more', relatedItem.name) + '</span>';
el += '</div>';
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) + '">';
el += '<span class="title">' + p.title + '</span>';
if (p.description && p.description.length > 0) {
el += '<span class="excerpt">' + p.description + '</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 += '</a>';
}

View File

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

View File

@ -58,6 +58,8 @@ module.exports = ctx => {
// wiki 所有页面
const wiki_pages = pages.filter(p => (p.layout === 'wiki')).map(p => new WikiPage(p))
const wiki_list = Object.keys(wiki.tree)
// 上架的项目列表
wiki.shelf = ctx.locals.get('data').wiki
// 数据整合:项目标签
var all_tag_name = []
@ -158,17 +160,25 @@ module.exports = ctx => {
// 全站所有的项目标签
var all_tags = {}
all_tag_name.forEach((tag_name, i) => {
var subs = []
var items = []
for (let id of wiki_list) {
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] = {
name: tag_name,
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) {
let item = wiki.tree[id]
if (item.tags) {
var related = []
var relatedItems = []
item.tags.forEach((tag_name, i) => {
let tagObj = all_tags[tag_name]
related = related.concat(tagObj.items)
related = [...new Set(related)]
let relatedOtherItems = all_tags[tag_name].items.filter(name => name != item.id)
if (relatedOtherItems.length > 0) {
relatedItems.push({
name: tag_name,
items: relatedOtherItems
})
}
})
item.related = related
item.relatedItems = relatedItems
}
}

View File

@ -164,3 +164,5 @@
word-wrap: break-word
p:last-child
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;
if (!needFancybox) {
const els = document.getElementsByClassName('stellar-memos-api');
console.log('els', els);
if (els != undefined && els.length > 0) {
needFancybox = true;
}