ZMediumToMarkdown #293
This file contains hidden or 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: ZMediumToMarkdown | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "10 1 15 * *" # At 01:10 on day-of-month 15. | |
| permissions: | |
| contents: write | |
| jobs: | |
| ZMediumToMarkdown: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: 3.4.2 | |
| - run: gem install ZMediumToMarkdown | |
| shell: bash | |
| - name: MV posts to root | |
| run: | | |
| mkdir -p ./_posts/zmediumtomarkdown/ | |
| mv ./_posts/zh-tw/zmediumtomarkdown/* ./_posts/zmediumtomarkdown/ | |
| - name: update unlisted posts | |
| run: | | |
| echo "PWD: $(pwd)" | |
| echo "Repo root files:" | |
| ls -la | sed -n '1,200p' | |
| if [[ ! -f unlist.txt ]]; then | |
| echo "❌ unlist.txt not found in repo root" | |
| exit 1 | |
| fi | |
| echo "---- Preview unlist.txt (show control chars) ----" | |
| nl -ba unlist.txt | sed -n '1,200p' | sed 's/\r$//' | |
| # 確認 CLI 存在 | |
| command -v ZMediumToMarkdown >/dev/null || { echo "❌ ZMediumToMarkdown not in PATH"; exit 1; } | |
| echo "ZMediumToMarkdown path: $(command -v ZMediumToMarkdown)" | |
| # 過濾:去 CR、修剪空白、跳過空白/註解行 | |
| count=0 | |
| sed 's/\r$//' unlist.txt \ | |
| | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \ | |
| | awk 'NF && $0 !~ /^[[:space:]]*#/' \ | |
| | while IFS= read -r line; do | |
| echo "▶ ZMediumToMarkdown -k '$line'" | |
| ZMediumToMarkdown -k "$line" \ | |
| --cookie_uid "${{ secrets.MEDIUM_COOKIE_UID }}" \ | |
| --cookie_sid "${{ secrets.MEDIUM_COOKIE_SID }}" \ | |
| -j zhgchgli | |
| count=$((count+1)) | |
| done | |
| # 上面 while 在 subshell 中執行,若需要在這裡拿到 count,可改用暫存檔或用 xargs 方案(見下) | |
| echo "✅ update unlisted posts step finished." | |
| shell: bash | |
| - run: ZMediumToMarkdown --cookie_uid ${{ secrets.MEDIUM_COOKIE_UID }} --cookie_sid ${{ secrets.MEDIUM_COOKIE_SID }} -j zhgchgli | |
| shell: bash | |
| - name: MV posts to zh-tw | |
| run: mv ./_posts/zmediumtomarkdown/* ./_posts/zh-tw/zmediumtomarkdown/ | |
| - name: 🐍 Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| - name: 📦 Install Poetry | |
| uses: abatilo/actions-poetry@v3 | |
| with: | |
| poetry-version: 2.1.4 | |
| - name: 🔧 Install dependencies | |
| working-directory: ./tools/zhgchgli | |
| run: poetry install | |
| - name: Execute | |
| working-directory: ./tools/zhgchgli | |
| run: | | |
| poetry run optimizePhotos | |
| poetry run seoMaker --api-key ${{ secrets.OPENAI_API_KEY }} | |
| poetry run aioMaker --api-key ${{ secrets.OPENAI_API_KEY }} | |
| poetry run translator --api-key ${{ secrets.OPENAI_API_KEY }} | |
| poetry run translator_cn | |
| poetry run unifyAllTags | |
| - uses: stefanzweifel/git-auto-commit-action@v4 | |
| with: | |
| commit_message: "Update fetched posts." | |
| commit_user_name: "ZMediumToMarkdown" | |
| commit_user_email: "[email protected]" | |
| commit_author: ZMediumToMarkdown <[email protected]> |