修复归档页面bug
This commit is contained in:
1 parent
8352af3610
commit
17412a5f58
17 files changed
+67
-39
No files matched your search
@@ -8,7 +8,7 @@ date: 2024-04-08T19:16:00
|
|||||||
updated: 2024-04-12T13:18:52
|
updated: 2024-04-12T13:18:52
|
||||||
status: hidden
|
status: hidden
|
||||||
draft: true
|
draft: true
|
||||||
draft: false
|
draft: true
|
||||||
author: 小赵同学
|
author: 小赵同学
|
||||||
categories:
|
categories:
|
||||||
- 生活
|
- 生活
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ title: win11右键菜单改回win10方法
|
|||||||
slug: 120
|
slug: 120
|
||||||
date: 2024-05-19T13:21:00
|
date: 2024-05-19T13:21:00
|
||||||
updated: 2024-07-23T12:36:24
|
updated: 2024-07-23T12:36:24
|
||||||
draft: false
|
draft: true
|
||||||
status: hidden
|
status: hidden
|
||||||
draft: true
|
draft: true
|
||||||
author: 小赵同学
|
author: 小赵同学
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ title: idea关闭ai自动补全
|
|||||||
slug: 121
|
slug: 121
|
||||||
date: 2024-06-01T19:48:00
|
date: 2024-06-01T19:48:00
|
||||||
updated: 2024-07-23T12:36:02
|
updated: 2024-07-23T12:36:02
|
||||||
draft: false
|
draft: true
|
||||||
status: hidden
|
status: hidden
|
||||||
draft: true
|
draft: true
|
||||||
author: 小赵同学
|
author: 小赵同学
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ title: parsec远程软件报6023错误
|
|||||||
slug: 122
|
slug: 122
|
||||||
date: 2024-06-02T11:36:00
|
date: 2024-06-02T11:36:00
|
||||||
updated: 2024-07-23T12:35:53
|
updated: 2024-07-23T12:35:53
|
||||||
draft: false
|
draft: true
|
||||||
status: hidden
|
status: hidden
|
||||||
draft: true
|
draft: true
|
||||||
author: 小赵同学
|
author: 小赵同学
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 125
|
|||||||
title: "Hugo使用GitHub Action自动刷新多吉云CDN缓存"
|
title: "Hugo使用GitHub Action自动刷新多吉云CDN缓存"
|
||||||
date: "2024-09-16T14:48:42+08:00"
|
date: "2024-09-16T14:48:42+08:00"
|
||||||
slug: 125
|
slug: 125
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ categories: []
|
|||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
layout: "post"
|
layout: "post"
|
||||||
status: "public"
|
# status: "public" # Auto-hidden by script
|
||||||
categories: ["生活"]
|
categories: ["生活"]
|
||||||
tags: []
|
tags: []
|
||||||
weight: -1
|
weight: -1
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 129
|
|||||||
title: "Failed to connect to github.com port 443 解决方案"
|
title: "Failed to connect to github.com port 443 解决方案"
|
||||||
date: "2024-10-18T16:34:20+08:00"
|
date: "2024-10-18T16:34:20+08:00"
|
||||||
slug: 129
|
slug: 129
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 132
|
|||||||
title: "解决webstorm本地调试跨域问题"
|
title: "解决webstorm本地调试跨域问题"
|
||||||
date: "2024-11-13T09:03:25+08:00"
|
date: "2024-11-13T09:03:25+08:00"
|
||||||
slug: 132
|
slug: 132
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 128
|
|||||||
title: "Hugo自动化备份至阿里云OSS"
|
title: "Hugo自动化备份至阿里云OSS"
|
||||||
date: "2024-10-06T15:49:58+08:00"
|
date: "2024-10-06T15:49:58+08:00"
|
||||||
slug: 128
|
slug: 128
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 127
|
|||||||
title: "大一学弟学妹军训结营"
|
title: "大一学弟学妹军训结营"
|
||||||
date: "2024-09-21T19:20:37+08:00"
|
date: "2024-09-21T19:20:37+08:00"
|
||||||
slug: 127
|
slug: 127
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 123
|
|||||||
title: "添加ikun摆件"
|
title: "添加ikun摆件"
|
||||||
date: "2024-08-07T16:10:05+08:00"
|
date: "2024-08-07T16:10:05+08:00"
|
||||||
slug: 123
|
slug: 123
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 130
|
|||||||
title: "win10&win11去除桌面快捷方式小箭头方法"
|
title: "win10&win11去除桌面快捷方式小箭头方法"
|
||||||
date: "2024-10-18T17:37:36+08:00"
|
date: "2024-10-18T17:37:36+08:00"
|
||||||
slug: 130
|
slug: 130
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ pid: 131
|
|||||||
title: "windows系统自启redis服务"
|
title: "windows系统自启redis服务"
|
||||||
date: "2024-11-10T10:09:16+08:00"
|
date: "2024-11-10T10:09:16+08:00"
|
||||||
slug: 131
|
slug: 131
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ pid: 135
|
|||||||
title: "还是放弃了iPhone16e"
|
title: "还是放弃了iPhone16e"
|
||||||
date: "2025-12-21T21:56:57+08:00"
|
date: "2025-12-21T21:56:57+08:00"
|
||||||
slug: 135
|
slug: 135
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
layout: "post"
|
layout: "post"
|
||||||
status: "public"
|
# status: "public" # Auto-hidden by script
|
||||||
categories: ["生活"]
|
categories: ["生活"]
|
||||||
tags: []
|
tags: []
|
||||||
status: hidden
|
status: hidden
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ pid: 136
|
|||||||
title: "脂溢性皮炎的烦恼"
|
title: "脂溢性皮炎的烦恼"
|
||||||
date: "2025-12-24T19:31:53+08:00"
|
date: "2025-12-24T19:31:53+08:00"
|
||||||
slug: 136
|
slug: 136
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
layout: "post"
|
layout: "post"
|
||||||
status: "public"
|
# status: "public" # Auto-hidden by script
|
||||||
categories: ["生活"]
|
categories: ["生活"]
|
||||||
tags: []
|
tags: []
|
||||||
status: hidden
|
status: hidden
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ pid: 133
|
|||||||
title: "除草日记"
|
title: "除草日记"
|
||||||
date: "2025-11-21T16:45:27+08:00"
|
date: "2025-11-21T16:45:27+08:00"
|
||||||
slug: 133
|
slug: 133
|
||||||
draft: false
|
draft: true
|
||||||
categories: []
|
categories: []
|
||||||
tags: []
|
tags: []
|
||||||
author: "小赵同学"
|
author: "小赵同学"
|
||||||
layout: "post"
|
layout: "post"
|
||||||
status: "public"
|
# status: "public" # Auto-hidden by script
|
||||||
categories: ["生活"]
|
categories: ["生活"]
|
||||||
tags: []
|
tags: []
|
||||||
status: hidden
|
status: hidden
|
||||||
|
|||||||
@@ -1,27 +1,38 @@
|
|||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
将所有包含 'status: hidden' 的文章标记为草稿 (draft: true)。
|
将所有包含 'status: hidden' 的文章标记为草稿 (draft: true),并清理冲突的设置。
|
||||||
|
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
此脚本用于批量处理 Hugo 文章。它会遍历 content/post 目录下的所有 .md 文件,
|
此脚本用于批量处理 Hugo 文章。它会遍历 content/post 目录下的所有 .md 文件。
|
||||||
解析 Front Matter。如果发现 'status: hidden' 且没有 'draft: true',
|
如果发现 'status: hidden':
|
||||||
则会在 'status: hidden' 下一行添加 'draft: true',以确保 Hugo 不会生成这些页面。
|
1. 将 'draft: false' 修改为 'draft: true'。
|
||||||
|
2. 注释掉冲突的 'status: public' 设置。
|
||||||
|
3. 如果没有 'draft: true',则添加它。
|
||||||
|
|
||||||
脚本包含安全检查:
|
脚本包含安全检查:
|
||||||
1. 确保读取和写入使用 UTF-8 编码。
|
1. 确保读取和写入使用 UTF-8 编码。
|
||||||
2. 确保新内容不为空。
|
2. 确保新内容不为空。
|
||||||
3. 确保文件大小没有异常减小(防止数据丢失)。
|
3. 确保文件大小没有异常减小。
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
.\scripts\add_draft_to_hidden.ps1
|
.\scripts\add_draft_to_hidden.ps1
|
||||||
#>
|
#>
|
||||||
|
|
||||||
$postsPath = "content/post"
|
$postsPath = "content/post"
|
||||||
|
# Ensure path exists
|
||||||
|
if (-not (Test-Path $postsPath)) {
|
||||||
|
Write-Error "Path not found: $postsPath"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
$files = Get-ChildItem -Path $postsPath -Recurse -Filter "*.md"
|
$files = Get-ChildItem -Path $postsPath -Recurse -Filter "*.md"
|
||||||
$count = 0
|
$count = 0
|
||||||
|
|
||||||
Write-Host "Starting scan for hidden posts..." -ForegroundColor Cyan
|
Write-Host "Starting scan for hidden posts cleanup..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
# Set console encoding to UTF8 to correctly display filenames
|
||||||
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
foreach ($file in $files) {
|
foreach ($file in $files) {
|
||||||
# Read with UTF8
|
# Read with UTF8
|
||||||
@@ -32,19 +43,36 @@ foreach ($file in $files) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
# Check for 'status: hidden'
|
$modified = $false
|
||||||
if ($content -match "(?m)^status:\s*hidden") {
|
$newContent = $content
|
||||||
|
|
||||||
|
# Check for 'status: hidden' or 'status: "hidden"'
|
||||||
|
if ($content -match "(?m)^status:\s*(`"hidden`"|hidden)") {
|
||||||
|
|
||||||
# Check if 'draft: true' is already present
|
# 1. Replace draft: false -> draft: true
|
||||||
if ($content -notmatch "(?m)^draft:\s*true") {
|
if ($newContent -match "(?m)^draft:\s*false") {
|
||||||
Write-Host "Processing: $($file.Name)"
|
$newContent = $newContent -replace "(?m)^draft:\s*false", "draft: true"
|
||||||
|
$modified = $true
|
||||||
# Use regex replace
|
Write-Host " Fixed 'draft: false' in $($file.Name)" -ForegroundColor Yellow
|
||||||
# Capture the status: hidden line and append draft: true
|
}
|
||||||
# Note: `n is newline in PowerShell
|
|
||||||
$newContent = $content -replace "(?m)(^status:\s*hidden.*$)", "`$1`ndraft: true"
|
# 2. Comment out status: public / status: "public"
|
||||||
|
if ($newContent -match "(?m)^status:\s*(`"public`"|public)") {
|
||||||
# SAFETY CHECK: Ensure new content is not empty and size is reasonable
|
$newContent = $newContent -replace "(?m)(^status:\s*(`"public`"|public))", "# `$1 # Auto-hidden by script"
|
||||||
|
$modified = $true
|
||||||
|
Write-Host " Commented out 'status: public' in $($file.Name)" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
# 3. Ensure draft: true exists
|
||||||
|
if ($newContent -notmatch "(?m)^draft:\s*true") {
|
||||||
|
# Append after status: hidden
|
||||||
|
$newContent = $newContent -replace "(?m)(^status:\s*(`"hidden`"|hidden).*$)", "`$1`ndraft: true"
|
||||||
|
$modified = $true
|
||||||
|
Write-Host " Added 'draft: true' to $($file.Name)" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($modified) {
|
||||||
|
# SAFETY CHECK: Ensure new content is not empty and size is reasonable
|
||||||
if ([string]::IsNullOrEmpty($newContent) -or $newContent.Length -eq 0) {
|
if ([string]::IsNullOrEmpty($newContent) -or $newContent.Length -eq 0) {
|
||||||
Write-Error "CRITICAL: New content is empty for $($file.Name). Skipping save."
|
Write-Error "CRITICAL: New content is empty for $($file.Name). Skipping save."
|
||||||
continue
|
continue
|
||||||
@@ -56,9 +84,9 @@ foreach ($file in $files) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
# Save file using .NET method to ensure UTF8 no BOM (or compatible UTF8)
|
# Save file using .NET method to ensure UTF8
|
||||||
[System.IO.File]::WriteAllText($file.FullName, $newContent, [System.Text.Encoding]::UTF8)
|
[System.IO.File]::WriteAllText($file.FullName, $newContent, [System.Text.Encoding]::UTF8)
|
||||||
Write-Host " -> Updated." -ForegroundColor Green
|
Write-Host " -> Saved changes to $($file.Name)" -ForegroundColor Green
|
||||||
$count++
|
$count++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user