dsh-zdiary-kit 0.7.0 → 0.7.1
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/README.md +1 -1
- package/dist/cli.js +13 -5
- package/dist/features/zk-tools/feature.js +13 -5
- package/dist/lib/lint.js +31 -14
- package/docs/features/zk-tools.md +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -23,7 +23,8 @@ const HELP = `zk-kit —— dsh-zdiary-kit 的命令行
|
|
|
23
23
|
zk-kit daily [--entry 一段] [--date yesterday]
|
|
24
24
|
zk-kit append <路径> --text 一段 [--heading 标题]
|
|
25
25
|
zk-kit link <来源路径> <目标路径或标题>
|
|
26
|
-
zk-kit lint [--stale-days 90]
|
|
26
|
+
zk-kit lint [--stale-days 90] [--links-only]
|
|
27
|
+
体检:断链 / 孤儿 / 无标签 / 单向链接 / 陈旧 / 重名(只读)
|
|
27
28
|
zk-kit dream [--days 7] 晋升材料:窗口新增 / daily 未完成 / 被引最多(只读)
|
|
28
29
|
zk-kit query [-- <zk list 参数>] 透传 zk list(--notebook-dir / --format / -x 会被替换掉)
|
|
29
30
|
zk-kit index 重建索引
|
|
@@ -147,12 +148,16 @@ function lintReport(r) {
|
|
|
147
148
|
lines.push(row('孤儿', r.orphans.total, r.orphans.items));
|
|
148
149
|
lines.push(row('无标签', r.tagless.total, r.tagless.items));
|
|
149
150
|
const oneWay = r.oneWayLinks;
|
|
151
|
+
const oneWayLabel = oneWay.linksOnly ? '单向链接(Links)' : '单向链接';
|
|
152
|
+
const bodyNote = oneWay.bodyOnly > 0
|
|
153
|
+
? (oneWay.linksOnly ? `(另有正文引用 ${oneWay.bodyOnly} 条未计)` : `(正文引用 ${oneWay.bodyOnly} 条)`)
|
|
154
|
+
: '';
|
|
150
155
|
if (oneWay.total === 0)
|
|
151
|
-
lines.push(
|
|
156
|
+
lines.push(`✓ ${oneWayLabel}:0${bodyNote}`);
|
|
152
157
|
else {
|
|
153
158
|
const items = oneWay.items.slice(0, 5).map((i) => `${i.path} ← ${i.from.join('、')}`);
|
|
154
|
-
lines.push(`✗
|
|
155
|
-
|
|
159
|
+
lines.push(`✗ ${oneWayLabel}:${oneWay.total} 篇 / ${oneWay.edges} 条单向边` +
|
|
160
|
+
bodyNote +
|
|
156
161
|
` — ${items.join(';')}${oneWay.total > items.length ? ' …' : ''}`);
|
|
157
162
|
}
|
|
158
163
|
lines.push(r.stale.total === 0
|
|
@@ -353,7 +358,10 @@ async function main() {
|
|
|
353
358
|
}
|
|
354
359
|
case 'lint': {
|
|
355
360
|
await ensureNotebook(cfg);
|
|
356
|
-
const r = await lintNotebook(cfg, {
|
|
361
|
+
const r = await lintNotebook(cfg, {
|
|
362
|
+
staleDays: Number(str(flags['stale-days'])) || 90,
|
|
363
|
+
linksOnly: flags['links-only'] === true || flags['links-only'] === 'true',
|
|
364
|
+
});
|
|
357
365
|
print(json ? r : lintReport(r), json);
|
|
358
366
|
return;
|
|
359
367
|
}
|
|
@@ -39,8 +39,9 @@ const LINT_ONE_WAY = objSchema({
|
|
|
39
39
|
total: { type: 'number' },
|
|
40
40
|
edges: { type: 'number' },
|
|
41
41
|
bodyOnly: { type: 'number' },
|
|
42
|
+
linksOnly: { type: 'boolean' },
|
|
42
43
|
items: { type: 'array', items: LINT_ONE_WAY_ITEM },
|
|
43
|
-
}, ['total', 'edges', 'bodyOnly', 'items']);
|
|
44
|
+
}, ['total', 'edges', 'bodyOnly', 'linksOnly', 'items']);
|
|
44
45
|
const LINT_STALE = objSchema({
|
|
45
46
|
total: { type: 'number' },
|
|
46
47
|
items: {
|
|
@@ -807,7 +808,8 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
807
808
|
'supersede 不会重写 meta 文件里的链接,这类漂移 broken-links 看不见。' +
|
|
808
809
|
'孤儿与无标签不含日记(按天写的日记天然如此,报出来只会淹没真问题)。' +
|
|
809
810
|
'oneWayLinks.items 是缺回链的目标 X(不是来源),from 是没被 X 回链的来源 S;' +
|
|
810
|
-
'edges
|
|
811
|
+
'edges 是列出的单向边数,bodyOnly 是正文引用(不在 ## Links / ## 链接 小节)的单向边数。' +
|
|
812
|
+
'links_only=true 时只列 Links 小节的单向链接,正文引用只进 bodyOnly,适合把桶当可修清单。' +
|
|
811
813
|
'S 或 X 是日记的边不算 —— 日记天然是出边,回链它没有意义。' +
|
|
812
814
|
'触到扫描上限时结果只会漏报,不会误报。' +
|
|
813
815
|
'只读:不改任何笔记。拿到清单后自己判断先修哪个,再用 zk_link / zk_append / zk_supersede 动手。',
|
|
@@ -815,6 +817,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
815
817
|
type: 'object',
|
|
816
818
|
properties: {
|
|
817
819
|
stale_days: S.num('多少天没修改算陈旧(1-3650,默认 90)'),
|
|
820
|
+
links_only: S.bool('只报 Links 小节的单向链接;正文引用只计数(默认 false)'),
|
|
818
821
|
},
|
|
819
822
|
additionalProperties: false,
|
|
820
823
|
},
|
|
@@ -839,6 +842,7 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
839
842
|
await ensureNotebook(cfg, env.signal);
|
|
840
843
|
return lintNotebook(cfg, {
|
|
841
844
|
staleDays: args.stale_days === undefined ? undefined : Number(args.stale_days),
|
|
845
|
+
linksOnly: args.links_only === true,
|
|
842
846
|
}, env.signal);
|
|
843
847
|
},
|
|
844
848
|
render(_args, value) {
|
|
@@ -859,12 +863,16 @@ export function buildTools(workspaceOf = () => processWorkspace()) {
|
|
|
859
863
|
lines.push(line('孤儿', v.orphans));
|
|
860
864
|
lines.push(line('无标签', v.tagless));
|
|
861
865
|
const oneWay = v.oneWayLinks;
|
|
866
|
+
const oneWayLabel = oneWay.linksOnly ? '单向链接(Links)' : '单向链接';
|
|
867
|
+
const bodyNote = oneWay.bodyOnly > 0
|
|
868
|
+
? (oneWay.linksOnly ? '(另有正文引用 ' + oneWay.bodyOnly + ' 条未计)' : '(正文引用 ' + oneWay.bodyOnly + ' 条)')
|
|
869
|
+
: '';
|
|
862
870
|
if (oneWay.total === 0)
|
|
863
|
-
lines.push('✓
|
|
871
|
+
lines.push('✓ ' + oneWayLabel + ':0' + bodyNote);
|
|
864
872
|
else {
|
|
865
873
|
const items = oneWay.items.slice(0, 5).map((i) => i.path + ' ← ' + i.from.join('、'));
|
|
866
|
-
lines.push('✗
|
|
867
|
-
|
|
874
|
+
lines.push('✗ ' + oneWayLabel + ':' + oneWay.total + ' 篇 / ' + oneWay.edges + ' 条单向边' +
|
|
875
|
+
bodyNote +
|
|
868
876
|
' — ' + items.join(';') + (oneWay.total > items.length ? ' …' : ''));
|
|
869
877
|
}
|
|
870
878
|
lines.push(v.stale.total === 0
|
package/dist/lib/lint.js
CHANGED
|
@@ -290,6 +290,7 @@ export async function lintNotebook(cfg, opts = {}, signal) {
|
|
|
290
290
|
return 'body';
|
|
291
291
|
return starts.some((s) => s >= section.start && s < section.end) ? 'links' : 'body';
|
|
292
292
|
};
|
|
293
|
+
const linksOnly = opts.linksOnly === true;
|
|
293
294
|
const oneWayItems = [];
|
|
294
295
|
let oneWayEdges = 0;
|
|
295
296
|
let bodyOnly = 0;
|
|
@@ -301,29 +302,45 @@ export async function lintNotebook(cfg, opts = {}, signal) {
|
|
|
301
302
|
const target = byPath.get(row.target);
|
|
302
303
|
if (!target)
|
|
303
304
|
continue;
|
|
304
|
-
|
|
305
|
-
|
|
305
|
+
const all = [];
|
|
306
|
+
const links = [];
|
|
307
|
+
const body = [];
|
|
306
308
|
for (const source of row.from) {
|
|
307
|
-
|
|
309
|
+
all.push(source.path);
|
|
308
310
|
if (whereOf(source.path, source.snippetStarts) === 'links')
|
|
309
|
-
links
|
|
310
|
-
else
|
|
311
|
-
body
|
|
312
|
-
|
|
313
|
-
|
|
311
|
+
links.push(source.path);
|
|
312
|
+
else
|
|
313
|
+
body.push(source.path);
|
|
314
|
+
}
|
|
315
|
+
// bodyOnly 始终统计全部正文边:linksOnly 时它们被隐藏,但要让调用方知道有多少
|
|
316
|
+
bodyOnly += body.length;
|
|
317
|
+
if (linksOnly && links.length === 0)
|
|
318
|
+
continue;
|
|
319
|
+
if (linksOnly) {
|
|
320
|
+
oneWayEdges += links.length;
|
|
321
|
+
oneWayItems.push({
|
|
322
|
+
title: target.title,
|
|
323
|
+
path: target.path,
|
|
324
|
+
from: links,
|
|
325
|
+
where: 'links',
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
oneWayEdges += all.length;
|
|
330
|
+
oneWayItems.push({
|
|
331
|
+
title: target.title,
|
|
332
|
+
path: target.path,
|
|
333
|
+
from: all,
|
|
334
|
+
where: links.length === 0 ? 'body' : body.length === 0 ? 'links' : 'mixed',
|
|
335
|
+
});
|
|
314
336
|
}
|
|
315
|
-
oneWayItems.push({
|
|
316
|
-
title: target.title,
|
|
317
|
-
path: target.path,
|
|
318
|
-
from: row.from.map((s) => s.path),
|
|
319
|
-
where: links === 0 ? 'body' : body === 0 ? 'links' : 'mixed',
|
|
320
|
-
});
|
|
321
337
|
}
|
|
322
338
|
oneWayItems.sort((a, b) => a.path.localeCompare(b.path));
|
|
323
339
|
const oneWayBucket = {
|
|
324
340
|
total: oneWayItems.length,
|
|
325
341
|
edges: oneWayEdges,
|
|
326
342
|
bodyOnly,
|
|
343
|
+
linksOnly,
|
|
327
344
|
items: oneWayItems.slice(0, MAX_ITEMS),
|
|
328
345
|
};
|
|
329
346
|
const parseErrors = parseErrorWarnings(cfg, warnings);
|
|
@@ -82,9 +82,10 @@ YAML 独有的转义(`\N`、`\_`)不是合法 JSON,退回「去掉引号
|
|
|
82
82
|
不用 zk 的 `--missing-backlink`:它的原义是「至少有一条单向链接」,日记天然是一串出边,
|
|
83
83
|
日记提过的每篇笔记都会常年挂在桶里 —— 那不是「没接上」,是正常的引用方向,桶就再也清零不了。
|
|
84
84
|
普通笔记链到日记("今天做了 X")同理,不要求日记回链。
|
|
85
|
-
`oneWayLinks.items` 是缺回链的目标 X(不是来源),`from` 是没被 X 回链的来源 S;`edges`
|
|
85
|
+
`oneWayLinks.items` 是缺回链的目标 X(不是来源),`from` 是没被 X 回链的来源 S;`edges` 是列出的单向边数,
|
|
86
86
|
`where` / `bodyOnly` 标出其中来自正文引用(不在 `## Links` / `## 链接` 小节)的部分 —— 正文引用天然常单向,
|
|
87
|
-
|
|
87
|
+
单独计数,方便判断该不该补回链。`zk_lint(links_only=true)` / `zk-kit lint --links-only` 只列 Links 小节的单向边,
|
|
88
|
+
正文引用只进 `bodyOnly`;默认 `false`,仍然全报。
|
|
88
89
|
`parseErrors` 单列一类:frontmatter 写坏(典型是 `tags: [#你好世界]` —— YAML 里 `#` 不是 tag 前缀,要写 `tags: ["你好世界"]`)
|
|
89
90
|
时 zk 以 exit 0 跳过那篇、只往 stderr 打一行 `error parsing note content`,于是它不在索引里 ——
|
|
90
91
|
搜不到,也不会出现在上面任何一个桶里(表现成邻居突然孤儿 / 断链)。`zk()` 收 exit 0 的 stderr warning,
|