fixed 文章结构
This commit is contained in:
1 parent
6ad43b2c08
commit
ba93d0faa4
813 files changed
+243
-164
No files matched your search
+12
-9
@@ -43,14 +43,19 @@ if ([string]::IsNullOrWhiteSpace($author)) {
|
||||
$author = "小赵同学"
|
||||
}
|
||||
|
||||
# 6. 生成文件夹和文件名 (Page Bundles 模式: YYYY-MM-DD-Slug/index.md)
|
||||
# 6. 生成文件夹和文件名 (Page Bundles 模式: YYYY/YYYY-MM-DD-Slug/index.md)
|
||||
$date = Get-Date
|
||||
$year = $date.ToString("yyyy")
|
||||
$dateStr = $date.ToString("yyyy-MM-dd")
|
||||
$dateTimeStr = $date.ToString("yyyy-MM-ddTHH:mm:ss+08:00")
|
||||
|
||||
# 移除文件名中的非法字符
|
||||
$safeSlug = $slug -replace '[\\/:*?"<>|]', '' -replace '\s+', '-'
|
||||
$folderName = "$dateStr-$safeSlug"
|
||||
$folderPath = Join-Path "content/post" $folderName
|
||||
|
||||
# 路径结构:content/post/2024/2024-01-01-Slug/index.md
|
||||
$yearPath = Join-Path "content/post" $year
|
||||
$folderPath = Join-Path $yearPath $folderName
|
||||
$filePath = Join-Path $folderPath "index.md"
|
||||
|
||||
# 7. 生成 Front Matter 内容
|
||||
@@ -76,6 +81,11 @@ try {
|
||||
New-Item -ItemType Directory -Path "content/post" | Out-Null
|
||||
}
|
||||
|
||||
# 确保年份目录存在
|
||||
if (-not (Test-Path $yearPath)) {
|
||||
New-Item -ItemType Directory -Path $yearPath | Out-Null
|
||||
}
|
||||
|
||||
# 创建文章专属目录
|
||||
if (-not (Test-Path $folderPath)) {
|
||||
New-Item -ItemType Directory -Path $folderPath | Out-Null
|
||||
@@ -98,13 +108,6 @@ try {
|
||||
Write-Host "✅ 文章创建成功!" -ForegroundColor Green
|
||||
Write-Host "📂 文件路径: $filePath" -ForegroundColor Gray
|
||||
Write-Host "🔗 文章标题: $title" -ForegroundColor Gray
|
||||
Write-Host "📅 创建时间: $dateTimeStr" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
} catch {
|
||||
Write-Host "❌ 创建失败: $_" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# 暂停以便用户查看输出
|
||||
Write-Host "按任意键退出..."
|
||||
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
|
||||
Reference in new issue
Block a user