#!/bin/bash

# 修复所有章节文件的侧边栏 - 简化版

CHAPTERS_DIR="/root/.openclaw/workspace/alacarte-novel-website/chapters"

for file in $CHAPTERS_DIR/chapter-*.html; do
    chapter_file=$(basename "$file")
    
    # 1. 删除 sidebar-content 中所有 sidebar-chapter 链接
    # 2. 保留 sidebar-content div 容器
    sed -i '/sidebar-content/,/\/aside>/ {
        /<a href="chapter-.*class="sidebar-chapter"/d
    }' "$file"
    
    # 3. 在 app.js 后面添加 sidebar.js
    if ! grep -q "sidebar.js" "$file"; then
        sed -i 's|<script src="../js/app.js"></script>|<script src="../js/app.js"></script>\n    <script src="../js/sidebar.js"></script>|' "$file"
    fi
    
    echo "已修复: $chapter_file"
done

echo "全部修复完成！"