diff --git a/src/private/Get-BloggerSession.ps1 b/src/private/Get-BloggerSession.ps1 index 68473ce..e3212bb 100644 --- a/src/private/Get-BloggerSession.ps1 +++ b/src/private/Get-BloggerSession.ps1 @@ -11,6 +11,7 @@ Function Get-BloggerSession PandocTemplate = "$($env:USERPROFILE)\\.PSBlogger\\template.html" PandocAdditionalArgs = "--html-q-tags --ascii" BlogId = $null + ExcludeLabels = @() } if (Test-Path $session.UserPreferences) diff --git a/src/public/Get-BloggerConfig.ps1 b/src/public/Get-BloggerConfig.ps1 index 7ab3291..0eefe29 100644 --- a/src/public/Get-BloggerConfig.ps1 +++ b/src/public/Get-BloggerConfig.ps1 @@ -11,5 +11,6 @@ Function Get-BloggerConfig PandocHtmlFormat = $BloggerSession.PandocHtmlFormat PandocAdditionalArgs = $BloggerSession.PandocAdditionalArgs BlogId = $BloggerSession.BlogId + ExcludeLabels = $BloggerSession.ExcludeLabels } } \ No newline at end of file diff --git a/src/public/Get-BloggerPost.ps1 b/src/public/Get-BloggerPost.ps1 index 91665e0..b570367 100644 --- a/src/public/Get-BloggerPost.ps1 +++ b/src/public/Get-BloggerPost.ps1 @@ -116,6 +116,11 @@ Function Get-BloggerPost { $frontMatter = [ordered]@{ postId = $result.id } + if ($result['labels']) { + $frontMatter['tags'] = $result.labels + } else { + $frontMatter['tags'] = @() + } $file = "$title.md" $filePath = Join-Path -Path $OutDirectory -ChildPath $file ConvertTo-MarkdownFromHtml -Content $result.content -OutFile $filePath > $null diff --git a/src/public/Publish-MarkdownBloggerPost.ps1 b/src/public/Publish-MarkdownBloggerPost.ps1 index 4d2f686..cf1b4d3 100644 --- a/src/public/Publish-MarkdownBloggerPost.ps1 +++ b/src/public/Publish-MarkdownBloggerPost.ps1 @@ -42,8 +42,12 @@ Function Publish-MarkdownBloggerPost [Parameter(Mandatory=$false)] [switch]$Draft, + [Parameter(Mandatory=$false)] + [array]$ExcludeLabels = @(), + [Parameter(Mandatory=$false)] [switch]$Force + ) if (!$PSBoundParameters.ContainsKey("BlogId")) @@ -54,6 +58,10 @@ Function Publish-MarkdownBloggerPost } } + if (!$PSBoundParameters.ContainsKey("ExcludeLabels")) { + $ExcludeLabels = $BloggerSession.ExcludeLabels + } + # grab the front matter $postInfo = Get-MarkdownFrontMatter -File $File @@ -79,7 +87,7 @@ Function Publish-MarkdownBloggerPost } if ($postInfo["tags"]) { - $postArgs.Labels = [array]$postInfo.tags + $postArgs.Labels = [array]$postInfo.tags | Where-Object { $_ -notin $ExcludeLabels } } $post = Publish-BloggerPost @postArgs diff --git a/src/public/Set-BloggerConfig.ps1 b/src/public/Set-BloggerConfig.ps1 index d54c928..d4e9619 100644 --- a/src/public/Set-BloggerConfig.ps1 +++ b/src/public/Set-BloggerConfig.ps1 @@ -3,12 +3,12 @@ Function Set-BloggerConfig [CmdletBinding()] Param( [Parameter(Mandatory=$true)] - [ValidateSet("BlogId","PandocAdditionalArgs","PandocHtmlFormat","PandocMarkdownFormat")] + [ValidateSet("BlogId","PandocAdditionalArgs","PandocHtmlFormat","PandocMarkdownFormat","ExcludeLabels")] [string]$Name, [Parameter(Mandatory=$true)] [AllowEmptyString()] - [string]$Value + $Value ) $userPreferences = [pscustomobject]@{} diff --git a/src/tests/Get-BloggerPost.Tests.ps1 b/src/tests/Get-BloggerPost.Tests.ps1 index 84ad198..0d396fc 100644 --- a/src/tests/Get-BloggerPost.Tests.ps1 +++ b/src/tests/Get-BloggerPost.Tests.ps1 @@ -184,6 +184,7 @@ Describe "Get-BloggerPost" { title = "Test Post" published = [datetime]"2023-10-01T17:30:00-04:00" content = "
This is a post.
" + labels = @("Azure DevOps", "Azure Pipelines") } } } @@ -200,7 +201,7 @@ Describe "Get-BloggerPost" { } } - It "Should write post details to frontmatter" { + It "Should write postid to frontmatter" { # act Get-BloggerPost -PostId $postId -Format Markdown -OutDirectory "TestDrive:\" @@ -209,6 +210,44 @@ Describe "Get-BloggerPost" { $frontMatter = Get-MarkdownFrontMatter -File $outFile $frontMatter.postId | Should -Be "123" } + + It "Should write labels to frontmatter" { + # act + Get-BloggerPost -PostId $postId -Format Markdown -OutDirectory "TestDrive:\" + + # assert + $frontMatter = Get-MarkdownFrontMatter -File $outFile + $frontMatter.tags.Count | Should -Be 2 + $frontMatter.tags[0] | Should -Be "Azure DevOps" + $frontMatter.tags[1] | Should -Be "Azure Pipelines" + } + + It "Should include empty tags in frontmatter if labels are not present" { + # arrange + InModuleScope PSBlogger { + # Mock the session to return a test blog ID + $BloggerSession.BlogId = "test-blog-id" + + $postId = "123" + + # mock post retrieval + Mock Invoke-GApi { + return @{ + id = $postId + title = "Test Post" + published = [datetime]"2023-10-01T17:30:00-04:00" + content = "This is a post.
" + } + } + } + # act + Get-BloggerPost -PostId $postId -Format Markdown -OutDirectory "TestDrive:\" + + # assert + $frontMatter = Get-MarkdownFrontMatter -File $outFile + $frontMatter['tags'] -eq $null | Should -BeFalse + $frontMatter['tags'] | Should -Be @() + } } Context "As Json" { @@ -280,6 +319,7 @@ Describe "Get-BloggerPost" { It "Should write file to specified formatted directory -