File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( ) ;
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments