import os import re import shutil raw_path = r'E:\Wiki\2nd\00_Raw' target_base = r'E:\Wiki\2nd\10_Wiki\Topics\Game Design' if not os.path.exists(target_base): os.makedirs(target_base) def sanitize_filename(filename): # Extract English name from parentheses if exists, else clean Korean match = re.search(r'\((.*?)\)', filename) if match: name = match.group(1) else: name = filename.replace('.md', '') # Remove special chars, replace spaces with hyphens name = re.sub(r'[^\w\s-]', '', name) name = name.strip().replace(' ', '-') return name + '.md' files = [f for f in os.listdir(raw_path) if f.endswith('.md')] for f in files: src_path = os.path.join(raw_path, f) new_filename = sanitize_filename(f) dest_path = os.path.join(target_base, new_filename) try: with open(src_path, 'r', encoding='utf-8', errors='ignore') as f_obj: content = f_obj.read() # Extract title from first line if it's a header title_match = re.search(r'^#\s+\[\[(.*?)\]\]', content) if title_match: display_title = title_match.group(1) else: display_title = f.replace('.md', '') # Build Wikified Content wikified = f"""--- id: GAME-WC-{new_filename.split('.')[0].upper()} category: "10_Wiki/๐Ÿ’ก Topics/Game Design" confidence_score: 1.0 tags: [war-commander, game-mechanics, tactical-analysis] last_reinforced: 2026-04-27 --- # [[{display_title}]] """ # Reformat sections if they follow the draft pattern content = content.replace('## ๐Ÿ“Œ Brief Summary', '## ๐Ÿ“Œ ํ•œ ์ค„ ํ†ต์ฐฐ (The Karpathy Summary)') content = content.replace('## ๐Ÿ“– Core Content', '## ๐Ÿ“– ๊ตฌ์กฐํ™”๋œ ์ง€์‹ (Synthesized Content)') content = content.replace('## ๐Ÿ”— Knowledge Connections', '## ๐Ÿ”— ์ง€์‹ ์—ฐ๊ฒฐ (Graph)') # Add the rest of the content (skipping the original title if we already added one) body = re.sub(r'^#\s+\[\[.*?\]\]\s*', '', content, flags=re.MULTILINE) # Ensure Contradictions header exists if '## โš ๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ' not in body: body = body.replace('## ๐Ÿ”— ์ง€์‹ ์—ฐ๊ฒฐ', '## โš ๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & RL Update)\n- ์‹ ๊ทœ ์ง€์‹ ์ž์‚ฐํ™” (2026-04-27).\n- War Commander ์ „ํˆฌ ์ƒํƒœ๊ณ„ ๋ฐ์ดํ„ฐ ํ†ตํ•ฉ.\n\n## ๐Ÿ”— ์ง€์‹ ์—ฐ๊ฒฐ') wikified += body with open(dest_path, 'w', encoding='utf-8') as f_obj: f_obj.write(wikified) # Delete raw file os.remove(src_path) print(f"Wikified: {f} -> {new_filename}") except Exception as e: print(f"Error processing {f}: {e}")