diff --git a/Test/public/newNotes.test.ps1 b/Test/public/newNotes.test.ps1 index 4ec4b0d..b36d4c8 100644 --- a/Test/public/newNotes.test.ps1 +++ b/Test/public/newNotes.test.ps1 @@ -107,13 +107,14 @@ function Test_AddNotesToday_Client_Simple{ MockCallToString 'Invoke-NotesHelperNotesRoot' -OutString "./TestNotesRoot" $category = "Clients" + $clientName = "TestClientName" $title = "This is the title of the note" $date = (Get-Date).ToString("yyMMdd") $clientName = "TestClientName" - $header = "# {category} - {title} ({date})" - $header = $header -replace "{category}", $category + $header = "# {header} - {title} ({date})" + $header = $header -replace "{header}", $clientName $header = $header -replace "{title}", $title $header = $header -replace "{date}", $date diff --git a/public/newNotes.ps1 b/public/newNotes.ps1 index d8d440a..34094af 100644 --- a/public/newNotes.ps1 +++ b/public/newNotes.ps1 @@ -31,10 +31,10 @@ function New-NoteToday{ # Extract just the folder name from the path $today = Get-Date -Format "yyMMdd" - $titleHeader = [string]::IsNullOrWhiteSpace($Section) ? $Category : $Section + $header = [string]::IsNullOrWhiteSpace($Section) ? $Category : $Section # Create FullTitle using folder name and title, replacing spaces with underscores - $fullTitle = "{0}-{1}-{2}" -f $today, $titleHeader, $Title + $fullTitle = "{0}-{1}-{2}" -f $today, $header, $Title # Normilize fullTitle by removing special characters and replacing spaces with underscores $fullTitle = $fullTitle -replace '\s+', '_' @@ -64,7 +64,7 @@ function New-NoteToday{ # Replace placeholders in the template with actual values $content = $content -replace '{title}' , $Title - $content = $content -replace '{categoryname}', $category + $content = $content -replace '{header}' , $header $content = $content -replace '{date}' , $today $content = $content -replace '{notes}' , ([string]::IsNullOrWhiteSpace($Notes) ? '-' : $Notes) $content = $content -replace '{issueurl}' , ([string]::IsNullOrWhiteSpace($IssueUrl) ? '' : $IssueUrl) @@ -133,77 +133,41 @@ function New-NoteTodayClient{ } Export-ModuleMember -Function New-NoteTodayClient -Alias cnote -function NewNoteToday{ - # Add Force parameter to support creation of client folder if it doesn't exist +function New-NoteTodayMeeting{ [CmdletBinding()] - [alias("note")] + [alias("mnote")] param( - [Parameter(Mandatory)][string] $Category, - [Parameter(Mandatory)][string] $Section, - [Parameter(Mandatory)][string] $Title, - [Parameter()][string] $Notes, - [Parameter()][string] $IssueUrl, - [Parameter()][string] [ValidateSet("none","meetingmini")] $Template = "none", + [Parameter(Mandatory,Position = 0)][string] $Name, + [Parameter(Mandatory,Position = 1)][string] $Title, + [Parameter(Position = 2)][string] $Notes, + [Parameter(ValueFromPipeline)][string] $IssueUrl, [Parameter()][switch] $NoOpen, - [Parameter()][switch] $AvoidChildFolder, [Parameter()][switch] $Force ) - # FILENAME - - $folder = Get-NoteFolder -Category $Category -Section $Section -Force:$Force - - # Extract just the folder name from the path - $today = Get-Date -Format "yyMMdd" - - # Create FullTitle using folder name and title, replacing spaces with underscores - $fullTitle = "{0}-{1}-{2}" -f $today, $category, $Title - - # Normilize fullTitle by removing special characters and replacing spaces with underscores - $fullTitle = $fullTitle -replace '\s+', '_' - - if($AvoidChildFolder){ - # use folder as the parent folder of the note - $fullPath = Join-Path -Path $folder -ChildPath "$fullTitle.md" - } else { - # Create full path for the note file - $fullPath = Join-Path -Path $folder -ChildPath $fullTitle | Join-Path -ChildPath "$fullTitle.md" + begin { + $category = "meetings" + $section = $Name } - - # Check if file already exists - if (-Not (Test-Path -Path $fullPath)) { - - # Get template content - $content = Get-TemplatePath $Template | Get-FileContent - - # Replace placeholders in the template with actual values - $content = $content -replace '{title}' , $Title - $content = $content -replace '{categoryname}', $category - $content = $content -replace '{date}' , $today - $content = $content -replace '{notes}' , ([string]::IsNullOrWhiteSpace($Notes) ? '-' : $Notes) - $content = $content -replace '{issueurl}' , ([string]::IsNullOrWhiteSpace($IssueUrl) ? '' : $IssueUrl) + process{ - # If $Force check that the folders of $fullPath exists and if not create it - if ($Force) { - $parentFolder = Split-Path -Path $fullPath -Parent - if (-Not (Test-Path -Path $parentFolder)) { - New-Item -Path $parentFolder -ItemType Directory -Force | Out-Null - Write-Verbose "Created folder: $parentFolder" - } + $folder = Get-NoteFolder -Category $category -Section $section -Force:$Force + + if (-not $folder) { + Write-Error "Client folder for '$section' does not exist and Force was not specified." + return } - # Create the file with content - Set-Content -Path $fullPath -Value $content -Force - } - - if( -not $NoOpen) { - # Open file in VS Code with cursor at the end - $gotocmd = "{0}{1}" -f $fullPath, ":9999" - code --goto $gotocmd + New-NoteToday ` + -Category $category ` + -Section $section ` + -Title $Title ` + -Notes $Notes ` + -IssueUrl $IssueUrl ` + -Template "meetingmini" ` + -NoOpen:$NoOpen ` + -AvoidChildFolder # Add all the notes in the same client folder } - # Return file just created - return $fullPath - -} \ No newline at end of file +} Export-ModuleMember -Function New-NoteTodayMeeting -Alias mnote \ No newline at end of file diff --git a/public/notes/templates/meetingmini.template.md b/public/notes/templates/meetingmini.template.md index bc29e8c..ec376e7 100644 --- a/public/notes/templates/meetingmini.template.md +++ b/public/notes/templates/meetingmini.template.md @@ -1,4 +1,4 @@ -# {categoryname} - {title} ({date}) +# {header} - {title} ({date}) > {issueurl} diff --git a/public/notes/templates/none.template.md b/public/notes/templates/none.template.md index 6ef3db6..27e88b1 100644 --- a/public/notes/templates/none.template.md +++ b/public/notes/templates/none.template.md @@ -1,4 +1,4 @@ -# {categoryname} - {title} ({date}) +# {header} - {title} ({date}) > {issueurl}