# 设置输出编码为UTF-8 $OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 # 获取所有HTML文件 $htmlFiles = Get-ChildItem -Filter "*.html" # 菜单HTML模板 $menuTemplate = @'

地产后台管理

'@ foreach ($file in $htmlFiles) { Write-Host "正在处理: $($file.Name)" # 读取文件内容 $content = [System.IO.File]::ReadAllText($file.FullName, [System.Text.Encoding]::UTF8) # 获取当前页面名称 $currentPage = $file.Name # 准备新的菜单HTML $newMenu = $menuTemplate # 将当前页面的链接样式改为激活状态 $currentLinkPattern = "href=`"$currentPage`" class=`"flex items-center px-4 py-2 text-gray-300 hover:bg-gray-700 rounded`"" $activeLinkStyle = "href=`"$currentPage`" class=`"flex items-center px-4 py-2 text-blue-300 bg-blue-600 rounded`"" $newMenu = $newMenu -replace [regex]::Escape($currentLinkPattern), $activeLinkStyle # 替换菜单部分 $menuPattern = "(?s).*?\s*" $content = $content -replace $menuPattern, $newMenu # 更新标题 $titlePattern = ".*?" $pageName = $currentPage -replace "\.html$", "" $newTitle = "地产后台管理系统 - $pageName" $content = $content -replace $titlePattern, $newTitle # 保存更新后的内容 [System.IO.File]::WriteAllText($file.FullName, $content, [System.Text.Encoding]::UTF8) Write-Host "已完成: $($file.Name)" } Write-Host "所有文件更新完成!"