






















实例结果示意:
# Linked 。
以下为代码。
直接复制,替换目标文件夹 与# 标题名 后,即可使用。
```dataviewjs
function naturalCompare(a, b) {
const removeLeadingZeros = s => s.replace(/(\d+)/g, n => n.padStart(10, '0'));
return removeLeadingZeros(a).localeCompare(removeLeadingZeros(b));
}
const folderPath = "目标文件夹";
const pages = dv.pages(`"${folderPath}"`);
let results = [];
for (const page of pages) {
const file = app.vault.getAbstractFileByPath(page.file.path);
if (file) {
const fileContent = await app.vault.read(file);
const lines = fileContent.split('\n');
let capture = false;
let linkedContent = "";
for (const line of lines) {
if (line.startsWith("# 标题名")) {
capture = true;
continue;
}
if (capture && line.startsWith("#")) {
capture = false;
}
if (capture) {
linkedContent += line + "\n";
}
}
if (linkedContent.trim()) {
results.push({ name: page.file.name, path: page.file.path, content: linkedContent });
}
} else {
console.log("未找到文件: " + page.file.path);
}
}
results.sort((a, b) => naturalCompare(a.name, b.name));
for (const result of results) {
const fileLink = `[${result.name}](obsidian://open?vault=${app.vault.getName()}&file=${encodeURIComponent(result.path)})`;
dv.header(3, fileLink);
dv.paragraph(result.content);
}
```此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。