fixed 文章结构改变
This commit is contained in:
1 parent
7fb936ba78
commit
f6e7021fac
138 files changed
+11
-5
No files matched your search
+11
-5
@@ -43,14 +43,15 @@ if ([string]::IsNullOrWhiteSpace($author)) {
|
||||
$author = "小赵同学"
|
||||
}
|
||||
|
||||
# 6. 生成文件名 (YYYY-MM-DD-Slug.md)
|
||||
# 6. 生成文件夹和文件名 (Page Bundles 模式: YYYY-MM-DD-Slug/index.md)
|
||||
$date = Get-Date
|
||||
$dateStr = $date.ToString("yyyy-MM-dd")
|
||||
$dateTimeStr = $date.ToString("yyyy-MM-ddTHH:mm:ss+08:00")
|
||||
# 移除文件名中的非法字符
|
||||
$safeSlug = $slug -replace '[\\/:*?"<>|]', '' -replace '\s+', '-'
|
||||
$fileName = "$dateStr-$safeSlug.md"
|
||||
$filePath = Join-Path "content/post" $fileName
|
||||
$folderName = "$dateStr-$safeSlug"
|
||||
$folderPath = Join-Path "content/post" $folderName
|
||||
$filePath = Join-Path $folderPath "index.md"
|
||||
|
||||
# 7. 生成 Front Matter 内容
|
||||
$content = @"
|
||||
@@ -70,14 +71,19 @@ author: "$author"
|
||||
|
||||
# 8. 写入文件
|
||||
try {
|
||||
# 确保目录存在
|
||||
# 确保父目录存在
|
||||
if (-not (Test-Path "content/post")) {
|
||||
New-Item -ItemType Directory -Path "content/post" | Out-Null
|
||||
}
|
||||
|
||||
# 创建文章专属目录
|
||||
if (-not (Test-Path $folderPath)) {
|
||||
New-Item -ItemType Directory -Path $folderPath | Out-Null
|
||||
}
|
||||
|
||||
# 检查文件是否已存在
|
||||
if (Test-Path $filePath) {
|
||||
Write-Host "⚠️ 文件已存在: $fileName" -ForegroundColor Yellow
|
||||
Write-Host "⚠️ 文件已存在: $filePath" -ForegroundColor Yellow
|
||||
$overwrite = Read-Host "是否覆盖? (y/n)"
|
||||
if ($overwrite -ne 'y') {
|
||||
Write-Host "❌ 操作已取消" -ForegroundColor Red
|
||||
|
||||
Reference in new issue
Block a user