zhangdocs 1.1.20 → 1.1.24

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/lib/build.js CHANGED
@@ -32,7 +32,10 @@ var renderer = new marked.Renderer();
32
32
  renderer.code = function (code, lang) {
33
33
  if (lang === 'mermaid') {
34
34
  // 为Mermaid图表生成特殊的div容器
35
- return '<div class="mermaid">' + code + '</div>';
35
+ // 转义 HTML 特殊字符,避免被解析为 HTML 标签
36
+ // 将 < 转为 &lt;,> 转为 &gt;
37
+ var escapedCode = code.replace(/</g, '&lt;').replace(/>/g, '&gt;');
38
+ return '<div class="mermaid">' + escapedCode + '</div>';
36
39
  } else {
37
40
  // 对于其他语言,使用默认的高亮处理
38
41
  if (lang && highlight.getLanguage(lang)) {
@@ -186,6 +189,56 @@ function build(commander, changeFile) {
186
189
  // 图片引用路径处理
187
190
  markedstr = imgPath(markedstr, _path);
188
191
 
192
+ // 计算上一节和下一节的URL
193
+ var prevUrl = null;
194
+ var nextUrl = null;
195
+ var prevTitle = null;
196
+ var nextTitle = null;
197
+
198
+ if (idx > 0) {
199
+ // 上一节
200
+ var prevItem = pathArr[idx - 1];
201
+ var prevItemRel = path.normalize(prevItem);
202
+ prevItemRel = prevItemRel.replace(path.normalize(process.cwd() + '/md/'), '');
203
+ var prevPath = path.normalize(process.cwd() + '/html/' + prevItemRel).replace('.md', ".html");
204
+ // 计算从当前页面到上一节的相对路径
205
+ var relative = path.relative(path.dirname(_path), prevPath).replace(/\\/g, '/');
206
+ // 如果相对路径为空或为当前目录,使用文件名
207
+ if (!relative || relative === '.') {
208
+ prevUrl = path.basename(prevPath);
209
+ } else {
210
+ // 确保路径以 ./ 开头(如果不在同一目录)
211
+ if (!relative.startsWith('.')) {
212
+ prevUrl = './' + relative;
213
+ } else {
214
+ prevUrl = relative;
215
+ }
216
+ }
217
+ prevTitle = path.basename(prevItem, '.md');
218
+ }
219
+
220
+ if (idx < pathArr.length - 1) {
221
+ // 下一节
222
+ var nextItem = pathArr[idx + 1];
223
+ var nextItemRel = path.normalize(nextItem);
224
+ nextItemRel = nextItemRel.replace(path.normalize(process.cwd() + '/md/'), '');
225
+ var nextPath = path.normalize(process.cwd() + '/html/' + nextItemRel).replace('.md', ".html");
226
+ // 计算从当前页面到下一节的相对路径
227
+ var relative = path.relative(path.dirname(_path), nextPath).replace(/\\/g, '/');
228
+ // 如果相对路径为空或为当前目录,使用文件名
229
+ if (!relative || relative === '.') {
230
+ nextUrl = path.basename(nextPath);
231
+ } else {
232
+ // 确保路径以 ./ 开头(如果不在同一目录)
233
+ if (!relative.startsWith('.')) {
234
+ nextUrl = './' + relative;
235
+ } else {
236
+ nextUrl = relative;
237
+ }
238
+ }
239
+ nextTitle = path.basename(nextItem, '.md');
240
+ }
241
+
189
242
  // ejs 模板生成HTML
190
243
  html = file.ejs(template + '/layout.ejs', {
191
244
  title: pkg.name,//项目工程名字
@@ -194,7 +247,11 @@ function build(commander, changeFile) {
194
247
  relative_path: file.relativePath(_path, process.cwd()),//相对路径
195
248
  menu_html: navHTML,//页面之间的超链接导航
196
249
  toc_html: tocHTML,// markdown 导航
197
- markdown_html: markedstr // markdown 生成字符串
250
+ markdown_html: markedstr, // markdown 生成字符串
251
+ prev_url: prevUrl, // 上一节URL
252
+ next_url: nextUrl, // 下一节URL
253
+ prev_title: prevTitle, // 上一节标题
254
+ next_title: nextTitle // 下一节标题
198
255
  });
199
256
  file.mkdirsSync(path.dirname(_path));
200
257
  //写入指定目录中
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zhangdocs",
3
- "version": "1.1.20",
3
+ "version": "1.1.24",
4
4
  "description": "Simple document generation tool. Dependence Node.js run.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,6 +8,47 @@
8
8
  <div class="content markdown-body <%= index ? 'index-page-content' : '' %>">
9
9
 
10
10
  <%- markdown_html %>
11
+
12
+ <% if (!index) { %>
13
+ <!-- 上一节/下一节导航按钮 -->
14
+ <div class="page-navigation">
15
+ <% if (typeof prev_url !== 'undefined' && prev_url) { %>
16
+ <a href="<%= prev_url %>" class="nav-button nav-prev" id="nav-prev">
17
+ <span class="nav-arrow">←</span>
18
+ <span class="nav-text">
19
+ <span class="nav-label">上一节</span>
20
+ <span class="nav-title"><%= prev_title || '上一节' %></span>
21
+ </span>
22
+ </a>
23
+ <% } else { %>
24
+ <div class="nav-button nav-prev nav-disabled">
25
+ <span class="nav-arrow">←</span>
26
+ <span class="nav-text">
27
+ <span class="nav-label">上一节</span>
28
+ <span class="nav-title">没有上一节</span>
29
+ </span>
30
+ </div>
31
+ <% } %>
32
+
33
+ <% if (typeof next_url !== 'undefined' && next_url) { %>
34
+ <a href="<%= next_url %>" class="nav-button nav-next" id="nav-next">
35
+ <span class="nav-text">
36
+ <span class="nav-label">下一节</span>
37
+ <span class="nav-title"><%= next_title || '下一节' %></span>
38
+ </span>
39
+ <span class="nav-arrow">→</span>
40
+ </a>
41
+ <% } else { %>
42
+ <div class="nav-button nav-next nav-disabled">
43
+ <span class="nav-text">
44
+ <span class="nav-label">下一节</span>
45
+ <span class="nav-title">没有下一节</span>
46
+ </span>
47
+ <span class="nav-arrow">→</span>
48
+ </div>
49
+ <% } %>
50
+ </div>
51
+ <% } %>
11
52
  </div>
12
53
  </div>
13
54
 
@@ -374,5 +415,28 @@ style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background:
374
415
  setTimeout(initImageViewer, 500);
375
416
  setTimeout(initImageViewer, 1000);
376
417
  })();
418
+
419
+ // 上一节/下一节导航功能
420
+ (function() {
421
+ var prevButton = document.getElementById('nav-prev');
422
+ var nextButton = document.getElementById('nav-next');
423
+
424
+ // 键盘快捷键:Ctrl + 左箭头(上一节),Ctrl + 右箭头(下一节)
425
+ document.addEventListener('keydown', function(e) {
426
+ // 检查是否按下了Ctrl键
427
+ if (e.ctrlKey || e.metaKey) {
428
+ // Ctrl + 左箭头:上一节
429
+ if (e.key === 'ArrowLeft' && prevButton && prevButton.href) {
430
+ e.preventDefault();
431
+ window.location.href = prevButton.href;
432
+ }
433
+ // Ctrl + 右箭头:下一节
434
+ else if (e.key === 'ArrowRight' && nextButton && nextButton.href) {
435
+ e.preventDefault();
436
+ window.location.href = nextButton.href;
437
+ }
438
+ }
439
+ });
440
+ })();
377
441
  </script>
378
442
  <% include footer.ejs %>
@@ -440,4 +440,76 @@ table
440
440
  background: $secondary-color
441
441
  color: $primary-color
442
442
  border-left-color: $primary-color
443
- transform: translateX(5px)
443
+ transform: translateX(5px)
444
+
445
+ // 上一节/下一节导航按钮
446
+ .page-navigation
447
+ display: flex
448
+ justify-content: space-between
449
+ align-items: center
450
+ margin-top: 40px
451
+ padding-top: 30px
452
+ border-top: 1px solid $border-color
453
+ gap: 20px
454
+
455
+ .nav-button
456
+ display: flex
457
+ align-items: center
458
+ padding: 12px 20px
459
+ background: #fff
460
+ border: 1px solid $border-color
461
+ border-radius: 6px
462
+ text-decoration: none
463
+ color: $text-color
464
+ transition: all 0.2s ease
465
+ flex: 1
466
+ max-width: 45%
467
+
468
+ &:hover
469
+ background: $secondary-color
470
+ border-color: $primary-color
471
+ color: $primary-color
472
+ transform: translateY(-2px)
473
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1)
474
+
475
+ &.nav-disabled
476
+ opacity: 0.5
477
+ cursor: not-allowed
478
+ pointer-events: none
479
+
480
+ .nav-arrow
481
+ font-size: 20px
482
+ font-weight: bold
483
+ margin: 0 10px
484
+
485
+ .nav-text
486
+ display: flex
487
+ flex-direction: column
488
+ flex: 1
489
+
490
+ .nav-label
491
+ font-size: 12px
492
+ color: #999
493
+ margin-bottom: 4px
494
+ text-transform: uppercase
495
+ letter-spacing: 0.5px
496
+
497
+ .nav-title
498
+ font-size: 14px
499
+ font-weight: 500
500
+ line-height: 1.4
501
+
502
+ &.nav-prev
503
+ text-align: left
504
+
505
+ &.nav-next
506
+ text-align: right
507
+ flex-direction: row-reverse
508
+
509
+ @media mq-mobile
510
+ flex-direction: column
511
+ gap: 15px
512
+
513
+ .nav-button
514
+ max-width: 100%
515
+ width: 100%