|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { readFileSync, writeFileSync } from 'fs'; |
| 4 | +import { join, dirname } from 'path'; |
| 5 | +import { fileURLToPath } from 'url'; |
| 6 | +import { marked } from 'marked'; |
| 7 | + |
| 8 | +const __filename = fileURLToPath(import.meta.url); |
| 9 | +const __dirname = dirname(__filename); |
| 10 | + |
| 11 | +// Paths |
| 12 | +const projectRoot = join(__dirname, '../..'); |
| 13 | +const docPath = join(projectRoot, 'docs/openclaw-integration-en.md'); |
| 14 | +const distIndexPath = join(__dirname, '../dist/index.html'); |
| 15 | + |
| 16 | +console.log('📄 Reading markdown document...'); |
| 17 | +const markdownContent = readFileSync(docPath, 'utf-8'); |
| 18 | + |
| 19 | +console.log('🔄 Converting markdown to HTML...'); |
| 20 | +const htmlContent = marked.parse(markdownContent); |
| 21 | + |
| 22 | +console.log('📝 Reading dist/index.html...'); |
| 23 | +const indexHtml = readFileSync(distIndexPath, 'utf-8'); |
| 24 | + |
| 25 | +// Create the hidden SEO container |
| 26 | +const seoContainer = ` |
| 27 | + <!-- SEO: Hidden documentation for web crawlers --> |
| 28 | + <div id="seo-docs" style="position:absolute;left:-9999px;top:-9999px;overflow:hidden;width:1px;height:1px;" aria-hidden="true"> |
| 29 | + ${htmlContent} |
| 30 | + </div> |
| 31 | +`; |
| 32 | + |
| 33 | +// Inject before <div id="root"> |
| 34 | +const injectedHtml = indexHtml.replace( |
| 35 | + /<div id="root">/, |
| 36 | + `${seoContainer}\n <div id="root">` |
| 37 | +); |
| 38 | + |
| 39 | +console.log('💾 Writing updated index.html...'); |
| 40 | +writeFileSync(distIndexPath, injectedHtml, 'utf-8'); |
| 41 | + |
| 42 | +console.log('✅ Documentation injected successfully!'); |
| 43 | +console.log(` - Source: ${docPath}`); |
| 44 | +console.log(` - Target: ${distIndexPath}`); |
| 45 | +console.log(` - Content size: ~${Math.round(htmlContent.length / 1024)}KB`); |
0 commit comments