Skip to content

Rename Markdown files based on h1 titles #12

Rename Markdown files based on h1 titles

Rename Markdown files based on h1 titles #12

name: Rename and Commit Markdown Files
on:
push:
branches:
- main # main λΈŒλžœμΉ˜μ— ν‘Έμ‹œλ  λ•Œ μ›Œν¬ν”Œλ‘œμš° 트리거
workflow_dispatch: # μˆ˜λ™μœΌλ‘œ μ›Œν¬ν”Œλ‘œμš°λ₯Ό μ‹€ν–‰ν•  수 μžˆλŠ” μ˜΅μ…˜
jobs:
process-markdown:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITBOOKKEY }}
fetch-depth: 0
ref: main
- name: Set UTF-8 Encoding
run: |
export LC_CTYPE="UTF-8" # UTF-8 인코딩을 λͺ…μ‹œμ μœΌλ‘œ μ„€μ •
- name: Rename Markdown files
run: |
for file in developLog/*.md; do
# 첫 번째 H1 제λͺ©μ„ μΆ”μΆœν•˜μ—¬ 제λͺ©μœΌλ‘œ μ‚¬μš©
title=$(grep -m 1 '^# ' "$file" | sed 's/^# //')
if [ -n "$title" ]; then
# μƒˆ 파일λͺ…을 제λͺ©μ„ 기반으둜 생성
new_filename="title.md"
# 파일 이름이 λ™μΌν•œ κ²½μš°μ—λŠ” mv λͺ…령을 κ±΄λ„ˆλœλ‹ˆλ‹€
if [ "$file" != "$new_filename" ]; then
echo "Renaming $file to $new_filename" # 디버그 정보 좜λ ₯
mv "$file" "$new_filename"
else
echo "File $file already has the correct name, skipping rename."
fi
else
echo "No H1 title found in $file, skipping rename."
fi
done
- name: Commit changes
run: |
git add -A # λͺ¨λ“  변경사항 μΆ”κ°€
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git diff --staged --quiet || git commit -m "Rename Markdown files based on h1 titles"
git push https://${{ secrets.GITBOOKKEY }}@github.com/GoldenPearls/gitBook.git # 변경사항을 main 브랜치둜 ν‘Έμ‹œ