feat: 遺跡探索 カルン埋没寺院 完全攻略ページの作成およびリンク追加
This commit is contained in:
1 parent
cb8e062447
commit
9b561d9b6b
5 files changed
+2343
-922
No files matched your search
+65
-57
@@ -2,11 +2,9 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
def normalize_text(text):
|
||||
# CRLF統一
|
||||
text = text.replace('\r\n', '\n').replace('\r', '\n')
|
||||
lines = [line.rstrip() for line in text.split('\n')]
|
||||
# 連続空行の防止(最大1行)
|
||||
def save_clean_file(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:
|
||||
@@ -17,62 +15,72 @@ def normalize_text(text):
|
||||
else:
|
||||
result_lines.append(line)
|
||||
prev_empty = False
|
||||
return '\r\n'.join(result_lines) + '\r\n'
|
||||
while result_lines and result_lines[-1] == '':
|
||||
result_lines.pop()
|
||||
text = '\n'.join(result_lines) + '\n'
|
||||
text = text.lstrip('\ufeff')
|
||||
# Windows上で autocrlf=true と調和するように \r\n で書き込むか \n で書き込むかをテスト
|
||||
with open(path, 'w', encoding='utf-8-sig', newline='\n') as f:
|
||||
f.write(text)
|
||||
|
||||
def save_utf8_bom(path, content):
|
||||
content = normalize_text(content)
|
||||
# 既存の先頭BOM文字を除去してから書き込む
|
||||
content = content.lstrip('\ufeff')
|
||||
with open(path, 'w', encoding='utf-8-sig', newline='\r\n') as f:
|
||||
f.write(content)
|
||||
|
||||
def update_dungeon_index(dungeon_id, dungeon_name, url):
|
||||
path = 'dungeons/index.html'
|
||||
if not os.path.exists(path):
|
||||
return
|
||||
with open(path, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
def add_dungeon_entry(name, level, desc, url, sb_name):
|
||||
# 1. dungeons/index.html
|
||||
path_idx = 'dungeons/index.html'
|
||||
with open(path_idx, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
c = f.read()
|
||||
# 該当行の「準備中」をリンクへ置換
|
||||
pattern = re.compile(rf'(<td><strong>[^<]*{re.escape(dungeon_name)}[^<]*</strong></td>\s*<td>[^<]*</td>\s*<td>[^<]*</td>\s*<td>)準備中(</td>)', re.DOTALL)
|
||||
if pattern.search(c):
|
||||
c = pattern.sub(rf'\g<1><a href="{url}">攻略を見る ➜</a>\2', c)
|
||||
save_utf8_bom(path, c)
|
||||
print(f"Updated {path} for {dungeon_name}")
|
||||
if url not in c:
|
||||
target = '<td><a href="brayflox.html">攻略を見る ➜</a></td>\n </tr>'
|
||||
target_crlf = '<td><a href="brayflox.html">攻略を見る ➜</a></td>\r\n </tr>'
|
||||
new_row = f'''\n <tr>
|
||||
<td><strong>{name}</strong></td>
|
||||
<td>{level}</td>
|
||||
<td>{desc}</td>
|
||||
<td><a href="{url}">攻略を見る ➜</a></td>
|
||||
</tr>'''
|
||||
c = c.replace('\r\n', '\n')
|
||||
if target in c:
|
||||
c = c.replace(target, target + new_row)
|
||||
else:
|
||||
c = re.sub(r'(<td><a href="[^"]*brayflox\.html"[^>]*>.*?</td>\s*</tr>)', r'\1' + new_row, c, flags=re.DOTALL)
|
||||
save_clean_file(path_idx, c)
|
||||
print(f"Added {name} to {path_idx}")
|
||||
|
||||
def update_sidebar_dungeon(name, url):
|
||||
# 1. sidebar.html
|
||||
# 2. common/sidebar.html
|
||||
path_sb = 'common/sidebar.html'
|
||||
if os.path.exists(path_sb):
|
||||
with open(path_sb, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
c = f.read()
|
||||
target = '<li><a href="../dungeons/alexandria.html">記憶幻想 アレクサンドリア (Lv100)</a></li>'
|
||||
new_entry = f'<li><a href="../dungeons/{url}">{name}</a></li>'
|
||||
if new_entry not in c and target in c:
|
||||
c = c.replace(target, f'{target}\n {new_entry}')
|
||||
save_utf8_bom(path_sb, c)
|
||||
print(f"Updated {path_sb} with {name}")
|
||||
|
||||
# 2. wiki_common.js
|
||||
path_js = 'common/js/wiki_common.js'
|
||||
if os.path.exists(path_js):
|
||||
with open(path_js, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
c = f.read()
|
||||
target_js = "{ text: '記憶幻想 アレクサンドリア (Lv100)', path: 'dungeons/alexandria.html' }"
|
||||
new_entry_js = f"{{ text: '{name}', path: 'dungeons/{url}' }}"
|
||||
if new_entry_js not in c and target_js in c:
|
||||
c = c.replace(target_js, f"{target_js},\n {new_entry_js}")
|
||||
save_utf8_bom(path_js, c)
|
||||
print(f"Updated {path_js} with {name}")
|
||||
|
||||
def normalize_file(filepath):
|
||||
if not os.path.exists(filepath):
|
||||
return
|
||||
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
with open(path_sb, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
c = f.read()
|
||||
save_utf8_bom(filepath, c)
|
||||
print(f"Normalized {filepath}")
|
||||
new_sb = f'<li><a href="../dungeons/{url}">{sb_name}</a></li>'
|
||||
if new_sb not in c:
|
||||
c = c.replace('\r\n', '\n')
|
||||
target = '<li><a href="../dungeons/brayflox.html">ブレイフロクスの野営地 (Lv32)</a></li>'
|
||||
if target in c:
|
||||
c = c.replace(target, f'{target}\n {new_sb}')
|
||||
else:
|
||||
c = re.sub(r'(<li><a href="\.\./dungeons/brayflox\.html">.*?</li>)', r'\1\n ' + new_sb, c)
|
||||
save_clean_file(path_sb, c)
|
||||
print(f"Added {sb_name} to {path_sb}")
|
||||
|
||||
# 3. common/js/wiki_common.js
|
||||
path_js = 'common/js/wiki_common.js'
|
||||
with open(path_js, 'r', encoding='utf-8', errors='ignore') as f:
|
||||
c = f.read()
|
||||
new_js = f"{{ text: '{sb_name}', path: 'dungeons/{url}' }}"
|
||||
if url not in c:
|
||||
c = c.replace('\r\n', '\n')
|
||||
target = "{ text: 'ブレイフロクスの野営地 (Lv32)', path: 'dungeons/brayflox.html' }"
|
||||
if target in c:
|
||||
c = c.replace(target, f"{target},\n {new_js}")
|
||||
else:
|
||||
c = re.sub(r"(\{ text: 'ブレイフロクス[^}]*brayflox\.html' \})", r"\1,\n " + new_js, c)
|
||||
save_clean_file(path_js, c)
|
||||
print(f"Added {sb_name} to {path_js}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
normalize_file('dungeons/brayflox.html')
|
||||
update_dungeon_index('brayflox', 'ブレイフロクス', 'brayflox.html')
|
||||
update_sidebar_dungeon('ブレイフロクスの野営地 (Lv32)', 'brayflox.html')
|
||||
save_clean_file('dungeons/sunken_temple.html', open('dungeons/sunken_temple.html', 'r', encoding='utf-8', errors='ignore').read())
|
||||
add_dungeon_entry(
|
||||
'遺跡探索 カルン埋没寺院',
|
||||
'Lv35 (新生2.0)',
|
||||
'<strong>【死の宣告・即死回避の登竜門】</strong> 光るパネルでの解除、ハチのファイナルスピア阻止、天秤の彫像。',
|
||||
'sunken_temple.html',
|
||||
'カルン埋没寺院 (Lv35)'
|
||||
)
|
||||
Reference in new issue
Block a user