Boost Your Hugo Blog with Automated Open Graph Images
前言 / Introduction 突然想讓自己的文章在分享的時候更酷炫,那就試試看 Open Graph (OG) 圖片,可以讓你的連結在 Discord、Twitter、LinkedIn 等平台上顯示精美的預覽卡片。 本文將教你:/ What you’ll learn: 設計 OG 圖片模板 / Design OG image templates 用 Playwright 自動生成圖片 / Auto-generate images with Playwright 整合 GitHub Actions / Integrate with GitHub Actions 自動化部署到 Cloudflare Pages / Deploy to Cloudflare Pages Step 1: Design an HTML Template 建立 og-template/template.html 作為 OG 圖片模板。標準 OG 圖片尺寸為 1200x630px。 <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <style> body { width: 1200px; height: 630px; margin: 0; display: flex; justify-content: center; align-items: center; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); font-family: 'Inter', -apple-system, sans-serif; color: white; text-align: center; padding: 60px; } h1 { font-size: 80px; font-weight: 800; margin: 0; text-shadow: 2px 2px 4px rgba(0,0,0,0.3); } </style> </head> <body> <h1>{{TITLE}}</h1> </body> </html> Tips: ...
When My Email Was Taken, I Built My Own Instead
前言 / Introduction 最近在註冊某個服務時,我的 email 地址竟然被別人註冊走,導致驗證信收不到。 但聯絡客服申訴又過於麻煩,搶回來的機會又很渺茫,與其這樣,不如自己建立一個「可以正常收信」的網域信箱。 於是我用 Cloudflare Email Routing 搭配現有的 Gmail/iOS Mail 完成這件事,以下是我實際操作的流程與心得。 Why using Cloudflare Email Routing 與其再去註冊一個新信箱,不如直接用自己的網域收信,再轉寄到現有的 Gmail 或 iOS Mail。 Cloudflare 的 Email Routing 是免費的、無需自架 Mail Server,也完全不會改變日常的收信方式。 How to Do It Add or Select Your Domain If your domain is already on Cloudflare, just open it. Otherwise, add a new one Enable Email Routing 進入後該網域,在左側的功能列表選「Email」→ 啟用 Email Routing。 Create a Custom Email Address Custom address: hello@yourdomain.com Action: 選擇 “Send to email” Destination: 輸入你要接收的信箱(Gmail / iCloud / Outlook 都可以) Verify and Apply DNS Records ...
Real Concurrency in Python 3.14: InterpreterPoolExecutor and Beyond
前言 / Introduction 隨著 Python 3.14 的正式發布,多線程開發的限制,也隨著下面的改動迎刃而解: Free-threaded mode (PEP 703), Isolated interpreters (PEP 684), And the new InterpreterPoolExecutor (PEP 734), Python can now run true parallel CPU-bound code directly — even within the same process. 下面將展示一些 Example Async I/O CPU-bound parallelism Multicore execution with interpreter pools 1. Classic Problem: Async + CPU Work 如果你遇到需要 You fetch data from multiple APIs (I/O-bound) Then process, analyze, or compress the data (CPU-bound) 在 Python 3.14 之前 ...
The GIL Problem and What Changes in Python 3.13+
前言 / Introduction 我們在上一篇講述了如何有效的處理 I/O bound 的方法,但實際上困擾 Python 開發的問題在於 CPU bound,原因來自 Global Interpreter Lock (GIL)。 這項限制導致 CPU-bound work slow,迫使許多開發者放棄Python,轉而使用其他語言去進行開發。 但這將會是過去式! 從 Python 3.12,尤其是 3.13 and 3.14,Python 進行大量的改動,使其能夠有效的開發多線程: Multiple interpreters running in parallel (PEP 684, PEP 734) Free-threaded mode (PEP 703) New executors like InterpreterPoolExecutor Less performance penalty compared to past experimental builds 在這篇文章將簡短討論 why the GIL was a bottleneck ,過去的情況是如何,以及有甚麼改變。 What the GIL Really Does The Global Interpreter Lock ensures that only one thread executes Python bytecode at a time — even on a multicore machine. ...
Asyncio vs Threads: Avoiding I/O Blocking in Modern Python
前言 / Introduction 在 Python 專案的開發過程,或多或少會碰到需要平行運行的時候,而大多的資料只說使用 asyncio 就可以加速,但實際上執行時,卻還是一樣的緩慢甚至更糟,那或許你也踩到了錯誤使用線程的坑。 在這篇文章,將討論下面幾點: Why I/O-bound and CPU-bound tasks behave differently The right way to use asyncio Why requests.get() blocks async functions- This sets the foundation for understanding Python 3.13 and 3.14 improvements later in the series. I/O-Bound vs CPU-Bound: The Real Difference 在討論 asyncio or threads 之前,我們需要先搞清楚甚麼樣的任務類型是你面對的 Type What slows it down? Best approach I/O-bound Waiting on network, files, DB, API asyncio, threads CPU-bound Calculations, parsing, encoding multiprocessing, free-threading If your app is fetching APIs, reading files, or handling sockets → it’s I/O-bound. If it’s crunching data or doing math → it’s CPU-bound. 本篇文章為了更清楚描述,接下來會專注在 I/O-bound 的討論。 ...