# -*- coding: utf-8 -*- import os import re def clean_and_save(path, content): content = content.replace('\r\n', '\n').replace('\r', '\n') lines = [line.rstrip() for line in content.split('\n')] result_lines = [] prev_empty = False for line in lines: if line == '': if not prev_empty: result_lines.append(line) prev_empty = True else: result_lines.append(line) prev_empty = False while result_lines and result_lines[-1] == '': result_lines.pop() text = '\r\n'.join(result_lines) + '\r\n' text = text.lstrip('\ufeff') with open(path, 'wb') as f: f.write(b'\xef\xbb\xbf' + text.encode('utf-8')) def clean_sidebar_js(): path = 'common/js/wiki_common.js' with open(path, 'rb') as f: c = f.read().decode('utf-8', errors='ignore') c = c.replace('\r\n', '\n') # バトル個別攻略のグループ全体を削除 c = re.sub(r"\{\s*type:\s*'groups',\s*title:\s*'🏰 バトル個別攻略'.*?\n\s*\}\s*,\s*(?=\{\s*type:\s*'links',\s*title:\s*'⚔️ バトル・特殊コンテンツ')", "", c, flags=re.DOTALL) # バトル・特殊コンテンツにリンクを追加 special_target = "{ text: 'ディープダンジョン完全攻略', path: 'deep_dungeon/index.html' }" special_repl = '''{ text: 'ディープダンジョン完全攻略', path: 'deep_dungeon/index.html' }, { text: 'PvP・クリコン&フロントライン', path: 'pvp/index.html' }, { text: 'ゴールドソーサー総合攻略', path: 'gold_saucer/index.html' }, { text: 'ミラプリ・2箇所染色完全攻略', path: 'glamour/index.html' }, { text: 'リテイナー・マーケット金策', path: 'retainer/index.html' }''' if special_target in c and 'pvp/index.html' not in c: c = c.replace(special_target, special_repl) clean_and_save(path, c) print("Cleaned common/js/wiki_common.js") # sidebar.html も正規化 with open('common/sidebar.html', 'rb') as f: sb_c = f.read().decode('utf-8', errors='ignore') clean_and_save('common/sidebar.html', sb_c) print("Cleaned common/sidebar.html") if __name__ == '__main__': clean_sidebar_js()