Skip to content

Commit 697b83c

Browse files
committed
修复后退不出内容的问题
1 parent ebbc1f4 commit 697b83c

3 files changed

Lines changed: 198 additions & 14 deletions

File tree

IFLOW.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Catsith's Home - Jekyll 博客项目
2+
3+
## 项目概述
4+
5+
这是一个基于 Jekyll 构建的个人技术博客,主要用于分享算法解题报告、技术笔记和生活感悟。博客托管在 GitHub Pages 上,使用了响应式设计,支持多设备访问。
6+
7+
- **项目名称**: Catsith's Home
8+
- **作者**: Catsith (马壮)
9+
- **主要技术**: Jekyll, GitHub Pages, Markdown
10+
- **网站地址**: https://mycodebattle.github.io
11+
12+
## 项目结构
13+
14+
```
15+
mycodebattle.github.io/
16+
├── _config.yml # Jekyll 配置文件
17+
├── _includes/ # 可重用的 HTML 组件
18+
│ ├── comments.html # 评论组件
19+
│ ├── footer.html # 页脚
20+
│ ├── header.html # 页头
21+
│ ├── navigation.html # 导航栏
22+
│ ├── pagination.html # 分页组件
23+
│ └── search_data.html # 搜索数据
24+
├── _layouts/ # 页面布局模板
25+
│ ├── default.html # 默认布局
26+
│ ├── page.html # 页面布局
27+
│ ├── post.html # 文章布局
28+
│ └── wiki.html # Wiki 页面布局
29+
├── _posts/ # 博客文章目录
30+
├── _wiki/ # Wiki 页面目录
31+
├── _site/ # Jekyll 生成的静态网站
32+
├── assets/ # 静态资源
33+
├── css/ # 样式文件
34+
├── js/ # JavaScript 文件
35+
├── images/ # 图片资源
36+
├── page/ # 静态页面
37+
├── vendor/ # 第三方资源
38+
├── Gemfile # Ruby 依赖管理
39+
├── Gemfile.lock # Ruby 依赖锁定文件
40+
├── index.html # 首页
41+
├── favicon.ico # 网站图标
42+
└── new.py # 创建新文章的 Python 脚本
43+
```
44+
45+
## 构建和运行
46+
47+
### 本地运行
48+
49+
1. 安装 Jekyll 和相关依赖:
50+
```bash
51+
bundle install
52+
```
53+
54+
2. 启动本地服务器:
55+
```bash
56+
bundle exec jekyll serve
57+
```
58+
59+
3. 在浏览器中访问 `http://localhost:4000`
60+
61+
### 创建新文章
62+
63+
项目提供了一个 Python 脚本来快速创建新文章:
64+
65+
```bash
66+
python new.py "文章标题"
67+
```
68+
69+
这将在 `_posts` 目录下创建一个新的 Markdown 文件,文件名格式为 `YYYY-MM-DD-文章标题.md`
70+
71+
### 部署到 GitHub Pages
72+
73+
项目配置为自动部署到 GitHub Pages。只需将更改推送到 GitHub 仓库,GitHub 会自动构建并部署网站。
74+
75+
## 开发约定
76+
77+
### 文章命名规范
78+
79+
- 文章文件名格式:`YYYY-MM-DD-文章标题.md`
80+
- 日期必须与文章前置内容中的日期保持一致
81+
- 文章标题使用连字符分隔,不包含空格
82+
83+
### 文章前置内容
84+
85+
每篇文章都需要以下前置内容:
86+
87+
```yaml
88+
---
89+
layout: post
90+
date: YYYY-MM-DD HH:MM:SS
91+
title: 文章标题
92+
categories: 分类
93+
tags: [标签1, 标签2]
94+
---
95+
```
96+
97+
### Wiki 页面
98+
99+
Wiki 页面存放在 `_wiki` 目录下,使用 `wiki` 布局,适合用于编写教程和文档。
100+
101+
### 评论系统
102+
103+
项目使用 Disqus 作为评论系统,配置在 `_config.yml` 中。
104+
105+
## 特殊功能
106+
107+
### 搜索功能
108+
109+
网站集成了搜索功能,搜索数据由 `_includes/search_data.html` 生成,搜索逻辑在 `js/search.js` 中实现。
110+
111+
### 响应式设计
112+
113+
网站支持响应式设计,在小屏幕设备上会自动应用 `css/small.css` 中的样式。
114+
115+
### 页面过渡
116+
117+
通过 `js/page-transition.js` 实现页面过渡效果。
118+
119+
## 自定义脚本
120+
121+
### new.py
122+
123+
用于快速创建新文章的 Python 脚本,自动生成符合 Jekyll 规范的 Markdown 文件,包含正确的前置内容。
124+
125+
### 清理脚本
126+
127+
- `clean_duplicate_posts.sh`: 清理重复文章
128+
- `list_duplicate_titles.py`: 列出重复标题
129+
- `find_duplicate_titles.py`: 查找重复标题
130+
- `convert_html_to_md.py`: 将 HTML 转换为 Markdown
131+
132+
## 维护说明
133+
134+
### 定期任务
135+
136+
1. 定期运行清理脚本,清理重复内容
137+
2. 更新依赖包:`bundle update`
138+
3. 检查链接有效性
139+
140+
### 备份
141+
142+
建议定期备份 `_posts` 目录中的内容,以防意外丢失。
143+
144+
## 许可证
145+
146+
项目采用开源许可证,具体信息请参考 `LICENSE` 文件。

_includes/search_data.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
<script src="/assets/js/search_data.js.liquid"></script>
1+
<script>
2+
// 预加载所有文章数据
3+
const searchPosts = [
4+
{% for post in site.posts %}
5+
{
6+
"title": "{{ post.title | escape }}",
7+
"url": "{{ site.url }}{{ post.url }}",
8+
"date": "{{ post.date | date: "%b %d, %Y" }}"
9+
}{% unless forloop.last %},{% endunless %}
10+
{% endfor %}
11+
];
12+
</script>

js/page-transition.js

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
11
// 页面过渡动画处理
22
(function() {
3-
// 页面加载完成后添加进入动画
4-
document.addEventListener('DOMContentLoaded', function() {
5-
// 为内容区域添加过渡动画类
3+
// 为内容区域添加过渡动画类
4+
function addTransitionClass() {
5+
const mainContent = document.querySelector('.main');
6+
if (mainContent) {
7+
mainContent.classList.add('page-transition');
8+
}
9+
}
10+
11+
// 页面进入动画
12+
function playEnterAnimation() {
613
const mainContent = document.querySelector('.main');
714
if (mainContent) {
8-
mainContent.classList.add('page-transition', 'page-enter');
15+
// 重置状态
16+
mainContent.classList.remove('page-exit', 'page-enter');
17+
18+
// 触发重排
19+
mainContent.offsetHeight;
20+
21+
// 添加进入动画
22+
mainContent.classList.add('page-enter');
923

10-
// 添加页面进入动画
1124
setTimeout(() => {
1225
mainContent.classList.remove('page-enter');
1326
}, 300);
1427
}
28+
}
29+
30+
// 页面加载完成后初始化
31+
function initPage() {
32+
addTransitionClass();
33+
playEnterAnimation();
34+
}
35+
36+
// 页面加载完成后添加进入动画
37+
document.addEventListener('DOMContentLoaded', initPage);
38+
39+
// 监听页面显示事件(包括从缓存中加载)
40+
window.addEventListener('pageshow', function(e) {
41+
// 检查是否是从缓存中加载的页面
42+
if (e.persisted) {
43+
initPage();
44+
}
1545
});
1646

1747
// 监听所有链接的点击事件
@@ -37,6 +67,7 @@
3767

3868
// 动画结束后跳转页面
3969
setTimeout(() => {
70+
// 使用location.replace()避免在历史记录中添加重复条目
4071
window.location.href = href;
4172
}, 300);
4273
} else {
@@ -48,13 +79,9 @@
4879

4980
// 监听浏览器前进/后退按钮事件
5081
window.addEventListener('popstate', function() {
51-
const mainContent = document.querySelector('.main');
52-
if (mainContent) {
53-
mainContent.classList.add('page-enter');
54-
55-
setTimeout(() => {
56-
mainContent.classList.remove('page-enter');
57-
}, 300);
58-
}
82+
// 延迟执行,确保页面内容已经更新
83+
setTimeout(() => {
84+
playEnterAnimation();
85+
}, 10);
5986
});
6087
})();

0 commit comments

Comments
 (0)