Skip to content

keyboard ⬅️➡️ cannot switch pics in dataview #9

@nevler2003-prog

Description

@nevler2003-prog
const targetName = dv.current().file.name;
const pages = dv.pages(`[[${targetName}]]`).where(p => p.file.name !== targetName);
let rows = [];

for (let page of pages) {
    const content = await dv.io.load(page.file.path);
    const lines = content.split("\n");

    for (let i = 0; i < lines.length; i++) {
        if (lines[i].includes(`[[${targetName}]]`)) {
            // 向上回溯 5 行找图片
            let targetLine = "";
            for (let j = 1; j <= 5; j++) {
                if (i - j >= 0 && lines[i - j].includes("![[")) {
                    targetLine = lines[i - j];
                    break;
                }
            }
            if (!targetLine) continue;

            // 图片提取
            let imgList = [...targetLine.matchAll(/!\[\[(.*?)\]\]/g)]
                .map(m => dv.fileLink(m[1].split("|")[0], true, 100));
            let imgColumn = imgList.length > 0 ? dv.el("div", imgList, { cls: "custom-img-row" }) : "❌";

            // 时间链接
            let timeMatch = targetLine.match(/\[(\d{2}:\d{2})\]\((.*?)\)/);
            let timeLink = timeMatch ? `[${timeMatch[1]}](${timeMatch[2]})` : "🔗";

            // 文字提取
            let analysisText = targetLine
                .replace(/!\[\[.*?\]\]/g, "")
                .replace(/\[\d{2}:\d{2}\]\(.*?\)/g, "")
                .replace(/^- /, "")
                .trim();

            rows.push([imgColumn, timeLink, page.file.link, analysisText]);
        }
    }
}

dv.table(["📸截图", "⏱️", "🎬 来源", "📝 标注"], rows);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions