| 开发者 | derickschaefer |
|---|---|
| 更新时间 | 2026年1月22日 11:05 |
| PHP版本: | 7.4 及以上 |
| WordPress版本: | 6.9 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
wp scw-headless convert --cms=sanity
Smart Pattern Detection:
wp scw-headless scan - View cached files
wp scw-headless analyze <file> - Detect patternswp scw-headless convert --cms=sanity - Export to Sanitywp scw-headless patterns - List registered patternswp scw-headless detectors - Show detector moduleswp scw-headless targets - List available CMS platformswp scw-headless info - Show plugin statisticswp scw-headless normalizephp
// Register custom patterns
add_action('stcw_headless_patterns_loaded', function() {
\STCW\Headless\Engine\Detector\PatternRegistry::register('custom_block', [
'selectors' => ['.my-custom-block'],
'extractor' => [MyExtractor::class, 'extract'],
'priority' => 8,
'confidence' => 0.95,
]);
});
How It Works
wp scw-headless scanwp scw-headless analyze /page/wp scw-headless convert --cms=sanitywp scw-headless info to verify installationstcw-headless-assistant folder to /wp-content/plugins/wp scw-headless scan to verify setupwp scw enablewp scw-headless analyze /No, this is a companion plugin that requires Static Cache Wrangler to be installed and active. It converts the HTML files that Static Cache Wrangler generates.
Commands:
wp scw-headless info - Show system status and statisticswp scw-headless scan - List all cached HTML files ready for conversionwp scw-headless analyze <file> - Detect patterns in specific filewp scw-headless patterns - List all registered patterns with confidence scoreswp scw-headless detectors - Show registered detector moduleswp scw-headless convert --cms=sanity - Convert all files to Sanity formatwp scw-headless targets - List available CMS targets
All commands support --format=json for automation.Current (Sanity conversion): The plugin creates a complete export package containing:
data.ndjson - Sanity import data in newline-delimited JSON formatasset-manifest.json - Asset references with URLs and metadataschemas/ - Sanity Studio schema definitionsREADME.md - Import instructions for Sanity.zip archive - Complete package for downloadwp-content/cache/stcw-headless-exports/ .
The plugin uses a sophisticated multi-phase pipeline:
Production Results (cachewrangler.com):
Falls back to rawHtml block type with pattern metadata. You can:
Yes! Three ways:
1. Register patterns via filter:
php
add_action('stcw_headless_patterns_loaded', function() {
\STCW\Headless\Engine\Detector\PatternRegistry::register('my_block', [
'selectors' => ['.my-block-class'],
'extractor' => [MyExtractor::class, 'extract_my_block'],
'priority' => 8,
'confidence' => 0.95,
]);
});
2. Create detector modules (for larger block libraries)
3. Use pattern inheritance:
php
// Extend existing patterns
PatternRegistry::register('custom_button', [
'extends' => 'button', // Inherits base button selectors
'selectors' => ['.my-custom-button'], // Adds custom selectors
]);
Yes! The plugin is designed with a pluggable architecture:
php
// Register custom CMS target
add_action('stcw_headless_register_targets', function() {
$my_target = new My_CMS_Target();
\STCW\Headless\Engine\Target\TargetRegistry::register($my_target);
});
Your target class must implement TargetInterface with methods for convert(), generate_schemas(), and export().
By default, these paths are excluded:
assets/ - Static assets (CSS, JS, images)author/ - Author archivescategory/, tag/ - Taxonomy archivesindex.php/ - WordPress quirksfeed/, wp-json/ - API endpointssitemap/, 404/ - Utility pagesstcw_headless_excluded_paths to customize.WordPress "Posts Page" archives (the page set as your blog index in Settings → Reading) are intentionally skipped because they contain dynamic post loops, not static content. Individual blog posts are converted successfully. To recreate your blog index in Sanity:
groq
*[_type == "post"] | order(publishedAt desc) {
title, slug, excerpt, publishedAt
}Kadence Blocks is currently supported. Support is being considered for Elementor, Otter Blocks, Divi, and more.
v2.1.0 Benchmarks (cachewrangler.com test site):
Yes! Use wp scw-headless analyze <file> to see:
File: index.html (104 KB) Patterns Found: 71 paragraph 20 Confidence: 1.00 heading 15 Confidence: 1.00 separator 14 Confidence: 1.00 kadence_button 6 Confidence: 0.90 kadence_accordion 2 Confidence: 0.95 ... Confidence Distribution: High (≥0.95): 60 Medium (0.85+): 11 Low (<0.85): 0 ```
Static Cache Wrangler may create gzipped files or use compression. The plugin handles this automatically by reading the actual index.html files within cached directories.
stcw_headless_is_enterprise filternormalize command for generic Portable Text export--verbose flag support for detailed output--output=<path> flag to save JSON to fileparse_file())/contact/, contact, /)index.php/, author/admin/)/ now resolves correctly to index.htmlstcw_headless_excluded_pathsinfo command shows full parity with admin dashboardwp scw-headless detectors command to list detector moduleswp scw-headless analyze command for pattern debugging--verbose flag for detailed outputwp scw-headless targets command--cms=<target> flagSTCWSC_* to STCW\Headless\*wp scw-sanity to wp scw-headless