路径转换模块

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

# ============================================
# 《意识之道》智能文章创建脚本
# 作者:道祖
# 版本:v1
# 日期:2026-02-04 00:10
# 更新日期:2026-02-04 00:10
# ============================================


# 路径转换模块
# 功能:将中文路径转换为英文别名路径

# 将相对路径转换为英文别名
function Convert-PathToEnglish {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string]$RelativePath,

[Parameter(Mandatory=$true)]
[hashtable]$CategoryMap
)

if ([string]::IsNullOrWhiteSpace($RelativePath)) {
return $RelativePath
}

$parts = $RelativePath -split '/'
$convertedParts = @()

foreach ($part in $parts) {
if ($CategoryMap.ContainsKey($part)) {
# 如果映射表中存在这个部分,转换为英文
$convertedParts += $CategoryMap[$part]
} else {
# 否则保留原样
$convertedParts += $part
}
}

return $convertedParts -join '/'
}

# 批量转换路径列表
function Convert-PathsToEnglish {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string[]]$Paths,

[Parameter(Mandatory=$true)]
[hashtable]$CategoryMap
)

$convertedPaths = @()

foreach ($path in $Paths) {
$convertedPath = Convert-PathToEnglish -RelativePath $path -CategoryMap $CategoryMap
$convertedPaths += $convertedPath
}

return $convertedPaths
}

# 显示路径转换结果
function Show-PathConversion {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string[]]$Paths,

[Parameter(Mandatory=$true)]
[hashtable]$CategoryMap
)

Write-Host "📁 原始路径 (中文):" -ForegroundColor Yellow
$Paths | ForEach-Object { Write-Host " • $_" -ForegroundColor Gray }

Write-Host "`n🔤 转换路径 (英文):" -ForegroundColor Cyan
$convertedPaths = Convert-PathsToEnglish -Paths $Paths -CategoryMap $CategoryMap
$convertedPaths | ForEach-Object { Write-Host " • $_" -ForegroundColor Cyan }

# 显示使用的映射关系
Write-Host "`n📋 使用的分类映射:" -ForegroundColor DarkGray
$Paths | ForEach-Object {
$parts = $_ -split '/'
foreach ($part in $parts) {
if ($CategoryMap.ContainsKey($part)) {
Write-Host " $part$($CategoryMap[$part])" -ForegroundColor DarkGray
}
}
}

return $convertedPaths
}

# 显示可用的分类映射
function Show-AvailableCategoryMaps {
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[hashtable]$CategoryMap
)

if ($CategoryMap.Count -eq 0) {
Write-Host "📋 没有可用的分类映射" -ForegroundColor Yellow
return
}

Write-Host "📋 可用的分类映射 (共 $($CategoryMap.Count) 个):" -ForegroundColor Yellow

# 按分组显示
$groups = @{
"道经卷" = $CategoryMap.Keys | Where-Object { $_ -match "^道经卷|法则篇|道演篇" }
"道境卷" = $CategoryMap.Keys | Where-Object { $_ -match "^道境卷|道境之门|境界论述|实修根本|实修经|实修理术" }
"实践方向" = $CategoryMap.Keys | Where-Object { $_ -match "^实践方向|哲学之道|科学之道|技术之道|道祖之道" }
"其他" = $CategoryMap.Keys | Where-Object { $_ -notmatch "^道经卷|道境卷|实践方向" }
}

foreach ($groupKey in $groups.Keys) {
if ($groups[$groupKey].Count -gt 0) {
Write-Host "`n ${groupKey} ($($groups[$groupKey].Count) 个):" -ForegroundColor Cyan
$groups[$groupKey] | Sort-Object | ForEach-Object {
Write-Host " • $_$($CategoryMap[$_])" -ForegroundColor DarkGray
}
}
}
}

# 导出模块函数
Export-ModuleMember -Function `
Convert-PathToEnglish,
Convert-PathsToEnglish,
Show-PathConversion,
Show-AvailableCategoryMaps