Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/public/Publish-BloggerPost.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
.PARAMETER Draft
Optional. If specified, the post will be saved as a draft instead of being published.

.PARAMETER Open
Optional. If specified, launches a browser to view the post after publishing.

#>
Function Publish-BloggerPost {
[CmdletBinding()]
Expand All @@ -39,9 +42,14 @@ Function Publish-BloggerPost {
[Parameter(Mandatory = $true)]
[string]$Content,

[Parameter(Mandatory = $false)]
[string[]]$Labels,

[switch]$Draft
[Parameter(Mandatory = $false)]
[switch]$Draft,

[Parameter(Mandatory = $false)]
[switch]$Open
)

$uri = "https://www.googleapis.com/blogger/v3/blogs/$BlogId/posts"
Expand Down Expand Up @@ -77,15 +85,17 @@ Function Publish-BloggerPost {

$post = Invoke-GApi -Uri $uri -Body ($body | ConvertTo-Json) -Method $method

$postUrl = `
if ($Draft) {
"https://www.blogger.com/blog/post/edit/preview/$BlogId/$($post.id)"
}
else {
$post.url
}
if ($Open) {
$postUrl = `
if ($Draft) {
"https://www.blogger.com/blog/post/edit/preview/$BlogId/$($post.id)"
}
else {
$post.url
}

Start-Process $postUrl
Start-Process $postUrl
}

return $post
}
53 changes: 39 additions & 14 deletions src/public/Publish-MarkdownBloggerPost.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
<#
.SYNOPSIS
Publishes a markdown file as a blog post to Blogger, including uploading any local images to Google Drive.
Publishes a markdown file as a blog post to Blogger, including uploading any local images to Google Drive.

.DESCRIPTION
This function processes a markdown file to publish it as a blog post. It handles:
- Extracting front matter from the markdown file
- Finding and uploading local images to Google Drive
- Converting markdown content to HTML
- Publishing the post to Blogger
- Updating the front matter with post information
This function processes a markdown file to publish it as a blog post. It handles:
- Extracting front matter from the markdown file
- Finding and uploading local images to Google Drive
- Converting markdown content to HTML
- Publishing the post to Blogger
- Updating the front matter with post information

.PARAMETER File
The path to the markdown file to publish.
The path to the markdown file to publish.

.PARAMETER BlogId
The ID of the blog to publish to. If not specified, uses the BlogId from the current BloggerSession.
The ID of the blog to publish to. If not specified, uses the BlogId from the current BloggerSession.

.PARAMETER Draft
If specified, publishes the post as a draft rather than a published post.
If specified, publishes the post as a draft rather than a published post.

.PARAMETER Force
If specified, will overwrite existing images in Google Drive with the same name.
If specified, will overwrite existing images in Google Drive with the same name.

.PARAMETER Open
If specified, launches a browser to view the post after publishing.

.EXAMPLE
# publish or update post
Publish-MarkdownBloggerPost -File "my-post.md"

.EXAMPLE
# publish or update a draft post
Publish-MarkdownBloggerPost -File "my-post.md" -Draft

.EXAMPLE
Publish-MarkdownBloggerPost -File "my-post.md"
# publish or update a post, updating google drive images if required
Publish-MarkdownBloggerPost -File "my-post.md" -Force

.EXAMPLE
Publish-MarkdownBloggerPost -File "my-post.md" -Draft -Force
# publish or update a post, launching a web browser to view the published post
Publish-MarkdownBloggerPost -File "my-post.md" -Open

.EXAMPLE
# publish or update a draft, launching a web browser with the page preview
Publish-MarkdownBloggerPost -File "my-post.md" -Draft -Open
#>
Function Publish-MarkdownBloggerPost
{
Expand All @@ -46,7 +63,10 @@ Function Publish-MarkdownBloggerPost
[array]$ExcludeLabels = @(),

[Parameter(Mandatory=$false)]
[switch]$Force
[switch]$Force,

[Parameter(Mandatory=$false)]
[switch]$Open

)

Expand Down Expand Up @@ -80,6 +100,7 @@ Function Publish-MarkdownBloggerPost
Title = $postInfo.title
Content = $content
Draft = $Draft
Open = $Open
}

if ($postInfo["postId"]) {
Expand All @@ -90,18 +111,22 @@ Function Publish-MarkdownBloggerPost
$postArgs.Labels = [array]$postInfo.tags | Where-Object { $_ -notin $ExcludeLabels }
}

Write-Verbose "Publishing blogger post with args: $($postArgs | ConvertTo-Json -Depth 5)"
$post = Publish-BloggerPost @postArgs

# update post id
$postInfo["postId"] = $post.id
if ($Draft) {
Write-Verbose "Adding 'wip' to front matter"
$postInfo["wip"] = $true
} else {
if ($postInfo["wip"]) {
Write-Verbose "Removing 'wip' from front matter"
$postInfo.Remove("wip")
}
}

Write-Verbose "Updating front matter with post id: $($postInfo['postId'])"
Set-MarkdownFrontMatter -File $File -Replace $postInfo

return $post
Expand Down
Loading