docnest 0.1.16 → 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.16",
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
 
@@ -568,25 +568,39 @@
568
568
  }
569
569
 
570
570
  function drawWatermarkPattern(context, width, height, referenceHeight, watermarkText) {
571
- if (!watermarkText) return;
572
- var tileWidth = width / 4;
573
- var tileHeight = referenceHeight / 2;
574
- var fontSize = Math.round(Math.min(tileWidth, tileHeight) * 0.38);
575
- var startX = tileWidth / 2;
576
- var startY = tileHeight / 2;
571
+ if (!watermarkText || width <= 0 || height <= 0 || referenceHeight <= 0) return;
572
+ var rotation = -Math.PI / 6;
573
+ var fontSize = Math.max(36, Math.min(56, Math.round(Math.min(width, referenceHeight) * 0.022)));
574
+ var font = '500 ' + fontSize + 'px "PingFang SC", "Microsoft YaHei", sans-serif';
577
575
 
578
576
  context.save();
579
577
  context.textAlign = 'center';
580
578
  context.textBaseline = 'middle';
581
- context.fillStyle = 'rgba(30, 41, 59, 0.055)';
582
- context.font = '700 ' + fontSize + 'px "PingFang SC", "Microsoft YaHei", sans-serif';
583
-
584
- for (var y = startY; y < height + tileHeight; y += tileHeight) {
585
- var rowOffsetX = Math.round(((y - startY) / tileHeight) % 2) * (tileWidth / 2);
586
- for (var x = startX; x < width + tileWidth; x += tileWidth) {
579
+ context.fillStyle = 'rgba(30, 41, 59, 0.04)';
580
+ context.font = font;
581
+
582
+ // Use the actual rendered text width to calculate the repeat distance. The
583
+ // old fixed four-column grid was narrower than this long title, so adjacent
584
+ // watermarks collided and looked like a rough gray texture.
585
+ var textWidth = typeof context.measureText === 'function'
586
+ ? context.measureText(watermarkText).width
587
+ : fontSize * Math.max(watermarkText.length, 1) * 0.9;
588
+ var textHeight = fontSize;
589
+ var cos = Math.abs(Math.cos(rotation));
590
+ var sin = Math.abs(Math.sin(rotation));
591
+ var rotatedWidth = textWidth * cos + textHeight * sin;
592
+ var rotatedHeight = textWidth * sin + textHeight * cos;
593
+ var columnStep = Math.max(width / 3, rotatedWidth * 1.55);
594
+ var rowStep = Math.max(referenceHeight / 3, rotatedHeight * 2.75);
595
+ var startX = columnStep / 2;
596
+ var startY = rowStep / 2;
597
+
598
+ for (var rowIndex = 0, y = startY; y < height; rowIndex += 1, y += rowStep) {
599
+ var rowOffsetX = rowIndex % 2 === 1 ? columnStep / 2 : 0;
600
+ for (var x = startX; x + rowOffsetX < width; x += columnStep) {
587
601
  context.save();
588
602
  context.translate(x + rowOffsetX, y);
589
- context.rotate(-Math.PI / 5.4);
603
+ context.rotate(rotation);
590
604
  context.fillText(watermarkText, 0, 0);
591
605
  context.restore();
592
606
  }