first commit
This commit is contained in:
140
README.md
Normal file
140
README.md
Normal file
@@ -0,0 +1,140 @@
|
||||
# Markdown文件自动处理与定时推送系统
|
||||
|
||||
## 功能说明
|
||||
|
||||
本系统用于自动处理Markdown文件,将24小时内更新的文件复制到指定目录并提交Git变更,然后定时推送到远程仓库。
|
||||
|
||||
## 主要功能
|
||||
|
||||
1. **遍历目录**:遍历指定目录下的所有Markdown文件(包含子文件夹)
|
||||
2. **解析frontmatter**:解析每个文件的YAML frontmatter属性
|
||||
3. **检查更新时间**:优先使用frontmatter中的`updated`字段,否则使用文件修改时间
|
||||
4. **筛选24小时内更新的文件**:只处理最近24小时内更新的文件
|
||||
5. **同名文件处理**:支持三种策略:overwrite(覆盖), skip(跳过), rename(重命名)
|
||||
6. **Git提交**:自动提交变更,提交信息格式:`feat: 📝 {title}`
|
||||
7. **定时推送**:每天早上六点、中午12点、晚上零点推送到远程仓库
|
||||
|
||||
## 文件说明
|
||||
|
||||
- `parse_frontmatter.py`:主脚本,用于处理Markdown文件
|
||||
- `push_to_remote.py`:推送脚本,用于将本地提交推送到远程仓库
|
||||
- `push_to_remote.bat`:Windows批处理文件,用于运行推送脚本
|
||||
- `push_to_remote.sh`:Linux shell脚本,用于运行推送脚本
|
||||
- `example.md`:示例Markdown文件
|
||||
|
||||
## 配置说明
|
||||
|
||||
### 1. 添加远程仓库
|
||||
|
||||
在目标目录下执行以下命令添加远程仓库(使用SSH协议):
|
||||
|
||||
```bash
|
||||
git remote add origin git@github.com:username/repo.git
|
||||
```
|
||||
|
||||
### 2. SSH密钥配置
|
||||
|
||||
确保SSH密钥已正确配置,密钥文件应位于`~/.ssh/`目录下:
|
||||
|
||||
- 检查SSH密钥是否存在:
|
||||
```bash
|
||||
ls -la ~/.ssh/
|
||||
```
|
||||
|
||||
- 如果没有SSH密钥,生成新密钥:
|
||||
```bash
|
||||
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
||||
```
|
||||
|
||||
- 将公钥添加到GitHub/GitLab等平台
|
||||
|
||||
### 3. 定时任务配置
|
||||
|
||||
#### Windows系统(使用任务计划程序)
|
||||
|
||||
1. 打开"任务计划程序"(搜索"Task Scheduler")
|
||||
2. 点击"创建基本任务"
|
||||
3. 输入任务名称和描述
|
||||
4. 选择"每天"触发器
|
||||
5. 设置起始时间为"00:00:00",重复任务间隔为"12"小时,持续时间为"1天"
|
||||
6. 选择"启动程序"操作
|
||||
7. 浏览并选择`push_to_remote.bat`文件
|
||||
8. 勾选"当单击完成时,打开此任务属性的对话框"
|
||||
9. 切换到"触发器"选项卡,点击"新建"
|
||||
10. 设置另一个触发器为"每天",起始时间为"12:00:00"
|
||||
11. 点击"确定"完成配置
|
||||
|
||||
#### Linux系统(使用cron)
|
||||
|
||||
1. 打开cron配置文件:
|
||||
```bash
|
||||
crontab -e
|
||||
```
|
||||
|
||||
2. 添加以下行,设置每天零点、六点、十二点执行推送脚本:
|
||||
```bash
|
||||
0 0 * * * /path/to/push_to_remote.sh
|
||||
0 6 * * * /path/to/push_to_remote.sh
|
||||
0 12 * * * /path/to/push_to_remote.sh
|
||||
```
|
||||
|
||||
3. 保存并退出(对于vim编辑器,按`Esc`,然后输入`:wq`)
|
||||
|
||||
### 4. 脚本参数配置
|
||||
|
||||
可以根据需要修改脚本中的默认参数:
|
||||
|
||||
- **parse_frontmatter.py**:
|
||||
- `source_dir`:源目录路径
|
||||
- `destination_dir`:目标目录路径
|
||||
- `overwrite_strategy`:同名文件处理策略
|
||||
|
||||
- **push_to_remote.py**:
|
||||
- `repo_path`:Git仓库路径
|
||||
- `remote_name`:远程仓库名称
|
||||
- `branch`:分支名称
|
||||
|
||||
## 使用说明
|
||||
|
||||
1. **运行主脚本**:
|
||||
```bash
|
||||
python parse_frontmatter.py
|
||||
```
|
||||
|
||||
2. **手动运行推送脚本**:
|
||||
- Windows:
|
||||
```bash
|
||||
push_to_remote.bat
|
||||
```
|
||||
- Linux:
|
||||
```bash
|
||||
chmod +x push_to_remote.sh
|
||||
./push_to_remote.sh
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保Python环境已正确安装,并且已安装所需依赖:
|
||||
```bash
|
||||
pip install pyyaml gitpython
|
||||
```
|
||||
|
||||
2. 确保目标目录已初始化Git仓库,或者主脚本会自动初始化
|
||||
|
||||
3. 确保已正确配置SSH密钥,并且有权限访问远程仓库
|
||||
|
||||
4. 定时任务运行时,确保系统处于开机状态
|
||||
|
||||
## 日志说明
|
||||
|
||||
脚本会输出详细的日志信息,包括:
|
||||
- 处理的文件数量
|
||||
- 成功复制的文件数量
|
||||
- 提交的Git变更
|
||||
- 推送到远程仓库的结果
|
||||
|
||||
可以根据需要将日志重定向到文件,以便查看历史记录:
|
||||
|
||||
```bash
|
||||
python parse_frontmatter.py > log.txt 2>&1
|
||||
```
|
||||
Reference in New Issue
Block a user