Skip to content

Commit e7605d7

Browse files
committed
Get-BloggerPost without labels #24
1 parent b1d558d commit e7605d7

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/public/Get-BloggerPost.ps1

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Function Get-BloggerPost {
6868
if ($null -eq $result) {
6969
throw "No post found with PostId '$PostId' in blog '$BlogId'."
7070
}
71+
Write-Verbose "Post: $($result | ConvertTo-Json -Depth 10)"
7172

7273
# Construct a subfolder based on the published date
7374
if ($FolderDateFormat -and $result.published) {
@@ -80,12 +81,14 @@ Function Get-BloggerPost {
8081
# Ensure the output directory exists
8182
if (!(Test-Path -Path $OutDirectory)) {
8283
try {
84+
Write-Verbose "Creating output directory: $OutDirectory"
8385
New-Item -ItemType Directory -Path $OutDirectory -Force | Out-Null
8486
}
8587
catch {
8688
throw "Failed to create output directory '$OutDirectory': $($_.Exception.Message)"
8789
}
8890
}
91+
Write-Verbose "Using output directory: $OutDirectory"
8992

9093
# Extract the HTML content
9194
$htmlContent = $result.content
@@ -111,17 +114,21 @@ Function Get-BloggerPost {
111114

112115
# Save the Post to a Markdown file
113116
"Markdown" {
114-
117+
115118
$title = $result.title
116119
$frontMatter = [ordered]@{
117120
postId = $result.id
118121
}
119-
if ($result['labels']) {
122+
if ($result.PSObject.Properties.Name -contains "labels") {
123+
Write-Verbose "Using post labels: $($result.labels)"
120124
$frontMatter['tags'] = $result.labels
121125
} else {
126+
Write-Verbose "No labels found in post, using empty tags."
122127
$frontMatter['tags'] = @()
123128
}
129+
Write-Verbose "Saving frontmatter: $($frontMatter | ConvertTo-Json -Depth 10)"
124130
$file = "$title.md"
131+
125132
$filePath = Join-Path -Path $OutDirectory -ChildPath $file
126133
ConvertTo-MarkdownFromHtml -Content $result.content -OutFile $filePath > $null
127134
Set-MarkdownFrontMatter -File $filePath -Replace $frontMatter
@@ -140,7 +147,7 @@ Function Get-BloggerPost {
140147
return $result
141148
}
142149
catch {
143-
throw "Failed to save post content to file '$filePath': $($_.Exception.Message)"
150+
throw "Failed to save post content: $($_.Exception.Message)"
144151
}
145152
}
146153
catch {

src/tests/Get-BloggerPost.Tests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Describe "Get-BloggerPost" {
4040

4141
# setup blog post retrieval
4242
Mock Invoke-GAPi {
43-
return @{ content = "<html>Test content</html>" }
43+
return [pscustomobject]@{ content = "<html>Test content</html>" }
4444
}
4545
}
4646

@@ -64,7 +64,7 @@ Describe "Get-BloggerPost" {
6464
It "Should call correct API endpoint" {
6565
InModuleScope PSBlogger {
6666
Mock Invoke-GApi {
67-
return @{ content = "<html>Test content</html>" }
67+
return [pscustomobject]@{ content = "<html>Test content</html>" }
6868
} -ParameterFilter {
6969
$uri -eq "https://www.googleapis.com/blogger/v3/blogs/test-blog-id/posts/123"
7070
} -Verifiable
@@ -179,7 +179,7 @@ Describe "Get-BloggerPost" {
179179

180180
# mock post retrieval
181181
Mock Invoke-GApi {
182-
return @{
182+
return [pscustomobject]@{
183183
id = $postId
184184
title = "Test Post"
185185
published = [datetime]"2023-10-01T17:30:00-04:00"
@@ -232,7 +232,7 @@ Describe "Get-BloggerPost" {
232232

233233
# mock post retrieval
234234
Mock Invoke-GApi {
235-
return @{
235+
return [pscustomobject]@{
236236
id = $postId
237237
title = "Test Post"
238238
published = [datetime]"2023-10-01T17:30:00-04:00"
@@ -260,7 +260,7 @@ Describe "Get-BloggerPost" {
260260

261261
# mock post retrieval
262262
Mock Invoke-GApi {
263-
return @{
263+
return [pscustomobject]@{
264264
id = $postId
265265
title = "Test Post"
266266
published = [datetime]"2023-10-01T17:30:00-04:00"
@@ -306,7 +306,7 @@ Describe "Get-BloggerPost" {
306306

307307
# mock post retrieval
308308
Mock Invoke-GApi {
309-
return @{
309+
return [pscustomobject]@{
310310
id = $postId
311311
title = "Test Post"
312312
published = [datetime]"2023-10-01T17:30:00-04:00"

0 commit comments

Comments
 (0)