obsidian-wordpress icon indicating copy to clipboard operation
obsidian-wordpress copied to clipboard

发布的内容,都是读取某一篇笔记,能否读取的是dataview检索出来的内容呢?

Open weqoocu opened this issue 1 year ago • 1 comments

自己使用dataview 将很多的小卡片进行拼接,能否将dataview检索的内容,进行发布呢?

//输入目标小标题(含#),例如:#### 项目进度条
const header = '### 正文'

// 按【路径或文件夹、文件名、标签】筛选并按修改时间降序排列
const pages = dv.pages('[[obsidian.wordpress]]').filter(p => p.file.name.includes("") && p.file.path.includes("文献笔记")).filter(p => p.file.name.includes("") || p.file.name.includes("")).sort(p=>p.编码,"asc");

// This regex will return text from the Summary header, until it reaches
// the next header, a horizontal line, or the end of the file
const regex = new RegExp(`\n${header}\r?\n(.*?)(\n#+ |\n---|$)`, 's')

for (const page of pages) {
    const file = app.vault.getAbstractFileByPath(page.file.path)
    // Read the file contents
    const contents = await app.vault.read(file)
    // Extract the summary via regex
    const summary = contents.match(regex)
    //显示全部包括空结果if (summary) {
    //不显示空结果if (summary && summary[1].trim()) {
    if (summary && summary[1].trim()) {
        // Output the header and summary
        //dv.header(3, '[['+ file.basename + '|'+page.编码+' '+page.需求+']]')
        dv.header(3, page.编码+' '+page.需求)
        //或者dv.header(2, '[[' + file.basename + ']]')
        dv.paragraph(summary[1].trim())
    }
}

weqoocu avatar Jan 18 '24 09:01 weqoocu

发布的时候,求支持dataview解析出来

weqoocu avatar May 06 '24 11:05 weqoocu