-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet-BloggerConfig.ps1
More file actions
65 lines (57 loc) · 2.28 KB
/
Copy pathSet-BloggerConfig.ps1
File metadata and controls
65 lines (57 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<#
.SYNOPSIS
Updates the local user preferences
.DESCRIPTION
Updates local user preferences that are used in Cmdlets in this module.
.PARAMETER Name
Name of the user preferene to set. Valid values are:
- BlogId: The ID of the Blogger blog to use.
- PandocAdditionalArgs: Additional arguments to pass to Pandoc when converting Markdown to HTML.
- PandocHtmlFormat: The HTML format to use when converting Markdown to HTML.
- PandocMarkdownFormat: The Markdown format to use when converting HTML to Markdown.
- ExcludeLabels: Labels to exclude when publishing to Blogger.
- AttachmentsDirectory: Folder path to attachments
.PARAMETER Value
The value to set for the specified user preference. Specify an empty string to remove the preference.
#>
Function Set-BloggerConfig
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[ValidateSet("BlogId","PandocAdditionalArgs","PandocHtmlFormat","PandocMarkdownFormat","ExcludeLabels","AttachmentsDirectory")]
[string]$Name,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
$Value
)
$userPreferences = [pscustomobject]@{}
if (Test-Path $BloggerSession.UserPreferences)
{
Write-Verbose "Set-BloggerConfig: Loading preferences from $($BloggerSession.UserPreferences)"
$userPreferences = [pscustomobject](Get-Content $BloggerSession.UserPreferences -Raw | ConvertFrom-Json)
$userPreferences | Out-String | Write-Verbose
}
if ($Value) {
switch ($Name) {
"AttachmentsDirectory" {
if (-not (Test-Path -Path $Value -PathType Container)) {
throw "AttachmentsDirectory must be a valid directory path."
}
$Value = (Resolve-Path -Path $Value).Path
}
}
}
if (@($userPreferences.PsObject.Properties).Count -eq 0 -or $Name -notin $userPreferences.PsObject.Properties.Name)
{
Write-Verbose "Set-BloggerConfig: Adding Property $Name"
$userPreferences | Add-Member -Name $Name -Value $Value -MemberType NoteProperty
}
else {
Write-Verbose "Set-BloggerConfig: Updating Propery $Name"
$userPreferences.$Name = $Value
}
Write-Verbose "Set-BloggerConfig: Saving preferences to $($BloggerSession.UserPreferences)"
Set-Content -Path $BloggerSession.UserPreferences -Value ($userPreferences | ConvertTo-Json)
$BloggerSession.$Name = $Value
}