EmDash 提供從 WordPress 的完整遷移路徑。無需 CLI,在管理後台即可匯入文章、頁面、媒體與分類法。
開始之前
匯出內容
在 WordPress 中前往 工具 → 匯出,下載完整匯出檔(.xml)。
備份網站
確認遷移成功前,請讓 WordPress 網站保持上線。
匯入方式
EmDash 支援三種匯入 WordPress 內容的方式:
| 方式 | 適用情境 | 含草稿 | 需認證 |
|---|---|---|---|
| WXR 檔案上傳 | 完整遷移 | 是 | 否 |
| WordPress.com | 託管於 WordPress.com 的網站 | 是 | OAuth |
| REST API(探測) | 匯出前先檢視內容概要 | 否 | 選用 |
多數遷移建議使用 WXR 檔上傳,可涵蓋草稿、自訂欄位與私密文章等全部內容。
WXR 檔案匯入
-
從 WordPress 匯出
在 WordPress 後台:工具 → 匯出 → 所有內容 → 下載匯出檔。
-
開啟匯入精靈
在 EmDash:管理 → 設定 → 匯入 → WordPress。
-
上傳匯出檔
拖放
.xml或點選瀏覽。檔案在瀏覽器中解析。 -
檢視偵測到的內容
精靈會顯示類似:
Found in export: ├── Posts: 127 → posts [New collection] ├── Pages: 12 → pages [Add fields] └── Media: 89 attachments -
設定對應
選擇要匯入的文章類型。EmDash 會:
- 為未對應的文章類型自動建立集合(collection)
- 為既有集合補上缺少的欄位
- 對欄位型別衝突提出警告
-
執行匯入
點選 匯入內容,可看到每個項目的處理進度。
-
匯入媒體(選用)
內容匯入後,可選擇是否下載媒體檔。EmDash 會:
- 從 WordPress URL 下載
- 以內容雜湊去重
- 自動改寫內容中的 URL
內容轉換
Gutenberg 到 Portable Text
EmDash 將 Gutenberg 區塊轉為 Portable Text 結構化格式。
| Gutenberg 區塊 | Portable Text | 說明 |
|---|---|---|
core/paragraph | block style=“normal” | 保留行內標記 |
core/heading | block style=“h1-h6” | 層級來自區塊屬性 |
core/image | image 區塊 | 更新媒體參照 |
core/list | 含 listItem 型別的 block | 有序與無序清單 |
core/quote | block style=“blockquote” | 含引用資訊 |
core/code | code 區塊 | 保留語言屬性 |
core/embed | embed 區塊 | 儲存 URL 與提供者 |
core/gallery | gallery 區塊 | 圖片參照陣列 |
core/columns | columns 區塊 | 保留巢狀內容 |
| 未知區塊 | htmlBlock | 保留原始 HTML 供複查 |
未知區塊以 htmlBlock 儲存,附原始 HTML 與區塊中繼資料。可手動處理或撰寫自訂 Portable Text 元件渲染。
傳統編輯器內容
傳統編輯器的 HTML 會轉成 Portable Text 區塊。行內樣式(<strong>、<em>、<a>)變成 span 上的標記。
狀態對應
| WordPress 狀態 | EmDash 狀態 |
|---|---|
publish | published |
draft | draft |
pending | pending |
private | private |
future | scheduled |
trash | archived |
分類法匯入
分類與標籤以分類法匯入,階層保留:
WordPress: EmDash:
├── Categories (hierarchical) ├── taxonomies table
│ ├── News │ ├── category/news
│ │ ├── Local │ ├── category/local (parent: news)
│ │ └── World │ ├── category/world (parent: news)
│ └── Sports │ └── category/sports
└── Tags (flat) └── content_taxonomies junction
├── featured ├── tag/featured
└── breaking └── tag/breaking
自訂欄位與 ACF
文章詮釋資料與 ACF 欄位會在匯入時分析:
-
分析階段
精靈會偵測自訂欄位並建議 EmDash 欄位型別:
Custom Fields: ├── subtitle (string, 45 posts) ├── _yoast_wpseo_title → seo.title (string, 127 posts) ├── _thumbnail_id → featuredImage (reference, 89 posts) └── price (number, 23 posts) -
欄位對應
以
_edit_、_wp_開頭的內部欄位預設隱藏。SEO 外掛欄位對應到seo物件。 -
型別推斷
EmDash 依值推斷型別:
- 數字字串 →
number "1"、"0"、"true"、"false"→boolean- ISO 日期 →
date - 序列化的 PHP/JSON →
json - WordPress ID(如
_thumbnail_id)→reference
- 數字字串 →
URL 重新導向
匯入後 EmDash 會產生重新導向對照:
{
"redirects": [
{ "from": "/?p=123", "to": "/posts/hello-world" },
{ "from": "/2024/01/hello-world/", "to": "/posts/hello-world" },
{ "from": "/category/news/", "to": "/categories/news" }
],
"feeds": [
{ "from": "/feed/", "to": "/rss.xml" },
{ "from": "/feed/atom/", "to": "/atom.xml" }
]
}
可套用至:
- Cloudflare 重新導向規則
- 主機平台的重新導向設定
astro.config.mjs中 Astro 的redirects選項
概念對照表
將 WordPress 慣例對應到 EmDash 時可參考:
| WordPress | EmDash | 說明 |
|---|---|---|
register_post_type() | 管理後台中的集合 | 透過控制台或 API 建立 |
register_taxonomy() | 分類法或陣列欄位 | 視複雜度而定 |
register_meta() | 集合 schema 中的欄位 | 有型別,非任意鍵值 |
WP_Query | getCollection(filters) | 執行階段查詢 |
get_post() | getEntry(collection, id) | 回傳項目或 null |
wp_insert_post() | POST /_emdash/api/content/{type} | REST API |
the_content | <PortableText value={...} /> | Portable Text 渲染 |
add_shortcode() | Portable Text 自訂區塊 | 自訂渲染元件 |
register_block_type() | Portable Text 自訂區塊 | 與短代碼類似 |
add_menu_page() | 外掛管理頁 | 位於 /_emdash/admin/ 下 |
add_action/filter() | 外掛勾點 | 如 hooks.content:beforeSave |
wp_options | ctx.kv | 鍵值儲存 |
wp_postmeta | 集合欄位 | 結構化儲存 |
$wpdb | ctx.storage | 直接存取儲存層 |
| 分類/標籤 | 分類法 | 保留階層 |
API 匯入(進階)
WordPress 匯入可透過管理後台與 REST API 使用。為取得欄位對應、衝突處理與進度追蹤,建議使用匯入精靈。
程式化存取使用 /_emdash/api/import/wordpress/ 下的端點。
疑難排解
「XML parsing error」
匯出檔可能損毀或不完整,請從 WordPress 重新匯出。
媒體下載失敗
部分圖片可能需登入或 URL 已變更。匯入會繼續,失敗的 URL 會記錄。
欄位型別衝突
若既有集合中有不相容型別的欄位,精靈會提示衝突。您可以:
- 重新命名 EmDash 中的欄位
- 調整 WordPress 欄位對應
- 刪除並重建該集合
超大匯出
超過約 100MB 時建議:
- 在 WordPress 依文章類型分別匯出
- 依序逐檔匯入
- 使用含
--resume的 CLI 以提高可靠度
下一步
- Content Import — 其他匯入來源與方式
- Plugin Porting — 遷移 WordPress 外掛能力
- Working with Content — 查詢與渲染已匯入內容