(
folderTemplate: string,
options: FolderTemplateOptions = {}
)
| 223 | * ``` |
| 224 | */ |
| 225 | export function processFolderTemplate( |
| 226 | folderTemplate: string, |
| 227 | options: FolderTemplateOptions = {} |
| 228 | ): string { |
| 229 | if (!folderTemplate) { |
| 230 | return folderTemplate; |
| 231 | } |
| 232 | |
| 233 | const { |
| 234 | date = new Date(), |
| 235 | taskData, |
| 236 | icsData, |
| 237 | extractProjectBasename, |
| 238 | extractProjectFilePath, |
| 239 | } = options; |
| 240 | |
| 241 | let processedPath = folderTemplate; |
| 242 | const shouldNormalizeRelativeSegments = hasRelativePathSegments(folderTemplate); |
| 243 | |
| 244 | processedPath = replaceDailyNotesDateTokens(processedPath, date); |
| 245 | |
| 246 | // Replace task variables if taskData is provided |
| 247 | if (taskData) { |
| 248 | // Handle single context (first one if multiple) |
| 249 | const context = |
| 250 | Array.isArray(taskData.contexts) && taskData.contexts.length > 0 |
| 251 | ? taskData.contexts[0] |
| 252 | : ""; |
| 253 | processedPath = processedPath.replace(/\{\{context\}\}/g, context); |
| 254 | |
| 255 | // Handle single project (first one if multiple) |
| 256 | const project = |
| 257 | Array.isArray(taskData.projects) && taskData.projects.length > 0 |
| 258 | ? extractProjectBasename |
| 259 | ? extractProjectBasename(taskData.projects[0]) |
| 260 | : taskData.projects[0] |
| 261 | : ""; |
| 262 | processedPath = processedPath.replace(/\{\{project\}\}/g, project); |
| 263 | |
| 264 | // Handle multiple projects |
| 265 | const projects = |
| 266 | Array.isArray(taskData.projects) && taskData.projects.length > 0 |
| 267 | ? taskData.projects |
| 268 | .map((proj) => |
| 269 | extractProjectBasename ? extractProjectBasename(proj) : proj |
| 270 | ) |
| 271 | .join("/") |
| 272 | : ""; |
| 273 | processedPath = processedPath.replace(/\{\{projects\}\}/g, projects); |
| 274 | |
| 275 | // Handle full project file paths while preserving path separators |
| 276 | const projectFilePath = |
| 277 | Array.isArray(taskData.projects) && taskData.projects.length > 0 |
| 278 | ? getProjectFilePath(taskData.projects[0], extractProjectFilePath) |
| 279 | : ""; |
| 280 | processedPath = processedPath.replace(/\{\{projectFilePath\}\}/g, projectFilePath); |
| 281 | |
| 282 | const projectFilePaths = |
no test coverage detected