技术栈

技术栈

更新时间:2025-01-02 7:42

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
56
57
58
59
60
61
62
const {createButton} = app.plugins.plugins["buttons"]

const currentFolder = dv.current().file.folder
const groups = dv.pages(`"${currentFolder}"`).sort(p => p.file.name, 'esc').groupBy(p => p.file.folder)
//不想展示的文件夹
const folderArr = ["MOD","后端","python"]
let result = [];
for (let group of groups) {
if (group.key!="Codes" && folderArr.filter(f => group.key.includes(f)).length == 0) {
const pages = dv.pages(`"${group.key}"`).sort(p => p.file.name, 'esc')
for (let page of pages) {
const content =await dv.io.load(page.file.link)
const headings = content.match(/^##+ .*$/gm);
let item2 = "--"
if(headings){
item2 = headings.map(function(heading){
const regex = /(^#+)(\s?)/g;
const replacedText = heading.replace(regex, function(match, p1, p2) {
return `${p2}`;
//if (p1.length == 2) {
// return `${p2}`;
// } else{
// return `${' '.repeat(p1.length-2)}🔸${p2}`;
// }
});
return replacedText
})
}
result.push([group.key.replace("Codes/",""),`${page.file.name}`,item2]);
}
}
}
dv.table(["文件","一级目录","二级目录"], result);
const table = dv.markdownList(["文件","一级目录","二级目录"], result)
async function copyPageUrl(text) {
try {
await navigator.clipboard.writeText(text);
console.log('Page URL copied to clipboard');
} catch (err) {
console.error('Failed to copy: ', err);
}
}
function replaceMarkdownHeadings(text) {
const regex = /(^|\n)(#{1,6})/g;
const replacer = (match, p1, p2) => {
const hashCount = p2.length;
return p1 + ' '.repeat(hashCount) + '-'.repeat(hashCount);
};
return text.replace(regex, replacer);
}
dv.paragraph(createButton({
app,
el: this.container,
args: {
name: '复制 MD table ',
class:'tiny'
},
clickOverride: {
click: copyPageUrl,
params: [table]
}
}))