feat: 友链/书库/移动端导航/排行榜等多模块功能
新增模块: - 友链(friendlink)后端处理 + 前端管理页与友链板 - 书库(library):导入、章节、封面、阅读页、横竖版自适应 AdaptiveCoverSlot - 顶栏导航(header_nav)配置与 MobileTabBar/MobileRailDrawers 移动端抽屉 - 排行榜 service 测试、站点页面测试、时间线发布(timeline_release) 其它改动: - 后端 handlers/services 全量小幅调整 - 前端组件、库函数、URL/品牌/站点 URL 工具更新 - Lightbox 图片、MdEntries 条目卡、coverColor 派生色相等前端能力
This commit is contained in:
39
frontend/lib/librarySections.ts
Normal file
39
frontend/lib/librarySections.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import type { LibrarySectionItem } from "@/lib/api";
|
||||
|
||||
/** 章 → 其下小节(保持平铺顺序;顺序沿用后端 sort_order) */
|
||||
export function groupSections(sections: LibrarySectionItem[]) {
|
||||
const groups: { chapter: LibrarySectionItem; subs: LibrarySectionItem[] }[] = [];
|
||||
for (const s of sections) {
|
||||
if (s.parent_id == null) {
|
||||
groups.push({ chapter: s, subs: [] });
|
||||
} else {
|
||||
groups[groups.length - 1]?.subs.push(s);
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
export interface ChapterNav {
|
||||
/** 当前章下标(0 起) */
|
||||
index: number;
|
||||
/** 章总数 */
|
||||
total: number;
|
||||
prev: LibrarySectionItem | null;
|
||||
next: LibrarySectionItem | null;
|
||||
}
|
||||
|
||||
/** 当前章在章节序列中的位置与相邻章(找不到回落第一章) */
|
||||
export function chapterNav(
|
||||
groups: { chapter: LibrarySectionItem }[],
|
||||
currentId: number | null
|
||||
): ChapterNav {
|
||||
const total = groups.length;
|
||||
let index = groups.findIndex((g) => g.chapter.id === currentId);
|
||||
if (index < 0) index = 0;
|
||||
return {
|
||||
index,
|
||||
total,
|
||||
prev: index > 0 ? groups[index - 1].chapter : null,
|
||||
next: index < total - 1 ? groups[index + 1].chapter : null,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user