GITBOOK-143: No subject #289
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Rename and Add New Markdown Files | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
process-markdown: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITBOOKKEY }} | |
fetch-depth: 1 | |
- name: Set UTF-8 Encoding | |
run: | | |
export LC_CTYPE="UTF-8" | |
- name: Rename and Copy Markdown files to koreanPageTitle, Rename Folders Based on README H1 | |
run: | | |
for file in $(find developLog -type f -name '*.md'); do | |
if [ -f "$dir/README.md" ]; then | |
# README.md νμΌμμ H1 μ λͺ©μ μΆμΆ | |
title=$(grep -m 1 '^#' "$dir/README.md" | sed 's/^# //') | |
if [ -n "$title" ]; then | |
# μ ν΄λ μ΄λ¦ μ€μ | |
parent_dir=$(dirname "$dir") | |
new_folder_name="$parent_dir/$title" | |
# ν΄λ μ΄λ¦ λ³κ²½ | |
if [ "$dir" != "$new_folder_name" ]; then | |
echo "Renaming folder $dir to $new_folder_name" | |
mv "$dir" "$new_folder_name" | |
else | |
echo "Folder $dir already has the correct name." | |
fi | |
else | |
echo "No valid H1 title found in $dir/README.md" | |
fi | |
fi | |
# Markdown νμΌ λ³΅μ¬ λ° μ΄λ¦ λ³κ²½ | |
if [[ "$file" == *"README.md" ]] || [[ "$file" == *"SUMMARY.md" ]]; then | |
echo "Skipping $file" | |
continue | |
fi | |
title=$(grep -m 1 '^#' "$file" | sed 's/^# //') | |
if [ -n "$title" ]; then | |
dir=$(dirname "$file") | |
new_dir="koreanPageTitle/$dir" | |
new_filename="$new_dir/$title.md" | |
mkdir -p "$new_dir" | |
if [ -f "$new_filename" ]; then | |
if cmp -s "$file" "$new_filename"; then | |
echo "File $new_filename already exists and is identical. Skipping..." | |
else | |
echo "File $new_filename already exists but is different. Overwriting with new file." | |
cp "$file" "$new_filename" | |
fi | |
else | |
echo "Copying $file to $new_filename" | |
cp "$file" "$new_filename" | |
fi | |
else | |
echo "No valid title found in $file, skipping." | |
fi | |
done | |
# .gitbook/assets λλ ν 리 λ³΅μ¬ | |
if [ -d "developLog/.gitbook/assets" ]; then | |
mkdir -p "koreanPageTitle/developLog/.gitbook/assets" | |
cp -r developLog/.gitbook/assets/* koreanPageTitle/developLog/.gitbook/assets/ | |
echo ".gitbook/assets directory copied to koreanPageTitle/developLog" | |
fi | |
- name: Commit changes in koreanPageTitle | |
run: | | |
cd koreanPageTitle | |
git init | |
git add -A | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git commit -m "Rename and update Markdown files based on h1 titles in koreanPageTitle" | |
git push https://${{ secrets.GITBOOKKEY }}@github.com/GoldenPearls/gitBook.git master:koreanPageTitle --force |