遇到的问题
使用 dataviewjs 设置二级标题,但是 obsidian 中无法是被这样的目录,看着是 dataviewjs 生成的内容被强制缩进了?所以没法识别,有没有办法解除强制缩进
我的 dataview 片段:
const pages = dv.pages('"ROS"')
.where(p => p.categories && p.categories.length > 1);
function createCategoryStructure(categories, page) {
let current = categorizedPages;
for (let i = 1; i < categories.length; i++) {
const category = categories[i];
if (!current[category]) {
current[category] = { pages: [], subcategories: {} };
}
current[category].pages.push(page);
current = current[category].subcategories;
}
}
const categorizedPages = {};
for (const page of pages) {
if (page.categories && page.categories.length > 1) {
createCategoryStructure(page.categories, page);
}
}
function generateNestedList(structure, level = 0) {
let result = '';
const sortedCategories = Object.keys(structure).sort();
for (const category of sortedCategories) {
if (level === 0) {
// 使用二级标题来展示第二级分类
result += `## ${category}\n\n`;
} else {
result += ' '.repeat(level - 1) + `- **${category}**\n`;
}
if (structure[category].pages.length > 0) {
structure[category].pages.forEach(page => {
result += ' '.repeat(Math.max(level, 1)) + `- ${page.file.link}\n`;
});
}
if (Object.keys(structure[category].subcategories).length > 0) {
result += generateNestedList(structure[category].subcategories, level + 1);
}
}
return result;
}
const nestedList = generateNestedList(categorizedPages);
dv.paragraph(nestedList);