Skip to content

Commit 9479e77

Browse files
dongmucatvsxd
authored andcommitted
feat(web): inject OpenClaw integration docs into build output for SEO
1 parent 605f36e commit 9479e77

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"install:ci": "pnpm install --frozen-lockfile",
88
"dev": "vite",
9-
"build": "tsc -b && vite build",
9+
"build": "tsc -b && vite build && node scripts/inject-docs.mjs",
1010
"preview": "vite preview",
1111
"test": "vitest run",
1212
"typecheck": "tsc --noEmit",
@@ -28,9 +28,9 @@
2828
"react-dropzone": "^15.0.0",
2929
"react-i18next": "^16.5.8",
3030
"react-markdown": "^10.1.0",
31-
"remark-frontmatter": "^5.0.0",
3231
"rehype-highlight": "^7.0.2",
3332
"rehype-sanitize": "^6.0.0",
33+
"remark-frontmatter": "^5.0.0",
3434
"remark-gfm": "^4.0.1",
3535
"sonner": "^2.0.7",
3636
"tailwind-merge": "^2.2.1",
@@ -48,6 +48,7 @@
4848
"eslint": "^8.57.0",
4949
"eslint-plugin-react-hooks": "^4.6.0",
5050
"eslint-plugin-react-refresh": "^0.4.5",
51+
"marked": "^15.0.12",
5152
"openapi-typescript": "^7.6.1",
5253
"postcss": "^8.4.0",
5354
"tailwindcss": "^3.4.0",

web/pnpm-lock.yaml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/scripts/inject-docs.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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

Comments
 (0)