Files
2nd/scratch/wiki_auto_engine.ps1

62 lines
2.4 KiB
PowerShell

$rawDir = Join-Path (Get-Location) "00_Raw"
$targetBase = Join-Path (Get-Location) "10_Wiki\Topics"
# Robust Rules Array
$rules = @(
@{ keywords = @("WARNO", "Eugen", "Steel Division", "Wargame", "10v10", "Combined Arms", "제병협동", "사단", "은신", "탄도학", "장갑", "소음", "가용성", "가위바위보"); target = "AI & Games" },
@{ keywords = @("경제", "인플레이션", "수익화", "가차", "결제", "통화", "싱크", "Sinks", "IAA", "IAP", "PBR", "가격", "지표", "수도꼭지", "배수구", "보상", "난이도"); target = "Economics & Algorithms" },
@{ keywords = @("ndf", "parse", "WME", "War-Yes", "Warno-Armory", "파싱", "도구", "스크립트", "LOD", "렌더링", "Telemetry", "텔레메트리"); target = "Programming & Tools" },
@{ keywords = @("심리", "행동", "손실", "게이미피케이션", "사회", "Sociology", "대수"); target = "Psychology & Behavior" },
@{ keywords = @("Pocket Land", "Nexus Gaming", "Magic Sort", "WoW 토큰", "PLEX", "디아블로"); target = "General Knowledge" }
)
$files = Get-ChildItem -Path $rawDir -Filter "*.md"
foreach ($file in $files) {
$targetFolder = "General Knowledge" # Default fallback
$found = $false
foreach ($rule in $rules) {
foreach ($keyword in $rule.keywords) {
if ($file.Name -like "*$keyword*") {
$targetFolder = $rule.target
$found = $true
break
}
}
if ($found) { break }
}
$dstDir = Join-Path $targetBase $targetFolder
if (-not (Test-Path $dstDir)) { New-Item -ItemType Directory -Path $dstDir -Force | Out-Null }
$dstPath = Join-Path $dstDir $file.Name
# Process Content
$content = Get-Content $file.FullName -Raw
# Standardize H1: # [[Title]] -> # Title
$content = $content -replace '# \[\[(.*?)\]\]', '# $1'
# Metadata Insertion
$frontmatter = @"
---
category: $($targetFolder)
status: Final
converted_at: 2026-04-28
---
"@
$newContent = $frontmatter + $content
# Atomic Write & Delete
try {
[System.IO.File]::WriteAllText($dstPath, $newContent, [System.Text.Encoding]::UTF8)
if (Test-Path $dstPath) {
Remove-Item $file.FullName -Force
Write-Host "Success: $($file.Name) -> $($targetFolder)"
}
} catch {
Write-Host "Error processing $($file.Name): $($_.Exception.Message)"
}
}