sordahl/webflow-parser
最新稳定版本:1.1.10
Composer 安装命令:
composer require sordahl/webflow-parser
包简介
Webflow site parser to static html with local assets and translations
README 文档
README
A comprehensive PHP-based static site generator for Webflow sites with multi-language support, automatic sitemap generation, and SEO optimization.
Features
- 🌍 Multi-language support - Automatically generates locale-specific pages
- 🗺️ Auto-detecting sitemap - Automatically detects supported languages and creates SEO-optimized sitemap.xml
- 🤖 Robots.txt generation - Automatically generated with sitemap reference
- 🏷️ Open Graph tags - Includes og:site_name and other meta tags for social sharing
- 🔄 Translation system - Compares JSON DOM structures to generate accurate translations
- 📦 Asset management - Downloads and manages external assets locally
- 🔗 SEO optimized - Proper hreflang tags, alternate links, and meta translations
- ⚡ Unified generator - Single command to generate complete site
- 🗜️ Minification - Compresses inline CSS and JavaScript for faster page loads
Quick Start
Prerequisites
- PHP 8.3 or higher
- Composer
- Webflow API key
Installation
- Install dependencies:
composer install
- Create
.envfile with your Webflow API key:
echo 'WEBFLOW_API="your-api-key-here"' . PHP_EOL > .env
Generate Your Site
Simply run the unified generator script:
php generate-site.php
This single command will:
- ✅ Fetch and generate all locale-specific HTML pages
- ✅ Generate sitemap.xml with auto-detected languages
- ✅ Generate robots.txt
- ✅ Copy public files to dist directory
Architecture
Core Classes
WebflowLocaleFetcher- Main orchestrator for fetching and generating locale-specific pagesSitemapGenerator- Generates SEO-optimized sitemap.xml and robots.txt with auto-detected localesHtmlProcessor- Processes and transforms HTML (cleanup, assets, translations, meta tags)TranslationBuilder- Builds translation maps by comparing JSON DOM structuresLocaleGenerator- Generates and saves locale-specific HTML filesWebflowApiClient- Handles all Webflow API interactions
Directory Structure
/
├── generate-site.php # ⭐ Main unified generator (use this!)
├── generate-locale-pages.php # Legacy: locale pages only
├── generate-sitemap.php # Legacy: sitemap only
├── composer.json
├── .env
└── src/
├── WebflowLocaleFetcher.php # Main orchestrator
├── SitemapGenerator.php # Sitemap & robots.txt generator
├── HtmlProcessor.php # HTML processing & meta tags
├── TranslationBuilder.php # Translation logic
├── LocaleGenerator.php # File generation
└── WebflowApiClient.php # API communication
dist/ # Generated output
├── index.html # Primary language (English)
├── da/ # Danish locale folder
│ └── index.html # Translated Danish page
├── sitemap.xml # SEO sitemap with hreflang
├── robots.txt # Search engine instructions
├── json/ # JSON DOM files
│ ├── page-content-*-default.json
│ └── page-content-*-da.json
└── assets/ # Downloaded assets
├── *.css
├── *.js
└── *.svg
Configuration
Edit the $config array in generate-site.php:
$config = [ 'apiKey' => $apiKey, // From .env file 'siteId' => '<webflow-site-id>', // Your Webflow site ID 'siteUrl' => 'https://example.webflow.io', // Webflow staging URL 'hostUrl' => 'https://example.com', // Your production domain 'outputDir' => __DIR__ . '/dist', // Output directory 'site_name' => 'SiteName', // For og:site_name meta tag // Options 'fetchContent' => true, // Fetch JSON DOM structure 'fetchHtml' => true, // Fetch rendered HTML 'downloadAssets' => true, // Download external assets 'minifyInline' => true, // Minify inline styles and scripts // Pages to exclude by ID 'excludePageIds' => [], ];
How It Works
Translation Process
- Fetch JSON DOM: Downloads JSON representation of page structure from Webflow API
- Compare Structures: Compares primary locale JSON with secondary locale JSON
- Build Translation Map: Creates mapping of original text to translated text
- Apply Translations: Replaces original text in HTML with translations
- Update Meta Tags: Translates SEO titles, descriptions, and Open Graph tags (including og:site_name)
- Fix Paths: Updates relative paths for subdirectory locations
- Add Hreflang: Adds proper language alternate links
Sitemap Generation
- Auto-detect Locales: Scans pages to identify all supported languages automatically
- Group Pages: Groups pages by slug to identify translations
- Build Entries: Creates sitemap entries with proper hreflang alternate links
- Prioritize: Sets priority based on page type (homepage = 1.0, others = 0.8)
- Generate XML: Outputs valid sitemap.xml following sitemaps.org schema
Key Features Explained
Auto-Detecting Sitemap
The SitemapGenerator class automatically detects all supported languages by scanning the pages fetched from Webflow. You don't need to manually configure which languages are supported - just add them in Webflow and the generator will detect and include them in the sitemap.
// This method auto-detects locales from pages private function detectLocales(array $pages): array
Open Graph Site Name
The generator automatically adds og:site_name meta tags to all pages (both primary and translated). Configure it in generate-site.php:
'site_name' => 'SiteName', // Appears as <meta property="og:site_name" content="SiteName">
Hreflang Attributes
All pages automatically get proper hreflang alternate links for SEO:
<!-- Primary page links to Danish --> <link rel="alternate" hreflang="da" href="https://example.com/da/" /> <!-- Danish page links back to primary --> <link rel="alternate" hreflang="en" href="https://exampple.come/" />
Inline Minification
The generator automatically minifies inline <style> and <script> tags to reduce page size and improve load times:
Before minification:
<style type="text/css"> .section-features > .feature-item:nth-child(n + 3) { margin-top: -20vh; } .section-features { overflow-x: clip; } </style>
After minification:
<style type="text/css"> .section-features > .feature-item:nth-child(n + 3) { margin-top: -20vh; } .section-features { overflow-x: clip; } </style>
Features:
- Removes CSS/JS comments
- Removes unnecessary whitespace
- Removes spaces around operators and punctuation
- Preserves functionality while reducing file size
- Can be disabled by setting
'minifyInline' => falsein config
Development
Adding a New Locale
Locales are automatically detected from Webflow! Just add a new locale in your Webflow site settings, and the generator will detect and process it automatically.
Excluding Pages
Add page IDs to the excludePageIds array in generate-site.php:
'excludePageIds' => [ '671d6147172df4affd2ed334', // Page to exclude ],
Custom Meta Tags
To add custom meta tags, modify the HtmlProcessor::addSiteNameMeta() method or create a similar method in src/HtmlProcessor.php.
Legacy Scripts
The following scripts are still available but not recommended for regular use:
generate-locale-pages.php- Generate only locale pages (usegenerate-site.phpinstead)generate-sitemap.php- Generate only sitemap (usegenerate-site.phpinstead)
Troubleshooting
No locales detected
- Check that locales are properly configured in Webflow
- Ensure the Webflow API key has access to the site
Missing translations
- Verify that content exists in both primary and secondary locales in Webflow
- Check the
dist/json/directory for generated JSON files - Review translation pairs count in console output
Broken asset links
- Ensure
downloadAssetsis set totruein config - Check that the
dist/assets/directory has write permissions - Verify external assets are accessible
Sitemap not updating
- Make sure you're running
generate-site.php(not the legacy scripts) - Check that all locales are published in Webflow
- Verify the
hostUrlis correct in config
Performance
- Average generation time: 4-6 seconds (for 2 pages with 2 locales)
- API calls: Approximately 4-6 per page (varies by locale count)
- Output size: ~20KB per page (compressed HTML + assets)
Inspired By
This project uses concepts from WebflowParser for asset management and HTML cleanup.
License
Proprietary - Sordahl ApS
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-28