From 15385b0129374bc2d1137f576f79cc4f624ba2bf Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 18 Jan 2026 13:45:38 +0100 Subject: [PATCH] Enhance export functionality in Mindnet plugin - Introduced configurable export path for graph JSON files, allowing users to specify a custom location. - Added checks to ensure the output directory exists before exporting, improving reliability. - Updated settings interface to include export path configuration, enhancing user experience with clearer options for managing export settings. --- src/export/exportGraph.ts | 9 ++++++ src/main.ts | 8 +++++- src/settings.ts | 3 ++ src/ui/MindnetSettingTab.ts | 56 +++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/export/exportGraph.ts b/src/export/exportGraph.ts index 6532d7d..2d8ba31 100644 --- a/src/export/exportGraph.ts +++ b/src/export/exportGraph.ts @@ -3,6 +3,7 @@ import type { Vocabulary } from "../vocab/Vocabulary"; import type { ParsedEdge } from "../parser/types"; import type { ExportBundle, ExportNode, ExportEdge } from "./types"; import { parseEdgesFromCallouts } from "../parser/parseEdgesFromCallouts"; +import { ensureFolderExists } from "../mapping/folderHelpers"; /** * Export graph from vault markdown files. @@ -128,6 +129,14 @@ export async function exportGraph( }, }; + // Ensure output directory exists + const pathParts = outputPath.split("/"); + if (pathParts.length > 1) { + // Extract directory path (everything except the filename) + const directoryPath = pathParts.slice(0, -1).join("/"); + await ensureFolderExists(app, directoryPath); + } + // Write to file const jsonContent = JSON.stringify(bundle, null, 2); await app.vault.adapter.write(outputPath, jsonContent); diff --git a/src/main.ts b/src/main.ts index b44f8a2..43e7eb0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -187,7 +187,7 @@ export default class MindnetCausalAssistantPlugin extends Plugin { return; } - const outputPath = "_system/exports/graph_export.json"; + const outputPath = this.settings.exportPath || "_system/exports/graph_export.json"; await exportGraph(this.app, vocabulary, outputPath); new Notice(`Graph exported to ${outputPath}`); @@ -278,6 +278,12 @@ export default class MindnetCausalAssistantPlugin extends Plugin { // Write report file const reportPath = "_system/exports/chain_report.md"; + // Ensure output directory exists + const pathParts = reportPath.split("/"); + if (pathParts.length > 1) { + const directoryPath = pathParts.slice(0, -1).join("/"); + await ensureFolderExists(this.app, directoryPath); + } await this.app.vault.adapter.write(reportPath, report); // Open report diff --git a/src/settings.ts b/src/settings.ts index 79bf2f6..5ed7d2b 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -30,6 +30,8 @@ export interface MindnetSettings { inlineMicroEnabled: boolean; // default: true inlineMaxAlternatives: number; // default: 6 inlineCancelBehavior: "keep_link"; // default: "keep_link" (future: "revert") + // Export settings + exportPath: string; // default: "_system/exports/graph_export.json" } export const DEFAULT_SETTINGS: MindnetSettings = { @@ -62,6 +64,7 @@ export interface MindnetSettings { inlineMicroEnabled: true, inlineMaxAlternatives: 6, inlineCancelBehavior: "keep_link", + exportPath: "_system/exports/graph_export.json", }; /** diff --git a/src/ui/MindnetSettingTab.ts b/src/ui/MindnetSettingTab.ts index 1af9f8c..afcb9eb 100644 --- a/src/ui/MindnetSettingTab.ts +++ b/src/ui/MindnetSettingTab.ts @@ -640,5 +640,61 @@ export class MindnetSettingTab extends PluginSettingTab { await this.plugin.saveSettings(); }) ); + + // ============================================ + // 9. Export + // ============================================ + containerEl.createEl("h3", { text: "📤 Export" }); + containerEl.createEl("p", { + text: "Einstellungen für den Graph-Export.", + cls: "setting-item-description", + }); + + // Export path + new Setting(containerEl) + .setName("Export path") + .setDesc( + "Pfad für die exportierte Graph-JSON-Datei. Die Datei enthält alle Knoten (Nodes) und Kanten (Edges) aus dem Vault." + ) + .addText((text) => + text + .setPlaceholder("_system/exports/graph_export.json") + .setValue(this.plugin.settings.exportPath) + .onChange(async (value) => { + this.plugin.settings.exportPath = value || "_system/exports/graph_export.json"; + await this.plugin.saveSettings(); + }) + ) + .addButton((button) => + button + .setButtonText("Export now") + .setCta() + .onClick(async () => { + try { + // Load vocabulary using the same method as the command + const { VocabularyLoader } = await import("../vocab/VocabularyLoader"); + const { parseEdgeVocabulary } = await import("../vocab/parseEdgeVocabulary"); + const { Vocabulary } = await import("../vocab/Vocabulary"); + + const text = await VocabularyLoader.loadText( + this.app, + this.plugin.settings.edgeVocabularyPath + ); + + const parsed = parseEdgeVocabulary(text); + const vocabulary = new Vocabulary(parsed); + + const { exportGraph } = await import("../export/exportGraph"); + await exportGraph(this.app, vocabulary, this.plugin.settings.exportPath); + + new Notice(`Graph exported to ${this.plugin.settings.exportPath}`); + console.log(`Graph exported: ${this.plugin.settings.exportPath}`); + } catch (e) { + const msg = e instanceof Error ? e.message : String(e); + new Notice(`Failed to export graph: ${msg}`); + console.error(e); + } + }) + ); } }