11<#
2+ . SYNOPSIS
3+ Publishes a markdown file as a blog post to Blogger, including uploading any local images to Google Drive.
24
5+ . DESCRIPTION
6+ This function processes a markdown file to publish it as a blog post. It handles:
7+ - Extracting front matter from the markdown file
8+ - Finding and uploading local images to Google Drive
9+ - Converting markdown content to HTML
10+ - Publishing the post to Blogger
11+ - Updating the front matter with post information
12+
13+ . PARAMETER File
14+ The path to the markdown file to publish.
15+
16+ . PARAMETER BlogId
17+ The ID of the blog to publish to. If not specified, uses the BlogId from the current BloggerSession.
18+
19+ . PARAMETER Draft
20+ If specified, publishes the post as a draft rather than a published post.
21+
22+ . PARAMETER Force
23+ If specified, will overwrite existing images in Google Drive with the same name.
24+
25+ . EXAMPLE
26+ Publish-MarkdownBloggerPost -File "my-post.md"
27+
28+ . EXAMPLE
29+ Publish-MarkdownBloggerPost -File "my-post.md" -Draft -Force
330#>
431Function Publish-MarkdownBloggerPost
532{
@@ -13,7 +40,10 @@ Function Publish-MarkdownBloggerPost
1340 [int ]$BlogId ,
1441
1542 [Parameter (Mandatory = $false )]
16- [switch ]$Draft
43+ [switch ]$Draft ,
44+
45+ [Parameter (Mandatory = $false )]
46+ [switch ]$Force
1747 )
1848
1949 if (! $PSBoundParameters.ContainsKey (" BlogId" ))
@@ -28,41 +58,7 @@ Function Publish-MarkdownBloggerPost
2858 $postInfo = Get-MarkdownFrontMatter - File $File
2959
3060 # Process images: detect, upload to Google Drive, and update markdown
31- $imageMappings = @ ()
32- $images = Find-MarkdownImages - File $File
33- if ($images -and $images.Count -gt 0 ) {
34- Write-Verbose " Found $ ( $images.Count ) local images to upload to Google Drive"
35-
36- $anonymous = New-GoogleDriveFilePermission - role " reader" - type " anyone"
37-
38- foreach ($image in $images ) {
39- try {
40- Write-Verbose " Uploading image: $ ( $image.FileName ) "
41- $uploadResult = Add-GoogleDriveFile - FilePath $image.LocalPath - FileName $image.FileName
42- if (! $uploadResult ) {
43- Write-Warning " Failed to upload image $ ( $image.FileName ) "
44- continue
45- }
46- Set-GoogleDriveFilePermission - FileId $uploadResult.id - Permission $anonymous | Out-Null
47-
48- $image.NewUrl = $uploadResult.PublicUrl
49- $imageMappings += $image
50-
51- Write-Verbose " Successfully uploaded: $ ( $image.FileName ) -> $ ( $uploadResult.PublicUrl ) "
52- }
53- catch {
54- Write-Warning " Failed to upload image $ ( $image.FileName ) : $ ( $_.Exception.Message ) $ ( [Environment ]::NewLine) $ ( $_.ErrorDetails | ConvertTo-Json - Depth 10 ) "
55- }
56- }
57-
58- # Update the markdown file with new URLs
59- if ($imageMappings -and $imageMappings.Count -gt 0 ) {
60- $updated = Update-MarkdownImages - File $File - ImageMappings $imageMappings
61- if ($updated ) {
62- Write-Verbose " Updated markdown file with $ ( $imageMappings.Count ) new image URLs"
63- }
64- }
65- }
61+ $imageMappings = Publish-MarkdownDriveImages - File $File - Force:$Force
6662
6763 # convert from markdown to html file
6864 $content = ConvertTo-HtmlFromMarkdown - File $File
0 commit comments