|
|
@@ -16,7 +16,9 @@ const DOM = {
|
|
|
editBtn: null,
|
|
|
editorContainer: null,
|
|
|
markdownEditor: null,
|
|
|
- editorDocName: null
|
|
|
+ editorDocName: null,
|
|
|
+ navPrev: null,
|
|
|
+ navNext: null
|
|
|
};
|
|
|
|
|
|
// 配置 marked
|
|
|
@@ -159,6 +161,9 @@ async function loadDocument(docName, scrollToText = null) {
|
|
|
// 生成 TOC
|
|
|
generateTOC();
|
|
|
|
|
|
+ // 更新文档导航(上一页/下一页)
|
|
|
+ updateDocNavigation();
|
|
|
+
|
|
|
// 更新活动文档 - 使用 toggle 优化
|
|
|
if (DOM.docNav) {
|
|
|
const navItems = DOM.docNav.querySelectorAll('.nav-item');
|
|
|
@@ -272,6 +277,78 @@ function updateURL(category, doc) {
|
|
|
window.history.pushState({}, '', url);
|
|
|
}
|
|
|
|
|
|
+// 更新文档导航(上一页/下一页)
|
|
|
+function updateDocNavigation() {
|
|
|
+ // 缓存 DOM 元素
|
|
|
+ if (!DOM.navPrev) DOM.navPrev = document.getElementById('nav-prev');
|
|
|
+ if (!DOM.navNext) DOM.navNext = document.getElementById('nav-next');
|
|
|
+
|
|
|
+ if (!DOM.navPrev || !DOM.navNext || docList.length === 0) return;
|
|
|
+
|
|
|
+ const docNavigation = document.getElementById('doc-navigation');
|
|
|
+ if (!docNavigation) return;
|
|
|
+
|
|
|
+ // 找到当前文档在列表中的索引
|
|
|
+ const currentIndex = docList.findIndex(doc => doc.name === currentDoc);
|
|
|
+
|
|
|
+ if (currentIndex === -1) {
|
|
|
+ DOM.navPrev.style.display = 'none';
|
|
|
+ DOM.navNext.style.display = 'none';
|
|
|
+ docNavigation.className = 'doc-navigation';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const hasPrev = currentIndex > 0;
|
|
|
+ const hasNext = currentIndex < docList.length - 1;
|
|
|
+
|
|
|
+ // 处理上一页
|
|
|
+ if (hasPrev) {
|
|
|
+ const prevDoc = docList[currentIndex - 1];
|
|
|
+ DOM.navPrev.style.display = 'flex';
|
|
|
+ DOM.navPrev.querySelector('.nav-doc-name').textContent = prevDoc.name;
|
|
|
+ DOM.navPrev.onclick = () => {
|
|
|
+ loadDocument(prevDoc.name);
|
|
|
+ updateURL(currentCategory, prevDoc.name);
|
|
|
+ // 滚动到顶部
|
|
|
+ const contentArea = document.getElementById('content-area');
|
|
|
+ if (contentArea) {
|
|
|
+ contentArea.scrollTo({ top: 0, behavior: 'smooth' });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ DOM.navPrev.style.display = 'none';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理下一页
|
|
|
+ if (hasNext) {
|
|
|
+ const nextDoc = docList[currentIndex + 1];
|
|
|
+ DOM.navNext.style.display = 'flex';
|
|
|
+ DOM.navNext.querySelector('.nav-doc-name').textContent = nextDoc.name;
|
|
|
+ DOM.navNext.onclick = () => {
|
|
|
+ loadDocument(nextDoc.name);
|
|
|
+ updateURL(currentCategory, nextDoc.name);
|
|
|
+ // 滚动到顶部
|
|
|
+ const contentArea = document.getElementById('content-area');
|
|
|
+ if (contentArea) {
|
|
|
+ contentArea.scrollTo({ top: 0, behavior: 'smooth' });
|
|
|
+ }
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ DOM.navNext.style.display = 'none';
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据导航按钮状态添加类,用于CSS定位
|
|
|
+ if (hasPrev && hasNext) {
|
|
|
+ docNavigation.className = 'doc-navigation has-both';
|
|
|
+ } else if (hasPrev) {
|
|
|
+ docNavigation.className = 'doc-navigation has-prev-only';
|
|
|
+ } else if (hasNext) {
|
|
|
+ docNavigation.className = 'doc-navigation has-next-only';
|
|
|
+ } else {
|
|
|
+ docNavigation.className = 'doc-navigation';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// 显示错误
|
|
|
function showError(message) {
|
|
|
const content = document.getElementById('markdown-content');
|