58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
import os
|
|
import re
|
|
import shutil
|
|
|
|
raw_dir = "00_Raw"
|
|
target_base = "10_Wiki/Topics"
|
|
|
|
# Mapping Rules: Keyword regex -> Target Folder
|
|
rules = [
|
|
(r"WARNO|Eugen|Steel|Wargame|10v10|Combined|제병협동|사단|은신|탄도|장갑|소음|가용성|가위바위보", "AI & Games"),
|
|
(r"경제|인플레|수익|가차|결제|통화|싱크|Sinks|IAA|IAP|PBR|가격|지표|수도꼭지|배수구|보상|난이도", "Economics & Algorithms"),
|
|
(r"ndf|parse|WME|War-Yes|Armory|파싱|도구|스크립트|LOD|렌더링|텔레메트리", "Programming & Tools"),
|
|
(r"심리|행동|손실|게이미피케이션|사회|Sociology|대수", "Psychology & Behavior"),
|
|
(r"Pocket|Nexus|Magic|WoW|PLEX|디아블로", "General Knowledge")
|
|
]
|
|
|
|
if not os.path.exists(raw_dir):
|
|
print(f"Error: {raw_dir} not found")
|
|
exit(1)
|
|
|
|
files = [f for f in os.listdir(raw_dir) if f.endswith(".md")]
|
|
|
|
for filename in files:
|
|
src_path = os.path.join(raw_dir, filename)
|
|
target_folder = "General Knowledge"
|
|
|
|
for pattern, folder in rules:
|
|
if re.search(pattern, filename, re.IGNORECASE):
|
|
target_folder = folder
|
|
break
|
|
|
|
dst_dir = os.path.join(target_base, target_folder)
|
|
os.makedirs(dst_dir, exist_ok=True)
|
|
dst_path = os.path.join(dst_dir, filename)
|
|
|
|
try:
|
|
with open(src_path, "r", encoding="utf-8") as f:
|
|
content = f.read()
|
|
|
|
# Clean H1: # [[Title]] -> # Title
|
|
content = re.sub(r"# \[\[(.*?)\]\]", r"# \1", content)
|
|
|
|
# Add Frontmatter
|
|
frontmatter = f"---\ncategory: {target_folder}\nstatus: Final\nconverted_at: 2026-04-28\n---\n\n"
|
|
new_content = frontmatter + content
|
|
|
|
with open(dst_path, "w", encoding="utf-8") as f:
|
|
f.write(new_content)
|
|
|
|
if os.path.exists(dst_path):
|
|
os.remove(src_path)
|
|
print(f"Success: {filename} -> {target_folder}")
|
|
|
|
except Exception as e:
|
|
print(f"Failed: {filename} - {str(e)}")
|
|
|
|
print("Wiki-fication complete!")
|