diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9dc6dd08..9b653926 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -57,6 +57,7 @@ jobs: - name: Checkout uses: actions/checkout@v3 with: + path: ./www.byjp.me submodules: recursive - name: Setup Pages id: pages @@ -69,19 +70,35 @@ jobs: path: /tmp/hugo key: ${{ env.cache-name }} - name: Build site - run: task build + working-directory: ./www.byjp.me + run: | + task build + mv ./public/index.redirects ../new_redirects + - name: Upload site artifact uses: actions/upload-pages-artifact@v1 with: name: site - path: ./public + path: ./www.byjp.me/public + + - name: Checkout byjp.fyi + uses: actions/checkout@v4 + with: + repository: by-jp/byjp.fyi + path: ./byjp.fyi + token: ${{ secrets.GITHUB_PAT }} + - name: Update blog shortlinks + working-directory: ./byjp.fyi + run: cat ../new_redirects | tools/redirects/update-shortlinks.bash + - name: Build Gemini capsule + working-directory: ./www.byjp.me run: task gemini-reduce - name: Upload capsule artifact uses: actions/upload-pages-artifact@v1 with: name: capsule - path: ./public + path: ./www.byjp.me/public # Deployment job diff --git a/tools/redirects/update-shortlinks.bash b/tools/redirects/update-shortlinks.bash index 230c9306..46067ab0 100755 --- a/tools/redirects/update-shortlinks.bash +++ b/tools/redirects/update-shortlinks.bash @@ -18,6 +18,8 @@ mv public/_redirects public/_redirects.previous find public -type f -iname "_redirects" -delete # Create local _redirects files +echo "Sorting shortlinks into different directory _redirects files…" + while IFS=$'\n' read -r line do # Extract the absolute file path @@ -29,9 +31,11 @@ do else echo $line >> "public/_redirects" fi -done < "${1:-/dev/stdin}" +done < /dev/stdin # Combine new (root) _redirects and _redirects.previous +echo "Merging with existing links…" + start_line=$(awk '/^# From blog/{print NR; exit}' public/_redirects.previous) end_line=$(awk 'NR > '"$start_line"' && /^#/{print NR; exit}' public/_redirects.previous) @@ -42,3 +46,15 @@ awk 'NR=='"$((start_line + 1))"'{system("cat public/_redirects")} 1' old_removed mv public/_redirects.new public/_redirects rm public/_redirects.previous rm old_removed.txt + +# Push changes +echo "Pushing to github…" + +git add -A +git commit -m "Update blog shortlinks" +git push -q + +# Clean up +rm -r ${workdir} + +echo "All files cleaned up; update complete!"