Appearance
VSCode 扩展推荐
1. 扩展推荐
- EditorConfig for VS Code
- Encode Decode
- Foam
- Git Graph
- Git History
- gitignore
- GitLens — Git supercharged
- Go
- Increment Selection
- Insert GUID
- Lua
- Markdown All in One
- Markdown Image
- Markdown Preview Enhanced
- markdownlint
- Remote - SSH
- Remote - SSH: Editing Config
- Remote Explorer
- XML Tools
2. 推荐设置
2.1. Foam
2.1.1. 标签图谱
2.1.1.1. 插件源码修改
打开 C:\Users\Username\.vscode\extensions\foam.foam-vscode-0.26.12\static\dataviz\graph.js,找到 augmentGraphInfo 函数,将其替换为:
JavaScript
function augmentGraphInfo(graph) {
const tagNodes = {};
Object.values(graph.nodeInfo).forEach(node => {
if (node.type === 'tag') {
tagNodes[node.title] = node;
}
node.neighbors = [];
node.links = [];
});
Object.values(graph.nodeInfo).forEach(node => {
if (node.tags && node.tags.length > 0) {
node.tags.forEach(tag => {
subtags = tag.label.split('/');
for (let i = 0; i < subtags.length; i++) {
const label = subtags.slice(0, i + 1).join('/');
if (!tagNodes[label]) {
const tagNode = {
id: label,
title: label,
type: 'tag',
properties: {},
neighbors: [],
links: [],
};
graph.nodeInfo[tagNode.id] = tagNode;
tagNodes[tagNode.id] = tagNode;
}
if (i > 0) {
const parent = subtags.slice(0, i).join('/');
graph.links.push({
source: parent,
target: label,
});
}
}
graph.links.push({
source: tagNodes[tag.label].id,
target: node.id,
});
});
}
});
graph.links = Array.from(
new Set(graph.links.map(link => JSON.stringify(link)))
).map(link => JSON.parse(link));
graph.links.forEach(link => {
const a = graph.nodeInfo[link.source];
const b = graph.nodeInfo[link.target];
a.neighbors.push(b.id);
b.neighbors.push(a.id);
a.links.push(link);
b.links.push(link);
});
return graph;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
差异对比
diff
@@ -1,21 +1,30 @@
function augmentGraphInfo(graph) {
+ const tagNodes = {};
Object.values(graph.nodeInfo).forEach(node => {
+ if (node.type === 'tag') {
+ tagNodes[node.title] = node;
+ }
node.neighbors = [];
node.links = [];
+ });
+ Object.values(graph.nodeInfo).forEach(node => {
if (node.tags && node.tags.length > 0) {
node.tags.forEach(tag => {
subtags = tag.label.split('/');
for (let i = 0; i < subtags.length; i++) {
const label = subtags.slice(0, i + 1).join('/');
- const tagNode = {
- id: label,
- title: label,
- type: 'tag',
- properties: {},
- neighbors: [],
- links: [],
- };
- graph.nodeInfo[tagNode.id] = tagNode;
+ if (!tagNodes[label]) {
+ const tagNode = {
+ id: label,
+ title: label,
+ type: 'tag',
+ properties: {},
+ neighbors: [],
+ links: [],
+ };
+ graph.nodeInfo[tagNode.id] = tagNode;
+ tagNodes[tagNode.id] = tagNode;
+ }
if (i > 0) {
const parent = subtags.slice(0, i).join('/');
graph.links.push({
@@ -25,12 +34,15 @@
}
}
graph.links.push({
- source: tag.label,
+ source: tagNodes[tag.label].id,
target: node.id,
});
});
}
});
+ graph.links = Array.from(
+ new Set(graph.links.map(link => JSON.stringify(link)))
+ ).map(link => JSON.parse(link));
graph.links.forEach(link => {
const a = graph.nodeInfo[link.source];
const b = graph.nodeInfo[link.target];2.1.1.2. 使用方法
新建一个 Markdown 文档,正文内容为空,仅包含以下元数据:
Markdown
---
type: tag
tags:
- tag1
- tag2
---type:声明文档类型为tag;tags:声明文档关联的标签。
最终效果:
- 该文档的名称在 Foam Graph 中将被视为一个标签节点;
- 该文档将会关联
tags中声明的所有标签。