Skip to content

Commit ab5f4fa

Browse files
authored
move the file to correct folder + fix a small bug (#253)
1 parent 60f2784 commit ab5f4fa

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

apps/obsidian/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default class DiscourseGraphPlugin extends Plugin {
6767
plugin: this,
6868
file,
6969
nodeType,
70+
title,
7071
});
7172
},
7273
}).open();

apps/obsidian/src/utils/createNode.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,15 @@ export const convertPageToDiscourseNode = async ({
144144
plugin,
145145
file,
146146
nodeType,
147+
title,
147148
}: {
148149
plugin: DiscourseGraphPlugin;
149150
file: TFile;
150151
nodeType: DiscourseNode;
152+
title?: string;
151153
}): Promise<void> => {
152154
try {
153-
const formattedNodeName = formatNodeName(file.basename, nodeType);
155+
const formattedNodeName = formatNodeName(title || file.basename, nodeType);
154156
if (!formattedNodeName) {
155157
new Notice("Failed to format node name", 3000);
156158
return;
@@ -166,12 +168,21 @@ export const convertPageToDiscourseNode = async ({
166168
fm.nodeTypeId = nodeType.id;
167169
});
168170

171+
let newPath = "";
172+
const folderPath = plugin.settings.nodesFolderPath.trim();
173+
if (folderPath) {
174+
const folderExists = plugin.app.vault.getAbstractFileByPath(folderPath);
175+
if (!folderExists) {
176+
await plugin.app.vault.createFolder(folderPath);
177+
}
178+
newPath = `${folderPath}/${formattedNodeName}.md`;
179+
} else {
169180
const dirPath = file.parent?.path ?? "";
170-
const newPath = dirPath
181+
newPath = dirPath
171182
? `${dirPath}/${formattedNodeName}.md`
172183
: `${formattedNodeName}.md`;
173-
await plugin.app.fileManager.renameFile(file, newPath);
174-
184+
}
185+
await plugin.app.fileManager.renameFile(file, newPath);
175186

176187
new Notice("Converted page to discourse node", 10000);
177188
} catch (error) {

0 commit comments

Comments
 (0)