From 5f93fc095b3ddd0435030c2262b67dc296ffafd2 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:11:49 -0400 Subject: [PATCH 1/4] Get-BloggerPost markdown includes labels --- src/public/Get-BloggerPost.ps1 | 1 + src/tests/Get-BloggerPost.Tests.ps1 | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/public/Get-BloggerPost.ps1 b/src/public/Get-BloggerPost.ps1 index 91665e0..3798546 100644 --- a/src/public/Get-BloggerPost.ps1 +++ b/src/public/Get-BloggerPost.ps1 @@ -115,6 +115,7 @@ Function Get-BloggerPost { $title = $result.title $frontMatter = [ordered]@{ postId = $result.id + tags = $result.labels } $file = "$title.md" $filePath = Join-Path -Path $OutDirectory -ChildPath $file diff --git a/src/tests/Get-BloggerPost.Tests.ps1 b/src/tests/Get-BloggerPost.Tests.ps1 index 84ad198..57febdc 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 = "

Hello World

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,17 @@ 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" + } } Context "As Json" { From 48a62f0a9625c9990c43b2354f62afae7f414024 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:53:06 -0400 Subject: [PATCH 2/4] Publish-MarkdownBloggerPosts now supports -ExcludeLabels --- src/public/Publish-MarkdownBloggerPost.ps1 | 6 +++++- .../Publish-MarkdownBloggerPost.Tests.ps1 | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/public/Publish-MarkdownBloggerPost.ps1 b/src/public/Publish-MarkdownBloggerPost.ps1 index 4d2f686..9537fe9 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")) @@ -79,7 +83,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/tests/Publish-MarkdownBloggerPost.Tests.ps1 b/src/tests/Publish-MarkdownBloggerPost.Tests.ps1 index 06b7171..45364b5 100644 --- a/src/tests/Publish-MarkdownBloggerPost.Tests.ps1 +++ b/src/tests/Publish-MarkdownBloggerPost.Tests.ps1 @@ -146,6 +146,25 @@ postId: "123456" Should -InvokeVerifiable } + It "Should exclude certain tags from post labels when publishing " { + # arrange + + # add our tags to the file + $postInfo = Get-MarkdownFrontMatter -File $validFile + $postInfo.tags = @("PowerShell","Pester", "personal/blog-post") + Set-MarkdownFrontMatter -File $validFile -Replace $postInfo + + InModuleScope PSBlogger { + Mock Publish-BloggerPost -Verifiable -ParameterFilter { + $Labels -ne $null -and (-not (Compare-Object $Labels @("PowerShell","Pester")))} { return @{ id="123"} } + } + + # act + Publish-MarkdownBloggerPost -File $validFile -BlogId "123" -ExcludeLabels "personal/blog-post" + + # assert + Should -InvokeVerifiable + } It "Should update front matter with postid after publishing" { # arrange From dc0247d8210dfd94cb0ea797eca724cf064c2118 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Wed, 23 Jul 2025 13:29:56 -0400 Subject: [PATCH 3/4] add ExcludeLabels to user preferences and use as default --- src/private/Get-BloggerSession.ps1 | 1 + src/public/Get-BloggerConfig.ps1 | 1 + src/public/Publish-MarkdownBloggerPost.ps1 | 4 ++++ src/public/Set-BloggerConfig.ps1 | 4 ++-- .../Publish-MarkdownBloggerPost.Tests.ps1 | 20 +++++++++++++++++++ src/tests/Set-BloggerConfig.Tests.ps1 | 3 +++ 6 files changed, 31 insertions(+), 2 deletions(-) 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/Publish-MarkdownBloggerPost.ps1 b/src/public/Publish-MarkdownBloggerPost.ps1 index 9537fe9..cf1b4d3 100644 --- a/src/public/Publish-MarkdownBloggerPost.ps1 +++ b/src/public/Publish-MarkdownBloggerPost.ps1 @@ -58,6 +58,10 @@ Function Publish-MarkdownBloggerPost } } + if (!$PSBoundParameters.ContainsKey("ExcludeLabels")) { + $ExcludeLabels = $BloggerSession.ExcludeLabels + } + # grab the front matter $postInfo = Get-MarkdownFrontMatter -File $File 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/Publish-MarkdownBloggerPost.Tests.ps1 b/src/tests/Publish-MarkdownBloggerPost.Tests.ps1 index 45364b5..372a4e9 100644 --- a/src/tests/Publish-MarkdownBloggerPost.Tests.ps1 +++ b/src/tests/Publish-MarkdownBloggerPost.Tests.ps1 @@ -165,6 +165,26 @@ postId: "123456" # assert Should -InvokeVerifiable } + + It "Should use excludelabels user preference when not specified" { + # arrange + InModuleScope PSBlogger { + $BloggerSession.ExcludeLabels = @("personal/blog-post") + Mock Publish-BloggerPost -Verifiable -ParameterFilter { + $Labels -ne $null -and (-not (Compare-Object $Labels @("PowerShell","Pester")))} { return @{ id="123"} } + } + + # add our tags to the file + $postInfo = Get-MarkdownFrontMatter -File $validFile + $postInfo.tags = @("PowerShell","Pester", "personal/blog-post") + Set-MarkdownFrontMatter -File $validFile -Replace $postInfo + + # act + Publish-MarkdownBloggerPost -File $validFile -BlogId "123" + + # assert + Should -InvokeVerifiable + } It "Should update front matter with postid after publishing" { # arrange diff --git a/src/tests/Set-BloggerConfig.Tests.ps1 b/src/tests/Set-BloggerConfig.Tests.ps1 index f296688..f7ae6a8 100644 --- a/src/tests/Set-BloggerConfig.Tests.ps1 +++ b/src/tests/Set-BloggerConfig.Tests.ps1 @@ -13,6 +13,7 @@ Describe "Set-BloggerConfig" { # Create a new test-specific BloggerSession $BloggerSession = [pscustomobject]@{ BlogId = $null + ExcludeLabels = @() UserPreferences = "TestDrive:\UserPreferences.json" } @@ -23,6 +24,7 @@ Describe "Set-BloggerConfig" { It "Should persist new value to to BloggerSession.UserPreferences" -TestCases @( @{ UserPreference="BlogId"; UserPreferenceValue="12345" } + @{ UserPreference="ExcludeLabels"; UserPreferenceValue=@("personal/blog-post") } ) { # act @@ -37,6 +39,7 @@ Describe "Set-BloggerConfig" { It "Should persist new value to to empty BloggerSession.UserPreferences file" -TestCases @( @{ UserPreference="BlogId"; UserPreferenceValue="12345" } + @{ UserPreference="ExcludeLabels"; UserPreferenceValue=@("personal/blog-post") } ) { # arrange: empty file Set-Content TestDrive:\UserPreferences.json -Value "{}" From 23668313f705bec0239c95b76b0e257c964e4f99 Mon Sep 17 00:00:00 2001 From: bryan cook <3217452+bryanbcook@users.noreply.github.com> Date: Wed, 23 Jul 2025 13:30:18 -0400 Subject: [PATCH 4/4] include empty tags in frontmatter when labels are not present --- src/public/Get-BloggerPost.ps1 | 6 +++++- src/tests/Get-BloggerPost.Tests.ps1 | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/public/Get-BloggerPost.ps1 b/src/public/Get-BloggerPost.ps1 index 3798546..b570367 100644 --- a/src/public/Get-BloggerPost.ps1 +++ b/src/public/Get-BloggerPost.ps1 @@ -115,7 +115,11 @@ Function Get-BloggerPost { $title = $result.title $frontMatter = [ordered]@{ postId = $result.id - tags = $result.labels + } + if ($result['labels']) { + $frontMatter['tags'] = $result.labels + } else { + $frontMatter['tags'] = @() } $file = "$title.md" $filePath = Join-Path -Path $OutDirectory -ChildPath $file diff --git a/src/tests/Get-BloggerPost.Tests.ps1 b/src/tests/Get-BloggerPost.Tests.ps1 index 57febdc..0d396fc 100644 --- a/src/tests/Get-BloggerPost.Tests.ps1 +++ b/src/tests/Get-BloggerPost.Tests.ps1 @@ -221,6 +221,33 @@ Describe "Get-BloggerPost" { $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 = "

Hello World

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" { @@ -292,6 +319,7 @@ Describe "Get-BloggerPost" { It "Should write file to specified formatted directory - - " -TestCases @( @{ DateFormat = "yyyy\\MM"; ExpectedPath = "TestDrive:\2023\10\Test Post.md"; Format = "Markdown" } @{ DateFormat = "yyyy\\MM\\dd"; ExpectedPath = "TestDrive:\2023\10\01\123.html"; Format = "HTML" } + @{ DateFormat = "yyyy"; ExpectedPath = "TestDrive:\2023\123.json"; Format = "JSON"} ) { # arrange $invokeArgs = @{