更新readme文件
This commit is contained in:
1 parent
a7962d4762
commit
1243526162
2 files changed
+225
No files matched your search
@@ -0,0 +1,138 @@
|
||||
# 博客主题配置文档
|
||||
|
||||
本项目使用 Hugo 构建,主题为 `Ying`。以下是主要的配置说明,方便后续查阅和维护。
|
||||
|
||||
## 1. 基础配置 (`hugo.toml`)
|
||||
|
||||
位于项目根目录下,主要控制网站的全局行为。
|
||||
|
||||
* **网站标题**: `title = '优世界'`
|
||||
* **网站链接**: `baseURL = "https://usj.cc"`
|
||||
* **语言**: `languageCode = 'zh-cn'`
|
||||
* **URL 模式**:
|
||||
* `uglyURLs = true`: 生成以 `.html` 结尾的链接(如 `/about.html`)。
|
||||
* **固定链接 (Permalinks)**: 文章页面使用 `slug` 作为文件名。
|
||||
```toml
|
||||
[permalinks]
|
||||
post = "/:slug"
|
||||
```
|
||||
* **分页**: `paginate = 6` (每页显示 6 篇文章)
|
||||
* **代码高亮**: 使用 `tango` 样式。
|
||||
|
||||
## 2. 主题参数 (`themes/Ying/hugo.toml`)
|
||||
|
||||
位于 `themes/Ying/` 目录下,控制主题的外观和组件。
|
||||
|
||||
* **作者信息**:
|
||||
* 头像: `authorImage = "/image/tx7.jpg"`
|
||||
* 描述: `description = "不以物喜,不以己悲"`
|
||||
* **社交链接**:
|
||||
* 在 `[params]` 下的 `social` 列表中配置 GitHub、主页、RSS 等链接。
|
||||
* **菜单导航**:
|
||||
* 首页 (`/`)
|
||||
* 关于 (`/about.html`)
|
||||
* 留言 (`/ly.html`)
|
||||
* 友链 (`/links.html`)
|
||||
* 朋友圈 (`/circles.html`)
|
||||
* 归档 (`/archives.html`)
|
||||
|
||||
## 3. 文章管理
|
||||
|
||||
### 文章隐藏功能
|
||||
支持通过文章头部的 `status` 字段来控制文章是否在列表中显示。
|
||||
|
||||
* **隐藏文章**: 在文章的 Front Matter (头部 YAML 配置) 中添加:
|
||||
```yaml
|
||||
status: hidden
|
||||
```
|
||||
**效果**:
|
||||
* 文章**不会**出现在首页列表。
|
||||
* 文章**不会**出现在归档页面 (Archives)。
|
||||
* 文章**不会**出现在分类/标签列表中。
|
||||
* **但是**,可以通过直接访问链接(URL)来查看文章。
|
||||
|
||||
* **草稿文章**:
|
||||
```yaml
|
||||
draft: true
|
||||
```
|
||||
**效果**: 文章完全不生成,除非使用 `hugo server -D` 预览。
|
||||
|
||||
### URL 设置
|
||||
文章默认使用 `slug` 字段作为 URL 的文件名。
|
||||
例如:
|
||||
```yaml
|
||||
title: "我的文章"
|
||||
date: 2023-01-01
|
||||
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 评论全部变为父评论的问题。
|
||||
@@ -0,0 +1,87 @@
|
||||
|
||||
<#
|
||||
.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
|
||||
}
|
||||
Reference in new issue
Block a user