novel-doomsday-resurgence/tools/sync_inkos_chapters.sh

66 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 同步inkos生成的章节到Git仓库的脚本
# 作者:番茄小说创作助手
# 日期2026-03-30
# 配置
INKOS_DIR="/root/.openclaw/workspace/tomato-novel/books/末日重生-开局囤货十亿物资/chapters"
GIT_DIR="/root/.openclaw/workspace/projects/末日重生_囤货"
CHAPTERS_DIR="$GIT_DIR/chapters"
# 创建chapters目录如果不存在
mkdir -p "$CHAPTERS_DIR"
# 备份现有的chapters目录
BACKUP_DIR="$GIT_DIR/chapters_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
if [ -d "$CHAPTERS_DIR" ] && [ "$(ls -A "$CHAPTERS_DIR" 2>/dev/null)" ]; then
echo "备份现有的章节文件到 $BACKUP_DIR"
cp -r "$CHAPTERS_DIR"/* "$BACKUP_DIR/" 2>/dev/null
fi
# 清空chapters目录但保留git跟踪状态
echo "清空chapters目录..."
rm -f "$CHAPTERS_DIR"/*.md
# 获取inkos目录中所有章节的最新版本
echo "从inkos目录同步最新章节..."
# 找出所有章节编号1-30
for i in {1..30}; do
# 格式化为4位数字
chapter_num=$(printf "%04d" $i)
# 找出该章节的所有文件
chapter_files=$(find "$INKOS_DIR" -name "${chapter_num}_*.md" -type f | grep -v "backup" | grep -v "备份" | grep -v "report.json")
if [ -n "$chapter_files" ]; then
# 按修改时间排序,获取最新的文件
latest_file=$(echo "$chapter_files" | xargs ls -t | head -1)
if [ -n "$latest_file" ]; then
# 从文件名提取章节标题
filename=$(basename "$latest_file")
# 提取章节标题去除编号和_fixed等后缀
chapter_title=$(echo "$filename" | sed -E "s/^${chapter_num}_//" | sed -E "s/\.md$//" | sed -E "s/_fixed$//" | sed -E "s/_修复版$//" | sed -E "s/_全面修复$//" | sed -E "s/_最终版$//" | sed -E "s/_标准重写$//" | sed -E "s/_番茄标准版$//")
# 格式化输出文件名
output_file="$CHAPTERS_DIR/ch${i}-第${i}${chapter_title}.md"
echo "同步章节 $i: $filename -> ch${i}-第${i}${chapter_title}.md"
cp "$latest_file" "$output_file"
fi
fi
done
# 检查实际同步了多少文件
sync_count=$(ls -1 "$CHAPTERS_DIR"/*.md 2>/dev/null | wc -l)
echo "同步完成!共同步了 $sync_count 个章节文件。"
# 显示同步的章节列表
if [ $sync_count -gt 0 ]; then
echo "同步的章节列表:"
ls -1 "$CHAPTERS_DIR"/*.md | sort
fi