docnest 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docnest",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "可复用的本地 Markdown 文档中心",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,7 +23,8 @@
23
23
  crumbs.push({ name: displayName, isLast: true, url: '' });
24
24
  } else {
25
25
  var dirPath = parts.slice(0, i + 1).join('/');
26
- crumbs.push({ name: displayName, isLast: false, url: '/doc?path=' + encodeURIComponent(dirPath + '/README.md') });
26
+ // 服务端会根据目录是否存在 README.md 决定跳转到文档或目录列表。
27
+ crumbs.push({ name: displayName, isLast: false, url: '/dir?path=' + encodeURIComponent(dirPath) });
27
28
  }
28
29
  }
29
30
  return crumbs;
@@ -54,7 +55,17 @@
54
55
  return String(text).replace(/[&<>"']/g, function(m) { return map[m]; });
55
56
  }
56
57
 
57
- function updateBreadcrumbs(docPath) {
58
+ function updateBreadcrumbs(docPath, loadedDocument) {
59
+ var currentBreadcrumbs = document.querySelector('.breadcrumbs');
60
+ if (!currentBreadcrumbs) return;
61
+
62
+ // 服务端已经掌握真实目录结构,优先复用它生成的面包屑,避免客户端猜测 README.md。
63
+ var serverBreadcrumbs = loadedDocument && loadedDocument.querySelector('.breadcrumbs');
64
+ if (serverBreadcrumbs) {
65
+ currentBreadcrumbs.innerHTML = serverBreadcrumbs.innerHTML;
66
+ return;
67
+ }
68
+
58
69
  var crumbs = buildBreadcrumbsFromPath(docPath);
59
70
  renderBreadcrumbs(crumbs);
60
71
  }
@@ -194,7 +205,7 @@
194
205
  if (newTitle) document.title = newTitle.textContent;
195
206
  window.currentDocPath = pathFromUrl || pathFromHref(absoluteUrl);
196
207
  updateActiveLink(window.currentDocPath);
197
- updateBreadcrumbs(window.currentDocPath);
208
+ updateBreadcrumbs(window.currentDocPath, doc);
198
209
  if (typeof window.buildDocToc === 'function') window.buildDocToc();
199
210
  if (typeof window.scrollToDocHash === 'function') window.scrollToDocHash();
200
211