当前位置: 首页 > Skill >

WordPress to Static Site

WordPress to Static Site

1.2.0 2026.11.27 浏览:288
获取Skill文件查看使用说明
作者:林澄许可证:
本文目录展开

WordPress to Static Site (Cloudflare Pages)

Convert a WordPress website to a pixel-perfect static site and deploy it to Cloudflare Pages. Zero attack surface, zero hosting cost, instant load times.

Prerequisites

Before running this skill, the user MUST have:

  1. GitHub CLI authenticated: Run gh auth status to verify. If not logged in, run gh auth login first.
  2. Cloudflare Wrangler authenticated: Run wrangler whoami to verify. If not logged in, run wrangler login first.
  3. SSH key added to ssh-agent: The recommended way to handle SSH keys. Run:
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/your_wp_key
    
  4. Server host key verified: The user should have connected to the server at least once and accepted the host key, so it exists in ~/.ssh/known_hosts.

Environment Variables

Required (stop and ask if any are missing):

  • WP_SSH_HOST — SSH hostname (e.g., ssh.example.com)
  • WP_SSH_USER — SSH username
  • WP_SSH_PORT — SSH port (e.g., 18765)
  • WP_SSH_KEY — Path to SSH private key file (e.g., ~/.ssh/wp_key). Key must have chmod 600 permissions.
  • WP_SITE_URL — WordPress site URL (e.g., https://example.com)
  • WP_SITE_NAME — Short project name (e.g., mysite)

Optional:

  • CF_ACCOUNT_ID — Cloudflare account ID for Pages deployment
  • GH_REPO_VISIBILITY — private (default) or public

Security Model

  • SSH authentication uses ssh-agent — keys are loaded into the agent before running, so no passphrase is passed via environment variables or command arguments
  • SSH host key verification is ENABLED (no StrictHostKeyChecking=no) — the server must already be in ~/.ssh/known_hosts
  • Credentials are NEVER logged, echoed, or displayed
  • Credentials are NEVER committed to git
  • GitHub repos are created as private by default

Step 0: Validate

  1. Check all required env vars are set. If any are missing, stop and tell the user.
  2. Verify required binaries exist: ssh, ssh-agent, rsync, curl, git, gh, wrangler.
  3. Verify gh auth status succeeds. If not, tell user to run gh auth login.
  4. Verify wrangler whoami succeeds (if CF_ACCOUNT_ID is set). If not, tell user to run wrangler login.
  5. Verify SSH key file exists and has correct permissions (chmod 600).
  6. Stop if anything is missing.

Step 1: Test SSH Connection

Test the connection using the key from ssh-agent:

ssh -i $WP_SSH_KEY -p $WP_SSH_PORT $WP_SSH_USER@$WP_SSH_HOST "echo connected"

If the key requires a passphrase and ssh-agent is not loaded, tell the user:

Please add your SSH key to ssh-agent first:
  eval "$(ssh-agent -s)"
  ssh-add /path/to/your/key
Then re-run /wp-to-static

If the host key is not recognized, tell the user to connect manually once first to verify and accept the host key:

Please connect to the server once manually to verify the host key:
  ssh -i $WP_SSH_KEY -p $WP_SSH_PORT $WP_SSH_USER@$WP_SSH_HOST
Accept the host key, then re-run /wp-to-static

Do NOT use StrictHostKeyChecking=no. Do NOT bypass host key verification.

Step 2: Locate WordPress Installation

SSH in and find the WordPress public_html directory. Common locations:

  • ~/www/DOMAIN/public_html/
  • ~/public_html/
  • ~/htdocs/
  • /var/www/html/

Confirm by finding wp-config.php. Store path as WP_ROOT.

Step 3: Mirror with wget (ON THE SERVER)

Run wget --mirror on the server (not locally):

cd /tmp && rm -rf static_mirror && mkdir -p static_mirror && cd static_mirror && 
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent 
  --restrict-file-names=windows -e robots=off --timeout=30 --tries=3 --wait=0.5 
  --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" 
  $WP_SITE_URL/ 2>&1 | tail -30

If wget is not available on the server, fall back to curl locally for rendered HTML.

Step 4: Rsync to Local

Create ./build/site (NEVER use the project root as temp dir).

Exclude server-side code and sensitive files. Only static assets (images, CSS, JS, fonts) are needed. PHP files, config files, and other server-side code must NEVER be downloaded.

RSYNC_EXCLUDE="--exclude='*.php' --exclude='wp-config*' --exclude='.htaccess' --exclude='*.sql' --exclude='*.log' --exclude='debug.log' --exclude='error_log' --exclude='.env' --exclude='*.bak' --exclude='*.backup'"

rsync -avz $RSYNC_EXCLUDE server:/tmp/static_mirror/DOMAIN/ ./build/site/
rsync -avz $RSYNC_EXCLUDE server:$WP_ROOT/wp-content/uploads/ ./build/site/wp-content/uploads/
rsync -avz $RSYNC_EXCLUDE server:$WP_ROOT/wp-content/themes/ ./build/site/wp-content/themes/
rsync -avz $RSYNC_EXCLUDE server:$WP_ROOT/wp-content/plugins/ ./build/site/wp-content/plugins/
rsync -avz $RSYNC_EXCLUDE server:$WP_ROOT/wp-includes/ ./build/site/wp-includes/

After rsync, verify no PHP or config files were downloaded:

find ./build/site -name '*.php' -o -name 'wp-config*' -o -name '.htaccess' -o -name '.env' | head -20

If any are found, delete them before proceeding.

Step 5: Extract Only Referenced Assets

This is the key step. Parse all HTML and CSS files to find every referenced local file:

From HTML: src=, href=, data-src=, data-srcset=, srcset=, inline background-image: url()

From CSS: All url() references — resolve relative paths from CSS file location to site root.

Write the list to ./build/referenced-files.txt, then copy only those files to ./public/ preserving directory structure. This typically shrinks 1.5GB+ down to ~25MB.

Step 6: Fix Absolute URLs

In index.html and ALL CSS files:

  1. Replace $WP_SITE_URL/ → empty string (relative paths)
  2. Replace any staging/dev domain URLs → local paths
  3. Self-host Google Fonts:
    • Download each .ttf to ./public/fonts/
    • Update @font-face src: to fonts/filename.ttf
  4. Remove <link rel="preconnect"> for Google Fonts domains

CSS path resolution is critical. If CSS is at wp-content/uploads/cache/file.css:

  • wp-content/uploads/ → ../../
  • wp-content/themes/ → ../../themes/
  • wp-includes/ → ../../../wp-includes/

Step 7: Strip WordPress Cruft

Remove:

  • <meta name="generator" ...> (WordPress, WPBakery, Slider Revolution)
  • <link rel="EditURI"...>, <link rel="alternate"...> (RSS, oEmbed)
  • <link rel="https://api.w.org/"...>, <link rel="shortlink"...>
  • <link rel="profile" href="gmpg.org/xfn/11">
  • <link rel="dns-prefetch"...> for fonts.googleapis.com
  • W3 Total Cache HTML comments
  • wp-json root references in inline JSON

Keep: Email addresses, <link rel="canonical"> (update to /)

Step 8: Cloudflare Pages Config

Create ./public/_headers with aggressive caching for /fonts/*, /wp-content/*, /wp-includes/*.

Create ./public/_redirects redirecting /wp-admin/*, /wp-login.php, /xmlrpc.php, /feed/* → / (302).

Step 9: Verify Locally

  1. Start python3 -m http.server from ./public/
  2. Test key assets return HTTP 200 (CSS, JS, logo, fonts, images)
  3. Tell user to open the URL and visually verify
  4. Wait for user confirmation before deploying

Step 10: Scrub Temporary Files and Deploy

Before any git operations, remove the ./build/ directory to ensure no server-side code, PHP files, or sensitive data can accidentally be committed:

rm -rf ./build

Verify only ./public/ remains and contains no PHP or config files:

find ./public -name '*.php' -o -name 'wp-config*' -o -name '.htaccess' -o -name '.env'

This must return empty. If not, delete those files before proceeding.

Then deploy:

  1. git init, commit ONLY ./public/ and .gitignore
  2. git config http.postBuffer 524288000 (for binary assets)
  3. gh repo create $WP_SITE_NAME --private --source=. --push
  4. CLOUDFLARE_ACCOUNT_ID=$CF_ACCOUNT_ID wrangler pages project create $WP_SITE_NAME --production-branch main
  5. CLOUDFLARE_ACCOUNT_ID=$CF_ACCOUNT_ID wrangler pages deploy ./public --project-name $WP_SITE_NAME
  6. Verify deployment, report live URL, remind about custom domain setup

Safety Rules

  • NEVER display or log credentials (SSH keys, passphrases, tokens)
  • NEVER commit credentials to git (.gitignore must exclude .env, *.key, *.pem)
  • NEVER use StrictHostKeyChecking=no or bypass SSH host verification
  • NEVER pass passphrases as command-line arguments or environment variables at runtime
  • NEVER delete the current working directory (breaks the shell CWD)
  • NEVER force-push or use destructive git commands
  • NEVER rsync PHP files, wp-config, .htaccess, .env, or SQL dumps from the server
  • Use ./build/ for temp files, ./public/ for output — only ./public/ is committed
  • ALWAYS delete ./build/ BEFORE any git operations to prevent accidental commits of server-side files
  • Verify ./public/ contains no PHP or config files before committing
  • Stop and report on any failure — do NOT retry blindly

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,031
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,029
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,017
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,014
OpenAI的Jalapeno芯片未落地,教你分辨300兆瓦算力消息

OpenAI计划在SB Energy租赁的数据中心部署约300兆瓦自研Jalapeno推理芯片,但目前双方仍处于洽谈阶段,交易细节与上线时间表均未公布。本文带你按报道原文核实项目所处阶段,厘清芯片发布、电力功率与实际推理算力的边界,并将融资意向与签约、开工、投运节点分开追踪,避免误将规划容量计入现有算力。

2026.12.02 1,011
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,011
Skill 文件
  • SKILL.md
    • WordPress to Static Site (Cloudflare Pages)
    • Prerequisites
    • Environment Variables
    • Security Model
    • Step 0: Validate
    • Step 1: Test SSH Connection
    • Step 2: Locate WordPress Installation
    • Step 3: Mirror with wget (ON THE SERVER)
    • Step 4: Rsync to Local
    • Step 5: Extract Only Referenced Assets
    • Step 6: Fix Absolute URLs
    • Step 7: Strip WordPress Cruft
    • Step 8: Cloudflare Pages Config
    • Step 9: Verify Locally
    • Step 10: Scrub Temporary Files and Deploy
    • Safety Rules
  • 项目或源文件

相关 Skill

更多
Wordpress AEO Autoblogger Wordpress AEO Autoblogger 自主AEO与SEO内容生成与优化引擎,用于规模化业务运营。适用于Codex需执行端到端程序化SEO的场景。
WordPress REST API CLI WordPress REST API CLI OpenClaw 技能,提供 WordPress REST API 命令行接口,用于文章、页面、分类、标签、用户及自定义请求,使用纯 HTTP。
wordpress-ultimate wordpress-ultimate Three env vars. One script. Your agent manages your entire WordPress site — draft-only safety included.
Develop and harden WordPress plugins with lifecycle and security guardrails Develop and harden WordPress plugins with lifecycle and security guardrails 当代理需要构建、重构、保护或打包具有正确激活钩子、设置处理、卸载行为和数据卫生的WordPress插件时,请使用Automattic官方wp-plugin-development技能。这是一个插件工程手册,而不是通用的WordPress列表。
WordPress MCP WordPress MCP 通过AI Engine的MCP(模型上下文协议)管理WordPress网站。用于创建/编辑文章、SEO分析、数据分析、媒体管理、分类操作、社媒排程、多语言内容(Polylang)及任何WordPress管理任务。需安装免费AI Engine插件并启用MCP服务器。适用于WordPress网站管理、内容工作流或WP相关任务。