NExT FC2 BLOG to WordPress Importer
FC2 BLOG to WordPress Importer - WP-CLI plugin to import FC2 blog posts to WordPress
by NExT-Season · github.com/atsushia/next-fc2blog2wp · website
★ 0stars
0forks
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/atsushia/next-fc2blog2wp/archive/refs/heads/main.zipFC2 BLOG to WordPress Importer
FC2ブログの記事を WordPress へインポートする WP-CLI プラグインです。 記事データ・画像・カテゴリー・タグ・公開日・コメントをまとめてインポートし、本文は Gutenberg ブロックとして取り込みます。
ameblo2wp と同様のアーキテクチャ・コマンド体系を採用しています。
機能
- FC2ブログの全記事をスクレイピングして WordPress へインポート
- 月別アーカイブを巡回して全記事 URL を自動収集
- 記事本文を Gutenberg ブロック(paragraph / image / heading / list など)に変換
- FC2 CDN 画像(
blog-imgs-*.fc2.com)を WordPress メディアライブラリへ登録・URL 置換 - カテゴリー・タグ・公開日を保持
- コメントのインポートに対応
- 進捗をファイルに保存し、中断・再開が可能
必要環境
- WordPress 5.0 以上
- WP-CLI
- PHP 7.4 以上
インストール
cd wp-content/plugins
git clone https://github.com/AtsushiA/NExT-fc2blog2wp.git
WordPress 管理画面でプラグインを有効化してください。
使い方
基本構文
wp fc2 import <blog_url> [--with-images] [--with-comments] [--reset]
オプション
| オプション | 説明 |
|---|---|
<blog_url> |
FC2ブログの URL(例: https://example.blog.fc2.com/) |
--with-images |
画像を WordPress メディアライブラリへインポートする |
--with-comments |
コメントをインポートする |
--reset |
進捗をリセットして最初から実行する |
使用例
# 記事のみインポート
wp fc2 import https://example.blog.fc2.com/
# 画像も含めてインポート
wp fc2 import https://example.blog.fc2.com/ --with-images
# 画像・コメントも含めてインポート
wp fc2 import https://example.blog.fc2.com/ --with-images --with-comments
# 進捗をリセットして最初から実行
wp fc2 import https://example.blog.fc2.com/ --with-images --reset
処理の流れ
- FC2ブログのトップページからサイドバーの月別アーカイブ URL を収集
- 各月別アーカイブページから記事 URL(
blog-entry-*.html)を収集 - 各記事ページをパースしてタイトル・本文・日付・カテゴリー・タグを取得
- 本文 HTML を Gutenberg ブロックに変換して WordPress に投稿
--with-images指定時: FC2 CDN 画像をダウンロードしてメディア登録・URL 置換--with-comments指定時: コメントを登録- 進捗を
/wp-content/next-fc2blog2wp/<blog-id>/progress.jsonに保存
ファイル構成
NExT-fc2blog2wp/
├── next-fc2blog2wp.php # メインプラグインファイル(WP-CLI 登録)
├── class/
│ ├── fc2_html_parser.php # FC2ブログ HTML パーサー
│ ├── next-fc2blog2wp_class.php # コアインポートロジック
│ └── next-fc2blog2wp_command.php # WP-CLI コマンド実装
├── SPEC.md # 仕様書
└── README.md
開発・テスト
動作要件: PHP 8.3 以上。CI は PHP 8.3 / 8.4 × WordPress(最新・1世代前)のマトリクスで実行されます。
# 依存関係のインストール(開発用)
composer install
# コーディング規約チェック(WordPress Coding Standards)
composer run phpcs # チェック
composer run phpcbf # 自動修正
# 単体テスト(WordPress 不要・ネットワーク不要)
composer run test:unit
# 統合テスト(WordPress テストスイートが必要)
bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest
composer run test:integration
統合テストは Docker + wp-env でも実行できます(.wp-env.json は PHP 8.4 / 最新 WP 設定済み)。
# Docker を起動しておくこと
npx @wordpress/env start
# 統合テスト(実 WordPress・実 DB、tests-cli コンテナ内で実行)
npx @wordpress/env run tests-cli --env-cwd=wp-content/plugins/NExT-fc2blog2wp \
vendor/bin/phpunit --testsuite integration --bootstrap tests/phpunit/bootstrap.php
# 単体テストも同様に実行可能
npx @wordpress/env run tests-cli --env-cwd=wp-content/plugins/NExT-fc2blog2wp \
vendor/bin/phpunit --testsuite unit
tests/phpunit/unit/… HTML パース・ブロック変換など純粋ロジックの単体テストtests/phpunit/integration/…wp_insert_post()等 WordPress 依存処理の統合テスト- GitHub Actions:
.github/workflows/ci.yml(phpcs / PHPUnit / Plugin Check)、.github/workflows/release.yml(v0.0.0タグで配布用 zip を Release に添付)
変更履歴
0.4.0
- PHP 8.3 / 8.4 対応(
mb_convert_encoding(..., 'HTML-ENTITIES')をmb_encode_numericentity()に置き換え、非推奨警告を解消) - 開発・テスト基盤を整備
- phpcs(WordPress Coding Standards)/ PHPUnit(単体・統合)を追加
- GitHub Actions による CI(マトリクステスト・Plugin Check)と自動リリースを追加
- 内部名を
NExTブランドへ統一(クラス名・ファイル名・テキストドメイン・一時データ保存先)
0.3.0
- Gutenberg ブロック変換ロジックを全面改善
- FC2ブログの
div.entryText内フラット HTML を正しく変換するよう対応 processChildNodes()を追加:divを再帰処理して子ノードをブロックに変換inlinesToParagraphs()を追加:<br>区切りのインライン要素を段落ブロックに変換<a><img></a>パターンを画像ブロックとして正しく変換<hr>を区切りブロック(wp:separator)に変換
- FC2ブログの
0.2.0
exec()+ WP-CLI 子プロセス呼び出しを WordPress API に置き換えwp_insert_post()で記事を作成するよう変更media_handle_sideload()で画像をメディアライブラリへ登録するよう変更wp_update_post()で記事を更新するよう変更wp_insert_comment()でコメントを登録するよう変更
- エックスサーバー等の環境で
escapeshellarg()がシェルのロケール依存でマルチバイト文字を消去し、タイトルが(no title)になる問題を修正
0.1.0
- 初回リリース
ライセンス
GPL-2.0-or-later