on:
push:
branches:
- main
paths:
- 'content-production/**/*.md'
- 'foreign-lang/**/*.md'
- 'webdev/**/*.md'
- '.github/workflows/update-indexes.yml'
def update_index_file(index_path, folder_path, is_foreign_lang=False):
# H1 태그 찾기
h1_match = re.search(r'^# .*$', content, re.MULTILINE)
if not h1_match:
print(f"Warning: No H1 header found in {index_path}")
return False
h1_pos = h1_match.end()
# Last updated 섹션 업데이트 또는 추가
last_updated = f"\n#### Last updated: {get_korean_time()}\n"
if '#### Last updated:' in content:
content = re.sub(r'#### Last updated:.*\n', last_updated, content)
else:
# H1 바로 다음에 Last updated 추가
content = content[:h1_pos] + last_updated + content[h1_pos:]
if is_foreign_lang:
# foreign-lang 폴더 특별 처리
for section, folder in [('## English', 'en'), ('## Japanese', 'jp')]:
section_match = re.search(f'{section}.*?\n', content)
if section_match:
section_pos = section_match.end()
# 해당 언어 폴더의 파일들 수집
md_files = []
target_folder = os.path.join(folder_path, folder)
if os.path.exists(target_folder):
for file in os.listdir(target_folder):
if re.match(r'^\d{8}\.md$', file):
date_str = file[:8]
formatted_date = f"{date_str[:4]}-{date_str[4:6]}-{date_str[6:8]}"
link_path = f"{folder}/{file}"
if f"]({link_path})" not in content: # 중복 체크
md_files.append((formatted_date, link_path))
# 정렬된 링크 추가
for date, link in sorted(md_files):
content = content[:section_pos] + f"- [{date}]({link})\n" + content[section_pos:]