feat: render source pipeline in left pane

This commit is contained in:
meels
2026-07-28 13:23:40 +02:00
parent 7958d225d5
commit 1045082df6
2 changed files with 228 additions and 3 deletions

View File

@@ -76,15 +76,118 @@ function parseConfig(source) {
return cfg;
}
const ICONS = {
terminal: "M4 17l6-6-6-6M12 19h8",
check: "M20 6 9 17l-5-5",
minus: "M5 12h14",
x: "M18 6 6 18M6 6l12 12",
refresh: "M3 12a9 9 0 0 1 9-9 9 9 0 0 1 6.7 3L21 8M21 3v5h-5 M21 12a9 9 0 0 1-9 9 9 9 0 0 1-6.7-3L3 16M3 21v-5h5",
};
// Built with createElementNS rather than Obsidian's createSvg helper, whose
// availability varies by version. This works on any Obsidian build.
const SVG_NS = "http://www.w3.org/2000/svg";
function addIcon(parent, name) {
const svg = document.createElementNS(SVG_NS, "svg");
svg.setAttribute("viewBox", "0 0 24 24");
svg.setAttribute("fill", "none");
svg.setAttribute("aria-hidden", "true");
const path = document.createElementNS(SVG_NS, "path");
path.setAttribute("d", ICONS[name]);
path.setAttribute("stroke", "currentColor");
path.setAttribute("stroke-width", "1.75");
path.setAttribute("stroke-linecap", "round");
path.setAttribute("stroke-linejoin", "round");
svg.appendChild(path);
parent.appendChild(svg);
return svg;
}
function formatBytes(n) {
return `${n.toLocaleString("en-US")} B`;
}
function renderLeftPane(container, pipeline, onIngest) {
const pane = container.createDiv({ cls: "wd-pane" });
const queue = pane.createDiv({ cls: "wd-block" });
queue.createDiv({
cls: "wd-eyebrow",
text: `Queue — ${pipeline.unprocessed.length} unprocessed`,
});
if (pipeline.unprocessed.length === 0) {
queue.createDiv({ cls: "wd-note", text: "Every raw source has a summary page." });
}
for (const file of pipeline.unprocessed) {
const row = queue.createDiv({ cls: "wd-row" });
const main = row.createDiv({ cls: "wd-row-main" });
main.createDiv({ cls: "wd-row-name", text: file.name });
main.createDiv({ cls: "wd-mono", text: formatBytes(file.size) });
const btn = row.createEl("button", { cls: "wd-btn" });
addIcon(btn, "terminal");
btn.createSpan({ text: "Ingest" });
btn.addEventListener("click", () => onIngest(file, row));
}
const done = pane.createDiv({ cls: "wd-block" });
done.createDiv({ cls: "wd-eyebrow", text: `Ingested — ${pipeline.processed.length}` });
const list = done.createDiv({ cls: "wd-done" });
for (const file of pipeline.processed) {
const row = list.createDiv({ cls: "wd-done-row" });
const date = file.page.name.slice(0, 10);
row.createSpan({ cls: "wd-mono", text: /^\d{4}-\d{2}-\d{2}$/.test(date) ? date : "—" });
row.createSpan({ cls: "wd-done-name", text: file.name.replace(/\.md$/, "") });
}
if (pipeline.orphaned.length > 0) {
const orphan = pane.createDiv({ cls: "wd-block" });
orphan.createDiv({
cls: "wd-eyebrow",
text: `Orphaned — ${pipeline.orphaned.length}`,
});
for (const page of pipeline.orphaned) {
const row = orphan.createDiv({ cls: "wd-done-row" });
row.createSpan({ cls: "wd-done-name", text: page.name });
row.createSpan({ cls: "wd-mono", text: page.rawPath || "no raw path" });
}
}
return pane;
}
class WebinarDashPlugin extends PluginBase {
async onload() {
this.registerMarkdownCodeBlockProcessor("webinar-dash", (source, el, ctx) => {
this.registerMarkdownCodeBlockProcessor("webinar-dash", async (source, el, ctx) => {
const cfg = parseConfig(source);
const root = el.createDiv({ cls: "webinar-dash" });
root.createDiv({ cls: "wd-eyebrow", text: "Webinar dashboard" });
root.createEl("p", { text: `Reading coverage from ${cfg.coverage}` });
try {
const pipeline = await this.readPipeline(cfg);
renderLeftPane(root, pipeline, () => {});
} catch (err) {
root.createDiv({ cls: "wd-error", text: `Dashboard failed: ${err.message}` });
}
});
}
async readPipeline(cfg) {
const all = this.app.vault.getFiles();
const rawDir = cfg.rawDir.replace(/\/+$/, "") + "/";
const wikiDir = cfg.wikiSourceDir.replace(/\/+$/, "") + "/";
const rawFiles = all
.filter((f) => f.path.startsWith(rawDir) && f.extension === "md")
.map((f) => ({ path: f.path, name: f.name, size: f.stat.size }));
const pageFiles = all.filter((f) => f.path.startsWith(wikiDir) && f.extension === "md");
const sourcePages = [];
for (const f of pageFiles) {
const text = await this.app.vault.cachedRead(f);
sourcePages.push({ path: f.path, name: f.name, rawPath: extractRawPath(text) });
}
return derivePipeline({ rawFiles, sourcePages });
}
}
module.exports = WebinarDashPlugin;