Files
blog/README.md
T

150 lines
4.5 KiB
Markdown
Raw Normal View History

2026-01-20 23:50:10 +08:00
# 博客主题配置文档
本项目使用 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 评论全部变为父评论的问题。
2026-01-20 23:57:41 +08:00
### 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 生成。