fixed 删除多余的脚本文件

This commit is contained in:
Vaica committed 2026-01-25 16:13:14 +08:00
1 parent a5b0ba1951
commit 5ae5d03f02
5 files changed
+65 -634

No files matched your search

+65 -179
View File
@@ -1,65 +1,77 @@
# 博客主题配置文档
# 博客项目说明
本项目使用 Hugo 构建,主题为 `Ying`。以下是主要的配置说明,方便后续查阅和维护。
本项目使用 Hugo 构建,主题为 `Ying`。以下是主要的配置说明与脚本使用指南,方便后续查阅和维护。
## 1. 基础配置 (`hugo.toml`)
## 1. 常用脚本与工具 (Scripts)
位于项目根目录下,主要控制网站的全局行为。
项目包含多个 PowerShell 和 Node.js 脚本,用于自动化维护、检查和部署。
* **网站标题**: `title = '优世界'`
* **网站链接**: `baseURL = "https://usj.cc"`
* **语言**: `languageCode = 'zh-cn'`
* **URL 模式**:
* `uglyURLs = true`: 生成以 `.html` 结尾的链接(如 `/about.html`)。
* **固定链接 (Permalinks)**: 文章页面使用 `slug` 作为文件名。
### 1.1 日常维护
* **新建文章 (`./new_post.ps1`)**
* **用途**: 交互式创建新的博客文章。
* **功能**: 自动引导输入标题、Slug、分类、标签等信息,并按 `YYYY-MM-DD-Slug` 格式创建 Page Bundle 目录和文件。
* **运行**:
```powershell
./new_post.ps1
```
* **手动构建与检查 (`./deploy.ps1`)**
* **用途**: 手动执行构建,包含友链健康检查。
* **流程**:
1. 运行 `scripts/check_links.js` 检查友链连通性。
2. 如果检查通过,执行 `hugo --minify` 生成静态文件。
* **运行**:
```powershell
./deploy.ps1
```
### 1.2 自动化与 CI/CD 工具
以下脚本主要在 GitHub Actions (`.github/workflows/upy.yml`) 中自动运行,也可手动用于调试:
* **友链数据同步 (`scripts/update_link_lite_json.ps1`)**
* **功能**: 将 `themes/Ying/data/links.yaml` (YAML源数据) 转换为 `themes/Ying/static/json/link_lite.json`,供前端 JS 和检查脚本使用。
* **友链健康检查 (`scripts/check_links.js`)**
* **功能**: 读取 `link_lite.json`,并发检查所有友链的可访问性。
* **依赖**: `node-fetch` (内置于 Node 18+ 或作为依赖)。
* **朋友圈数据生成 (`scripts/generate_circle_data.js`)**
* **功能**: 根据友链抓取 RSS/Atom 订阅源,生成朋友圈更新数据 (`friend_circle_data.json`)。
* **依赖**: `rss-parser`.
* **构建安全预处理 (`scripts/add_draft_to_hidden.ps1`)**
* **功能**: 在构建前扫描 `content/post`,将标记为 `status: hidden` 的文章强制设置为 `draft: true`,防止隐私文章意外泄露到公共列表。
* **CDN 刷新 (`scripts/RefreshCDN.py`)**
* **功能**: 部署完成后调用 DogeCloud API 刷新 CDN 缓存。
* **配置**: 需要在环境变量中设置 `DOGECLOUD_ACCESS_KEY` 等参数。
---
## 2. 基础配置 (`hugo.toml`)
位于项目根目录下,控制网站的全局行为。
* **网站信息**: 标题、BaseURL、语言等。
* **固定链接 (Permalinks)**:
```toml
[permalinks]
post = "/:slug"
```
* **分页**: `paginate = 6` (每页显示 6 篇文章)
* **代码高亮**: 使用 `tango` 样式。
文章页面使用 Front Matter 中的 `slug` 字段作为文件名(例如 `https://usj.cc/my-post.html`)。
## 2. 主题参数 (`themes/Ying/hugo.toml`)
## 3. 主题配置
位于 `themes/Ying/` 目录下,控制主题的外观和组件。
* **主题目录**: `themes/Ying/`
* **友链数据**: `themes/Ying/data/links.yaml`
* 添加友链请直接编辑此 YAML 文件,构建时会自动同步到 JSON。
* **作者信息**:
* 头像: `authorImage = "/image/tx7.jpg"`
* 描述: `description = "不以物喜,不以己悲"`
* **社交链接**:
* 在 `[params]` 下的 `social` 列表中配置 GitHub、主页、RSS 等链接。
* **菜单导航**:
* 首页 (`/`)
* 关于 (`/about.html`)
* 留言 (`/comment.html`)
* 友链 (`/links.html`)
* 朋友圈 (`/circles.html`)
* 归档 (`/archives.html`)
## 3. 文章管理
### 文章隐藏功能
支持通过文章头部的 `status` 字段来控制文章是否在列表中显示。
* **隐藏文章**: 在文章的 Front Matter (头部 YAML 配置) 中添加:
```yaml
status: hidden
```
**效果**:
* 文章**不会**出现在首页列表。
* 文章**不会**出现在归档页面 (Archives)。
* 文章**不会**出现在分类/标签列表中。
* **但是**,可以通过直接访问链接(URL)来查看文章。
* **草稿文章**:
```yaml
draft: true
```
**效果**: 文章完全不生成,除非使用 `hugo server -D` 预览。
## 4. 文章管理指南
### URL 设置
文章默认使用 `slug` 字段作为 URL 的文件名。
例如:
```yaml
title: "我的文章"
date: 2023-01-01
@@ -67,134 +79,8 @@ slug: "my-post"
```
生成的链接为: `https://usj.cc/my-post.html`
## 4. 输出格式 (RSS)
配置了全站 RSS 输出,支持非丑陋 URL (noUgly) 和固定链接。
RSS 地址: `https://usj.cc/rss.xml`
## 5. 常用命令
* **本地预览**:
```bash
hugo server
```
* **构建站点**:
```bash
hugo
```
## 6. 辅助脚本 (PowerShell)
项目中包含一些 PowerShell 脚本,用于简化日常维护工作。
### 6.1 新建文章 (`new_post.ps1`)
自动计算下一个 `pid` 并创建新文章。
* **用法**:
```powershell
./new_post.ps1
```
* **功能**:
1. 扫描 `content/post` 下所有文章,找到最大的 `pid`。
2. 提示输入新文章的文件名(例如 `my-new-post`)。
3. 创建新文件并自动插入 `pid: <max_pid + 1>`。
### 6.2 批量添加 PID (`add_pid_to_posts.ps1`)
为所有现有文章批量添加或更新 `pid` 字段。
* **用法**:
```powershell
./add_pid_to_posts.ps1
```
* **功能**:
1. 按日期对所有文章排序。
2. 从 1 开始顺序分配 `pid`。
3. 主要用于初始化或重置所有文章 ID。
### 6.3 部署脚本 (`deploy.ps1`)
集成友链检查和站点构建。
* **用法**:
```powershell
./deploy.ps1
```
* **功能**:
1. 运行 `node scripts/check_links.js` 检查友链健康状况。
2. 如果检查通过,执行 `hugo` 构建站点。
### 6.4 修复 Artalk 评论 ID (`scripts/fix_artalk_json.ps1`)
修复 Artalk 导出数据中 ID 类型错误导致的父子关系丢失问题。
* **用法**:
```powershell
# 基础用法(生成 _fixed.json 文件)
./scripts/fix_artalk_json.ps1 -InputFile "backup.artrans"
# 指定输出文件
./scripts/fix_artalk_json.ps1 -InputFile "backup.artrans" -OutputFile "fixed.artrans"
```
* **功能**:
1. 读取 JSON 导出文件。
2. 强制将所有 `id` 和 `rid` 字段转换为整数类型。
3. 解决 Artalk 评论全部变为父评论的问题。
### 6.5 批量隐藏文章 (`scripts/add_draft_to_hidden.ps1`)
扫描所有文章,将包含 `status: hidden` 的文章自动标记为草稿 (`draft: true`)。
* **用法**:
```powershell
./scripts/add_draft_to_hidden.ps1
```
* **功能**:
1. 扫描 `content/post` 下所有 Markdown 文件。
2. 如果文章包含 `status: hidden` 但没有 `draft: true`,自动添加 `draft: true`。
3. 用于批量确保“隐藏”的文章不被 Hugo 生成。
### 6.6 自动更新友链 JSON (`scripts/update_link_lite_json.ps1`)
根据 `themes/Ying/data/links.yaml` 自动生成 `themes/Ying/static/json/link_lite.json`。
* **用法**:
```powershell
./scripts/update_link_lite_json.ps1
```
* **功能**:
1. 读取 YAML 格式的友链数据。
2. 转换为 Friend-Circle-Lite 所需的 JSON 格式。
3. 通常在部署前自动运行。
### 6.7 刷新多吉云 CDN (`scripts/RefreshCDN.py`)
用于在部署完成后自动刷新 CDN 缓存。
* **用法**:
通常由 GitHub Actions 自动调用,不建议手动运行。
需要环境变量: `DOGECLOUD_ACCESS_KEY`, `DOGECLOUD_SECRET_KEY`, `CDN_URL_LIST`.
### 6.8 朋友圈数据生成 (`scripts/generate_circle_data.js`)
抓取友链 RSS 并生成朋友圈数据。
* **用法**:
```bash
node scripts/generate_circle_data.js
```
* **功能**:
1. 读取 `themes/Ying/static/json/link_lite.json` 中的友链列表。
2. 尝试抓取每个友链的 RSS/Atom 订阅源。
3. 提取最新文章(包含标题、链接、摘要、图片等)。
4. 生成 `themes/Ying/static/json/friend_circle_data.json` 供前端展示。
## 7. 自动化部署 (GitHub Actions)
本项目配置了完整的 CI/CD 流程 (`.github/workflows/upy.yml`),主要包含以下步骤:
1. **环境准备**: 安装 Hugo, Node.js, Python, PowerShell。
2. **预构建检查**:
* 运行 `update_link_lite_json.ps1` 确保友链数据最新。
* 运行 `add_draft_to_hidden.ps1` 确保隐藏文章安全。
3. **数据生成**:
* 运行 `npm install` 安装依赖。
* 运行 `generate_circle_data.js` 抓取并生成朋友圈数据。
4. **构建**: 运行 `hugo --minify` 生成静态文件。
5. **部署**: 将 `public` 目录推送到又拍云 (UpYun)。
6. **刷新缓存**: 部署成功后,调用多吉云 (DogeCloud) API 刷新 CDN 节点。
> **注意**: 友链健康检查 (`scripts/check_links.js`) 仅作为本地工具 (`deploy.ps1`) 运行,不会阻断线上部署流程。
### 隐藏文章
如果你想写一篇不公开在列表显示的文章(但可以通过链接访问):
1. 在 Front Matter 中添加 `status: hidden`。
2. 自动化脚本会在构建时将其标记为 `draft: true` (配合特殊构建逻辑) 或进行其他处理。
*注:具体表现取决于 CI 脚本的逻辑,通常用于草稿或隐藏页。*
-64
View File
@@ -1,64 +0,0 @@
# 脚本功能:批量给现有 Markdown 文章添加 pid 字段,按发布时间升序排列(1, 2, 3...)
$postsPath = "content/post"
$files = Get-ChildItem -Path $postsPath -Filter "*.md"
Write-Host "正在扫描文章..."
$postData = @()
foreach ($file in $files) {
$content = Get-Content $file.FullName -Raw -Encoding UTF8
# 提取日期
if ($content -match "(?m)^date:\s*([0-9T:-\s]+)") {
$dateStr = $matches[1].Trim()
try {
$date = [DateTime]::Parse($dateStr)
} catch {
$date = $file.CreationTime
}
} else {
$date = $file.CreationTime
}
$postData += [PSCustomObject]@{
Path = $file.FullName
Date = $date
Content = $content
}
}
# 按时间排序
$sortedPosts = $postData | Sort-Object Date
$id = 1
foreach ($post in $sortedPosts) {
$content = $post.Content
# 检查是否已有 pid
if ($content -match "(?m)^pid:\s*\d+") {
# 更新 pid
$newContent = $content -replace "(?m)^pid:\s*\d+", "pid: $id"
} else {
# 插入 pid (在第二个 --- 之前,或者在 layout/title 之后)
# 简单策略:在第一个 --- 后面插入
# 注意:Raw string start with ---
if ($content -match "^---\s*\r?\n") {
$newContent = $content -replace "^---\s*\r?\n", "--`npid: $id`n"
} else {
# 异常情况,直接追加
Write-Host "Skipping $($post.Path) (No front matter found)"
continue
}
}
# 保持 UTF8 编码 (无 BOM 或带 BOM 取决于原文件,这里统一用 UTF8)
[System.IO.File]::WriteAllText($post.Path, $newContent, [System.Text.Encoding]::UTF8)
Write-Host "Updated $($post.Path) with pid: $id"
$id++
}
Write-Host "处理完成!共更新 $($id - 1) 篇文章。"
-87
View File
@@ -1,87 +0,0 @@
<#
.SYNOPSIS
修复 Artalk 导出文件 (.artrans/JSON) 中的 ID 类型问题。
将所有 id 和 rid 字段转换为整数类型,解决父子评论关系丢失的问题。
.DESCRIPTION
Artalk 的某些版本/配置对 ID 的类型敏感(字符串 vs 整数)。
此脚本读取 JSON 文件,强制将 comments 数组中的 id 和 rid 转换为 Int64,
并保存为新的文件。
.PARAMETER InputFile
输入的 .artrans 或 .json 文件路径。
.PARAMETER OutputFile
(可选) 输出文件路径。如果不指定,将添加 "_fixed" 后缀。
.EXAMPLE
.\fix_artalk_json.ps1 -InputFile "backup.artrans"
.\fix_artalk_json.ps1 -InputFile "backup.artrans" -OutputFile "fixed.artrans"
#>
param (
[Parameter(Mandatory=$true)]
[string]$InputFile,
[Parameter(Mandatory=$false)]
[string]$OutputFile
)
# 检查输入文件是否存在
if (-not (Test-Path $InputFile)) {
Write-Error "错误: 找不到输入文件 '$InputFile'"
exit 1
}
# 如果未指定输出文件,自动生成
if ([string]::IsNullOrWhiteSpace($OutputFile)) {
$directory = [System.IO.Path]::GetDirectoryName($InputFile)
$filename = [System.IO.Path]::GetFileNameWithoutExtension($InputFile)
$extension = [System.IO.Path]::GetExtension($InputFile)
$OutputFile = Join-Path $directory "${filename}_fixed${extension}"
}
Write-Host "正在读取文件: $InputFile ..." -ForegroundColor Cyan
try {
# 读取并解析 JSON
$jsonContent = Get-Content -Path $InputFile -Raw -Encoding UTF8
$data = $jsonContent | ConvertFrom-Json
# 检查是否存在 comments 数组
if (-not $data.comments) {
Write-Warning "未在文件中找到 'comments' 数组。这可能不是有效的 Artalk 导出文件。"
} else {
$count = $data.comments.Count
Write-Host "找到 $count 条评论,正在处理..." -ForegroundColor Cyan
# 遍历并转换类型
foreach ($comment in $data.comments) {
# 强制转换为 Int64 (long)
if ($comment.id -ne $null) {
$comment.id = [int64]$comment.id
}
if ($comment.rid -ne $null) {
$comment.rid = [int64]$comment.rid
}
}
}
Write-Host "正在保存到: $OutputFile ..." -ForegroundColor Cyan
# 转换为 JSON 并保存
# Depth 100 防止深层嵌套被截断
# Compress 选项可减小体积,但为了可读性这里不使用(Artalk 导出通常也是展开的)
$newJson = $data | ConvertTo-Json -Depth 100
# 确保使用 UTF8 保存
[System.IO.File]::WriteAllText($OutputFile, $newJson, [System.Text.Encoding]::UTF8)
Write-Host "修复完成!" -ForegroundColor Green
Write-Host "请使用 Artalk 后台导入 '$OutputFile'。" -ForegroundColor Green
} catch {
Write-Error "处理过程中发生错误: $_"
exit 1
}
-10
View File
@@ -1,10 +0,0 @@
$files = Get-ChildItem -Path "content" -Recurse -Filter "*.md"
foreach ($file in $files) {
$content = Get-Content $file.FullName -Raw -Encoding UTF8
if ($content -match "status:\s*hidden") {
$newContent = $content -replace "status:\s*hidden`r`n", "" -replace "status:\s*hidden`n", "" -replace "status:\s*`"hidden`"`r`n", "" -replace "status:\s*`"hidden`"`n", ""
Set-Content -Path $file.FullName -Value $newContent -Encoding UTF8
Write-Host "Updated $($file.Name)"
}
}
-294
View File
@@ -1,294 +0,0 @@
{
"friends": [
[
"吾柯",
"https://blog.keepke.com",
"https://blog.keepke.com/logo.png"
],
[
"叶开",
"https://qq.md",
"https://cravatar.cn/avatar/4741124456fb02fa4da30494dbc6c99e?d=monsterid&s=80"
],
[
"一泽",
"https://yang99.fun",
"https://q.qlogo.cn/g?b=qq&nk=3369963811@qq.com&s=100"
],
[
"七栀",
"https://qydzz.cn",
"https://qydzz.cn/logo.png"
],
[
"若志随笔",
"https://www.rz.sb",
"https://q1.qlogo.cn/g?b=qq&nk=80360650&s=640"
],
[
"黑桃三",
"https://heitaosan.com",
"https://s2.ax1x.com/2020/01/03/lUmf81.png"
],
[
"十七的小栈",
"https://blog.allnull.cn",
"https://cravatar.cn/avatar/56238a7f177c534928fd3cf4161ab59e?s=65&r=G&d=mm"
],
[
"Vian",
"https://vian.top",
"https://www.vian.top/avatar.ico"
],
[
"油油",
"https://blog.200011.net",
"https://q1.qlogo.cn/g?b=qq&nk=1376652515&s=640"
],
[
"大悟博客",
"https://www.dawuyu.com",
"https://q1.qlogo.cn/g?b=qq&nk=2824236078&s=640"
],
[
"段先森",
"https://duanxiansen.com",
"https://q.qlogo.cn/g?b=qq&nk=2443266417@qq.com&s=100"
],
[
"Fivk博客",
"https://blog.fivk.cn",
"https://q1.qlogo.cn/g?b=qq&nk=11470226&s=640"
],
[
"日志屿",
"https://www.logyu.cc",
"https://p.logyu.cc/logo.png"
],
[
"百品博客",
"https://baipin.pw",
"https://www.baipin.pw/wp-content/uploads/2019/07/cropped-ABUIABACGAAg_bP2wwUorbiplQQwgAU4gAU.jpg"
],
[
"长安城下",
"https://cacx.cc",
"https://cacx.cc/favicon.ico"
],
[
"itsNekoDeng",
"https://dyfa.top",
"https://dyfa.top/medias/avatar.jpg"
],
[
"WhiteFan",
"https://www.baifan97.cn",
"https://ypy.baifan97.cn/typecho/uploads/img/avatar.png"
],
[
"北枫",
"https://beifeng.me",
"https://q1.qlogo.cn/g?b=qq&nk=41777657&s=640"
],
[
"团团生活志",
"https://t-t.live",
"https://img.t-t.live/img/tx.png"
],
[
"臭袜子",
"https://huziyan.com",
"https://huziyan.com/usr/themes/icefox/assets/img/tx.jpg"
],
[
"岳泽以",
"https://www.yuezeyi.com",
"https://q2.qlogo.cn/g?b=qq&nk=2780008080&s=100"
],
[
"三石的记录",
"https://www.fllv.cn",
"https://cdn.helingqi.com/wavatar/a25a7640aa68e6d26e32afee8120f7e5?s=65&r=G&d="
],
[
"竹春廿柒",
"https://mojinxi.cn",
"https://mojinxi.cn/img/logo.png"
],
[
"大嘴狗狗",
"https://www.sirit.com.cn",
"https://www.sirit.com.cn/siritlogo.png"
],
[
"半截の诗",
"https://sweetjing.cc/",
"https://q1.qlogo.cn/g?b=qq&nk=1486823198&s=640"
],
[
"XIAOMING'S BLOG",
"https://vimin.cc",
"https://cravatar.cn/avatar/6eb95597489dd26f15a973e667d71aef?s=100&r=G&d="
],
[
"网友小宋",
"https://xyzbz.cn",
"https://cravatar.cn/avatar/120340d1df519f4e28613fe5d404b286?s=65&r=G&d="
],
[
"微风忆夏",
"https://sumiler.com",
"https://cravatar.cn/avatar//a35f5ef7a4bce3b7cfa6f538ffcae7aa"
],
[
"林林杂语",
"https://www.xiaozonglin.cn",
"https://cravatar.cn/avatar/04bfc914bd50b42eb507bf66aad0cc31?d=mp"
],
[
"西瓜撞地球",
"https://www.bio-w.cn",
"https://bu.dusays.com/2022/10/17/634d313602a1e.png"
],
[
"Diayの日记",
"https://diay.cn",
"https://q1.qlogo.cn/g?b=qq&nk=763333529&s=100"
],
[
"Eacls",
"https://www.eacls.top",
"https://www.eacls.top/img/favicon.png"
],
[
"Kris Yan",
"https://blog.krisyan.dev",
"https://cravatar.cn/avatar/05729ab2ca3b99203a674859f77d592b?&d=mp"
],
[
"Echo 的小窝",
"https://www.liveout.cn/",
"https://yy.liveout.cn/photo/photo2.jpg"
],
[
"未来往事",
"https://felixway.cn",
"https://cravatar.cn/avatar/2ee35215cbea58cd8b2605e7f517d689?&d=mp"
],
[
"小稚生活志",
"https://ihello.cc",
"https://bu.dusays.com/2024/02/02/65bbce27b129a.jpg"
],
[
"风呼呼",
"https://whooc.com",
"https://whooc.com/logo"
],
[
"柳橙睿",
"https://www.liuchengrui.cn",
"https://www.liuchengrui.cn/myphoto.png"
],
[
"永恒末匕",
"https://likaijian.com",
"https://q.qlogo.cn/headimg_dl?dst_uin=1527335101&spec=640"
],
[
"刘郎阁",
"https://yjvc.cn/",
"https://yjvc.cn/usr/uploads/logo.jpeg"
],
[
"浮沉流年",
"https://www.fcln.net",
"https://cravatar.cn/avatar//4355eea603309a0c159ca27f54e27c89?s=65&r=G&d="
],
[
"蓝调时刻",
"https://www.landiaoshike.com/",
"https://www.landiaoshike.com/favicon.ico"
],
[
"二十六",
"https://www.ershiliu.com/",
"https://www.ershiliu.com/favicon.ico"
],
[
"阿呆日记",
"https://dai.ge",
"https://dai.ge/img/logo.png"
],
[
"雅余",
"https://yayu.net",
"https://yayu.net/wp-content/themes/yayu/assets/images/icon.png"
],
[
"如是乎",
"http://rushihu.com/",
"https://cravatar.com/wp-content/uploads/sites/9/2021/07/00000000000000000000000000000000.png"
],
[
"拾月",
"https://www.skyue.com/",
"https://gravatar.loli.net/avatar/c3fb4bb4d5101284ddd672fb722cdd7d?s=32&r=G"
],
[
"湘铭`Blog",
"https://xiangming.site",
"https://photo.xiangming.site/img/icologo.png"
],
[
"轻风记",
"https://windy.ink/",
"https://q1.qlogo.cn/g?b=qq&nk=2381548894&s=0"
],
[
"杜老师说",
"https://dusays.com",
"https://cdn.dusays.com/avatar.png"
],
[
"风记星辰",
"https://www.thyuu.com",
"https://std.thyuu.com/logo.webp"
],
[
"obaby",
"https://oba.by/",
"https://cravatar.cn/avatar/3a78942c4ddcda86242f20abdacee082?d=mp"
],
[
"Pampo",
"https://pampo.cn/",
"https://cravatar.cn/avatar/296655fd99af406835c8861efb84f6b8?s=200&r=G&d="
],
[
"邹江博客",
"https://www.zoujiang.com",
"https://www.zoujiang.com/logo.jpg"
],
[
"森木志",
"https://oxxx.cn",
"https://gravatar.webp.se/avatar/5a076aa876b435fe788c8eeda004e9ec"
],
[
"土拨许",
"https://zhuo.re",
"https://cravatar.cn/avatar/126bbc02f1aef6228805d330648d9aa1"
],
[
"Jdeal",
"https://www.jdeal.cn",
"https://qn.jdeal.cn/file/favicon.ico"
],
[
"优世界",
"https://usj.cc",
"https://usj.cc/favicon.ico"
]
]
}