File tree Expand file tree Collapse file tree 3 files changed +25
-36
lines changed
Expand file tree Collapse file tree 3 files changed +25
-36
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import {
1717import { log } from "../logger/logManager" ;
1818import { encodeToBase64 } from "../utils/base64" ;
1919import { deepClone } from "../utils/deepClone" ;
20+ import { ensureParentFolders } from "../utils/ensureParentFolders" ;
2021
2122export interface BuildPackageOptions {
2223 choices : IChoice [ ] ;
@@ -209,22 +210,3 @@ export async function writePackageToVault(
209210 const serialized = JSON . stringify ( pkg , null , 2 ) ;
210211 await app . vault . adapter . write ( normalizedPath , serialized ) ;
211212}
212-
213- async function ensureParentFolders ( app : App , filePath : string ) : Promise < void > {
214- const lastSlash = filePath . lastIndexOf ( "/" ) ;
215- if ( lastSlash < 0 ) return ;
216-
217- const folderPath = filePath . slice ( 0 , lastSlash ) ;
218- if ( ! folderPath ) return ;
219-
220- const segments = folderPath . split ( "/" ) . filter ( Boolean ) ;
221- let current = "" ;
222-
223- for ( const segment of segments ) {
224- current = current ? `${ current } /${ segment } ` : segment ;
225- const exists = await app . vault . adapter . exists ( current ) ;
226- if ( ! exists ) {
227- await app . vault . createFolder ( current ) ;
228- }
229- }
230- }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { CommandType } from "../types/macros/CommandType";
2121import { log } from "../logger/logManager" ;
2222import { decodeFromBase64 } from "../utils/base64" ;
2323import { deepClone } from "../utils/deepClone" ;
24+ import { ensureParentFolders } from "../utils/ensureParentFolders" ;
2425
2526export interface LoadedQuickAddPackage {
2627 pkg : QuickAddPackage ;
@@ -562,23 +563,6 @@ function findMultiByPath(
562563 return currentMulti ;
563564}
564565
565- async function ensureParentFolders ( app : App , filePath : string ) : Promise < void > {
566- const lastSlash = filePath . lastIndexOf ( "/" ) ;
567- if ( lastSlash < 0 ) return ;
568- const folderPath = filePath . slice ( 0 , lastSlash ) ;
569- if ( ! folderPath ) return ;
570-
571- const segments = folderPath . split ( "/" ) . filter ( Boolean ) ;
572- let current = "" ;
573- for ( const segment of segments ) {
574- current = current ? `${ current } /${ segment } ` : segment ;
575- const exists = await app . vault . adapter . exists ( current ) ;
576- if ( ! exists ) {
577- await app . vault . createFolder ( current ) ;
578- }
579- }
580- }
581-
582566function applyAssetPathOverrides (
583567 choice : IChoice ,
584568 pathOverrides : Map < string , string > ,
Original file line number Diff line number Diff line change 1+ import type { App } from "obsidian" ;
2+
3+ export async function ensureParentFolders (
4+ app : App ,
5+ filePath : string ,
6+ ) : Promise < void > {
7+ const lastSlash = filePath . lastIndexOf ( "/" ) ;
8+ if ( lastSlash < 0 ) return ;
9+
10+ const folderPath = filePath . slice ( 0 , lastSlash ) ;
11+ if ( ! folderPath ) return ;
12+
13+ const segments = folderPath . split ( "/" ) . filter ( Boolean ) ;
14+ let current = "" ;
15+
16+ for ( const segment of segments ) {
17+ current = current ? `${ current } /${ segment } ` : segment ;
18+ const exists = await app . vault . adapter . exists ( current ) ;
19+ if ( ! exists ) {
20+ await app . vault . createFolder ( current ) ;
21+ }
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments