import * as path from 'node:path'; import { fileURLToPath } from 'node:url'; import { defineConfig } from '@rspress/core'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); import { pluginClientRedirects } from '@rspress/plugin-client-redirects'; import { isAnchorOutsideMarkdown } from './plugins/anchor-excludes'; import { pluginGetStartedPages } from './plugins/get-started-pages'; import { pluginMarkdownOutput } from './plugins/markdown-output'; import { getGitHubStars } from './scripts/github-stars'; const SITE_URL = 'https://www.midscenejs.com'; const FAVICON_URL = `${SITE_URL}/favicon.png`; // Bump this version when browsers need to refresh their cached site icon. const FAVICON_LINK_URL = `${FAVICON_URL}?v=20260929`; const OG_IMAGE_URL = `${SITE_URL}/og-image.png`; const SEARCH_IDENTITY_JSON_LD = JSON.stringify({ '@context': 'https://schema.org', '@graph': [ { '@type': 'Organization', '@id': `${SITE_URL}/#organization`, name: 'Midscene.js', url: `${SITE_URL}/`, logo: { '@type': 'ImageObject', url: FAVICON_URL, width: 600, height: 600, }, image: OG_IMAGE_URL, }, { '@type': 'WebSite', '@id': `${SITE_URL}/#website`, name: 'Midscene.js', url: `${SITE_URL}/`, publisher: { '@id': `${SITE_URL}/#organization`, }, }, ], }); export default defineConfig(async () => { const githubStars = await getGitHubStars({ strict: process.env.MIDSCENE_SITE_BUILD === 'true', token: process.env.GITHUB_TOKEN, }); return { root: path.join(__dirname, 'docs'), route: { cleanUrls: true, // MDX fragments imported by pages. They are not pages themselves. exclude: ['**/common/**'], }, title: 'Midscene.js - AI UI Automation and E2E Testing', description: 'Bring AI vision to E2E testing with a newly designed test framework for web, mobile, and desktop apps.', icon: FAVICON_LINK_URL, logo: { light: '/images/brand/midscene_with_text_light.png', dark: '/images/brand/midscene_with_text_dark.png', }, head: [ [ 'link', { rel: 'icon', type: 'image/png', sizes: '600x600', href: FAVICON_LINK_URL, }, ], [ 'link', { rel: 'apple-touch-icon', href: FAVICON_LINK_URL, }, ], // Open Graph [ 'meta', { property: 'og:image', content: OG_IMAGE_URL, }, ], ['meta', { property: 'og:image:width', content: '1200' }], ['meta', { property: 'og:image:height', content: '630' }], ['meta', { property: 'og:image:alt', content: 'Midscene.js logo' }], // Twitter Card ['meta', { name: 'twitter:card', content: 'summary_large_image' }], [ 'meta', { name: 'twitter:image', content: OG_IMAGE_URL, }, ], ['meta', { name: 'twitter:image:alt', content: 'Midscene.js logo' }], // Prevent Bing from selecting arbitrary homepage images as search previews. ['meta', { name: 'bingbot', content: 'max-image-preview:none' }], ``, ], markdown: { link: { checkDeadLinks: true, checkAnchors: { excludes: isAnchorOutsideMarkdown }, }, }, // Render pages, including imported MDX fragments and components, to // Markdown for llms.txt, llms-full.txt, and per-page .md files. llms: true, sitemap: { siteUrl: SITE_URL, }, mediumZoom: { selector: '.rspress-doc img:not(.no-zoom)', }, themeConfig: { lastUpdated: true, llmsUI: { placement: 'outline', }, socialLinks: [ { icon: 'github', mode: 'link', content: 'https://github.com/web-infra-dev/midscene', }, { icon: 'discord', mode: 'link', content: 'https://discord.gg/2JyBHxszE4', }, { icon: 'x', mode: 'link', content: 'https://x.com/midscene_ai', }, { icon: 'lark', mode: 'link', content: 'https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=693v0991-a6bb-4b44-b2e1-365ca0d199ba', }, ], editLink: { docRepoBaseUrl: 'https://github.com/web-infra-dev/midscene/tree/main/apps/site/docs', }, nav: [ { text: 'Versions', items: [ { text: 'Changelog', link: 'https://www.midscenejs.com/changelog', }, { text: 'Midscene.js v0.x', link: 'https://v0.midscenejs.com', }, { text: 'Midscene.js v1.x', link: 'https://www.midscenejs.com', }, ], }, ], sidebar: { '/': [ { sectionHeaderText: 'Discover Midscene', }, { text: 'Introduction', link: '/', }, { text: 'The basics', link: '/basics', }, { text: 'Showcases', link: '/showcases', }, { sectionHeaderText: 'Getting started', }, { text: 'Get started', link: '/get-started', }, { text: 'Control any platform with Skills', link: '/skills', }, { sectionHeaderText: 'Models', }, { text: 'Model selection guide', link: '/model-selection', }, { text: 'Configure a model', collapsible: true, collapsed: false, items: [ { text: 'Use a model API Key', link: '/model-api-setup', }, { text: 'Use a ChatGPT subscription', link: '/chatgpt-subscription', }, { text: 'Advanced configuration & debugging', link: '/model-config', }, ], }, { sectionHeaderText: 'Platform environment setup', }, { text: 'Platform overview', link: '/platforms/', }, { text: 'Set up by platform', collapsible: true, collapsed: false, items: [ { text: 'Web', link: '/platforms/web', }, { text: 'Chrome Bridge', link: '/bridge-mode', }, { text: 'Android', link: '/platforms/android', }, { text: 'iOS', link: '/platforms/ios', }, { text: 'HarmonyOS', link: '/platforms/harmonyos', }, { text: 'Desktop', link: '/platforms/desktop', }, ], }, { sectionHeaderText: 'Midscene Test', }, { text: 'Framework overview', link: '/midscene-test/overview', }, { text: 'Getting started', collapsible: true, collapsed: false, items: [ { text: 'Create a test project', link: '/midscene-test/use', }, { text: 'Write YAML cases', link: '/midscene-test/writing', }, { text: 'Built-in Nodes across platforms', link: '/midscene-test/builtin-nodes', }, { text: 'Run tests', link: '/midscene-test/running', }, ], }, { text: 'Configure and extend', collapsible: true, collapsed: true, items: [ { text: 'Configure test projects', link: '/midscene-test/configuration', }, { text: 'Develop custom Nodes', link: '/midscene-test/extend', }, { text: 'Lifecycle and concurrency', link: '/midscene-test/execution', }, ], }, { sectionHeaderText: 'JavaScript SDK', }, { text: 'Integrate with Playwright Test', link: '/integrate-with-playwright', }, { text: 'Integrate with Rstest', link: '/sdk/rstest', }, { text: 'Integrate with Vitest', link: '/sdk/vitest', }, { text: 'Write standalone automation scripts', link: '/sdk/standalone', }, { text: 'API reference', items: [ { text: 'Shared Agent APIs', link: '/reference/', }, { text: 'Web / Playwright', link: '/sdk/playwright', }, { text: 'Web / Puppeteer', link: '/integrate-with-puppeteer', }, { text: 'Chrome Bridge', link: '/sdk/chrome-bridge', }, { text: 'Android', link: '/sdk/android', }, { text: 'iOS', link: '/sdk/ios', }, { text: 'HarmonyOS', link: '/sdk/harmonyos', }, { text: 'Desktop', link: '/sdk/desktop', }, ], }, { sectionHeaderText: 'Advanced guides', }, { text: 'Provide application knowledge to a GUI Agent', link: '/provide-application-knowledge-to-gui-agent', }, { text: 'Process report files', link: '/consume-report-file', }, { text: 'Write BDD scripts with Gherkin', link: '/advanced/bdd-style-scripts-with-gherkin', }, { text: 'Integrate with any interface', link: '/integrate-with-any-interface', }, { text: 'Cache AI plans & DOM locators', link: '/caching', }, // A group, not a section header, so it can start collapsed. Rspress // expands it when the current page is one of its items. { text: 'Legacy YAML automation', collapsible: true, collapsed: true, items: [ { text: 'YAML script runner', link: '/yaml-script-runner', }, { text: 'Workflow in YAML format', link: '/automate-with-scripts-in-yaml', }, { text: 'Migrate to Midscene Test', link: '/migrate-to-midscene-test', }, ], }, { sectionHeaderText: 'Resources', }, { text: 'FAQ', link: '/faq', }, { text: 'Changelog', link: '/changelog', }, { text: 'Awesome Midscene', link: '/awesome-midscene', }, { text: 'Data privacy', link: '/data-privacy', }, { sectionHeaderText: 'Benchmark', }, { text: 'AndroidWorld benchmark', link: '/android-world-benchmark-report', }, { text: 'MobileWorld benchmark', link: '/mobile-world-benchmark-report', }, { text: 'AppControlBench benchmark', link: '/app-control-bench-report', }, ], '/zh': [ { sectionHeaderText: '了解 Midscene', }, { text: '介绍', link: '/zh/', }, { text: '基本概念', link: '/zh/basics', }, { text: '案例展示', link: '/zh/showcases', }, { sectionHeaderText: '开始使用', }, { text: '开始使用', link: '/zh/get-started', }, { text: '使用 Skills 控制任意平台', link: '/zh/skills', }, { sectionHeaderText: '模型', }, { text: '模型选择指南', link: '/zh/model-selection', }, { text: '配置模型', collapsible: true, collapsed: false, items: [ { text: '使用模型 API Key', link: '/zh/model-api-setup', }, { text: '使用 ChatGPT 订阅', link: '/zh/chatgpt-subscription', }, { text: '高级配置与调试', link: '/zh/model-config', }, ], }, { sectionHeaderText: '平台环境配置', }, { text: '平台概览', link: '/zh/platforms/', }, { text: '按平台配置', collapsible: true, collapsed: false, items: [ { text: 'Web', link: '/zh/platforms/web', }, { text: 'Chrome Bridge', link: '/zh/bridge-mode', }, { text: 'Android', link: '/zh/platforms/android', }, { text: 'iOS', link: '/zh/platforms/ios', }, { text: 'HarmonyOS', link: '/zh/platforms/harmonyos', }, { text: '桌面端', link: '/zh/platforms/desktop', }, ], }, { sectionHeaderText: 'Midscene Test', }, { text: '框架概览', link: '/zh/midscene-test/overview', }, { text: '开始使用', collapsible: true, collapsed: false, items: [ { text: '创建测试项目', link: '/zh/midscene-test/use', }, { text: '编写 YAML 用例', link: '/zh/midscene-test/writing', }, { text: '各平台预置 Node', link: '/zh/midscene-test/builtin-nodes', }, { text: '运行测试', link: '/zh/midscene-test/running', }, ], }, { text: '配置与扩展', collapsible: true, collapsed: true, items: [ { text: '配置测试工程', link: '/zh/midscene-test/configuration', }, { text: '开发自定义 Node', link: '/zh/midscene-test/extend', }, { text: '生命周期与并发', link: '/zh/midscene-test/execution', }, ], }, { sectionHeaderText: 'JavaScript SDK', }, { text: '接入 Playwright Test', link: '/zh/integrate-with-playwright', }, { text: '接入 Rstest', link: '/zh/sdk/rstest', }, { text: '接入 Vitest', link: '/zh/sdk/vitest', }, { text: '编写独立自动化脚本', link: '/zh/sdk/standalone', }, { text: 'API reference', items: [ { text: '通用 Agent API', link: '/zh/reference/', }, { text: 'Web / Playwright', link: '/zh/sdk/playwright', }, { text: 'Web / Puppeteer', link: '/zh/integrate-with-puppeteer', }, { text: 'Chrome Bridge', link: '/zh/sdk/chrome-bridge', }, { text: 'Android', link: '/zh/sdk/android', }, { text: 'iOS', link: '/zh/sdk/ios', }, { text: 'HarmonyOS', link: '/zh/sdk/harmonyos', }, { text: '桌面端', link: '/zh/sdk/desktop', }, ], }, { sectionHeaderText: '进阶指南', }, { text: '为 GUI Agent 补充应用知识', link: '/zh/provide-application-knowledge-to-gui-agent', }, { text: '处理报告文件', link: '/zh/consume-report-file', }, { text: '使用 Gherkin 编写 BDD 脚本', link: '/zh/advanced/bdd-style-scripts-with-gherkin', }, { text: '与任意界面集成', link: '/zh/integrate-with-any-interface', }, { text: '缓存 AI 规划与 DOM 定位', link: '/zh/caching', }, // A group, not a section header, so it can start collapsed. Rspress // expands it when the current page is one of its items. { text: '旧版 YAML 自动化', collapsible: true, collapsed: true, items: [ { text: 'YAML 脚本运行器', link: '/zh/yaml-script-runner', }, { text: 'YAML 格式的工作流', link: '/zh/automate-with-scripts-in-yaml', }, { text: '迁移到 Midscene Test', link: '/zh/migrate-to-midscene-test', }, ], }, { sectionHeaderText: '资源', }, { text: '常见问题 FAQ', link: '/zh/faq', }, { text: '更新日志', link: '/zh/changelog', }, { text: 'Awesome Midscene', link: '/zh/awesome-midscene', }, { text: '数据隐私', link: '/zh/data-privacy', }, { sectionHeaderText: 'Benchmark', }, { text: 'AndroidWorld benchmark', link: '/zh/android-world-benchmark-report', }, { text: 'MobileWorld benchmark', link: '/zh/mobile-world-benchmark-report', }, { text: 'AppControlBench benchmark', link: '/zh/app-control-bench-report', }, ], }, }, globalStyles: path.join(__dirname, 'styles/index.css'), locales: [ { lang: 'en', label: 'English', title: 'Midscene.js - AI UI Automation and E2E Testing', description: 'Bring AI vision to E2E testing with a newly designed test framework for web, mobile, and desktop apps.', }, { lang: 'zh', label: '简体中文', title: 'Midscene.js - AI UI 自动化与 E2E 测试', description: '将 AI 视觉引入 E2E 测试,配套全新设计的测试框架,支持 Web、移动端和桌面应用。', }, ], builderConfig: { performance: { buildCache: false, }, source: { preEntry: ['./theme/tailwind.css'], define: { __MIDSCENE_GITHUB_STARS__: JSON.stringify(githubStars), }, }, html: { tags: [ { tag: 'script', attrs: { type: 'text/javascript', }, children: `(function(c,l,a,r,i,t,y){ c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); })(window, document, "clarity", "script", "rg8ztmkti8");`, }, ], meta: { 'google-site-verification': 'knm1l2oVU9IkHaYjq9q-FnyiEMVkt1b6i2El54Hphdw', }, }, }, lang: 'en', plugins: [ pluginGetStartedPages(), pluginMarkdownOutput(), pluginClientRedirects({ redirects: [ { from: '^/zh$', to: '/zh/' }, ...['', '/zh'].flatMap((locale) => [ { from: `^${locale}/sdk(?:/index(?:\\.html)?|\\.html)?/?$`, to: `${locale}/basics#choose-your-path`, }, { from: `^${locale}/(?:introduction(?:\\.html)?/?|index\\.html)$`, to: `${locale}/`, }, { from: `^${locale}/reference\\.html/?$`, to: `${locale}/reference/`, }, ...[ ['reporting', 'consume-report-file'], ['model-strategy', 'model-selection'], ['model-common-config', 'model-api-setup'], [ 'model-debugging-observability', 'model-config#verify-model-connectivity', ], ['cli', 'yaml-script-runner'], ['quick-start', 'get-started?scene=playground&platform=web'], [ 'blog-programming-practice-using-structured-api', 'basics#javascript-orchestration', ], ].map(([previous, current]) => ({ from: `^${locale}/${previous}(?:\\.html)?/?$`, to: `${locale}/${current}`, })), ]), ...['', '/zh'].flatMap((locale) => [ ['test-runner-overview', 'overview'], ['extend-test-runner', 'extend'], ['use-test-runner', 'use'], ].map(([previous, current]) => ({ from: `^${locale}/${previous}(?:\\.html)?/?$`, to: `${locale}/midscene-test/${current}`, })), ), { from: '^/android-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/platforms/android', }, { from: '^/android-integration(?:\\.html)?/?$', to: '/sdk/android', }, { from: '^/ios-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/platforms/ios', }, { from: '^/harmony-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/platforms/harmonyos', }, { from: '^/computer-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/platforms/desktop', }, { from: '^/(?:android-api-reference|reference/android)(?:\\.html)?/?$', to: '/sdk/android', }, { from: '^/(?:ios-api-reference|reference/ios)(?:\\.html)?/?$', to: '/sdk/ios', }, { from: '^/(?:harmony-api-reference|reference/harmonyos)(?:\\.html)?/?$', to: '/sdk/harmonyos', }, { from: '^/(?:computer-api-reference|reference/desktop)(?:\\.html)?/?$', to: '/sdk/desktop', }, { from: '^/(?:web-api-reference|reference/web)(?:\\.html)?/?$', to: '/sdk/playwright', }, { from: '^/(?:api|reference/common)(?:\\.html)?/?$', to: '/reference/#common', }, { from: '^/zh/android-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/zh/platforms/android', }, { from: '^/zh/ios-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/zh/platforms/ios', }, { from: '^/zh/harmony-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/zh/platforms/harmonyos', }, { from: '^/zh/computer-(?:introduction|getting-started)(?:\\.html)?/?$', to: '/zh/platforms/desktop', }, { from: '^/zh/(?:android-api-reference|reference/android)(?:\\.html)?/?$', to: '/zh/sdk/android', }, { from: '^/zh/(?:ios-api-reference|reference/ios)(?:\\.html)?/?$', to: '/zh/sdk/ios', }, { from: '^/zh/(?:harmony-api-reference|reference/harmonyos)(?:\\.html)?/?$', to: '/zh/sdk/harmonyos', }, { from: '^/zh/(?:computer-api-reference|reference/desktop)(?:\\.html)?/?$', to: '/zh/sdk/desktop', }, { from: '^/zh/(?:web-api-reference|reference/web)(?:\\.html)?/?$', to: '/zh/sdk/playwright', }, { from: '^/zh/(?:api|reference/common)(?:\\.html)?/?$', to: '/zh/reference/#common', }, { from: '^/integrate-with-android(?:\\.html)?/?$', to: '/sdk/android', }, { from: '^/integrate-with-ios(?:\\.html)?/?$', to: '/sdk/ios', }, { from: '^/integrate-with-harmony(?:\\.html)?/?$', to: '/sdk/harmonyos', }, { from: '^/android-playground(?:\\.html)?/?$', to: '/platforms/android', }, { from: '^/ios-playground(?:\\.html)?/?$', to: '/platforms/ios', }, { from: '^/choose-a-model(?:\\.html)?/?$', to: '/model-selection', }, { from: '^/api-reference(?:\\.html)?/?$', to: '/reference/', }, { from: '^/report(?:\\.html)?/?$', to: '/consume-report-file', }, { from: '^/benchmark(?:\\.html)?/?$', to: '/', }, { from: '^/integrate-with-yaml(?:\\.html)?/?$', to: '/automate-with-scripts-in-yaml', }, { from: '^/model-provider(?:\\.html)?/?$', to: '/model-api-setup', }, { from: '^/blog-use-javascript-to-optimize-ai-automation-code(?:\\.html)?/?$', to: '/basics#javascript-orchestration', }, { from: '^/use-javascript-to-optimize-ai-automation-code(?:\\.html)?/?$', to: '/basics#javascript-orchestration', }, { from: '^/bridge-mode-by-chrome-extension(?:\\.html)?/?$', to: '/bridge-mode', }, { from: '^/web-mcp(?:\\.html)?/?$', to: '/skills', }, { from: '^/mcp-android(?:\\.html)?/?$', to: '/skills', }, { from: '^/blog-support-android-automation(?:\\.html)?/?$', to: '/platforms/android', }, { from: '^/blog-support-ios-automation(?:\\.html)?/?$', to: '/platforms/ios', }, { from: '^/quick-experience(?:\\.html)?/?$', to: '/get-started?scene=playground&platform=web', }, { from: '^/quick-experience-with-android(?:\\.html)?/?$', to: '/platforms/android', }, { from: '^/quick-experience-with-ios(?:\\.html)?/?$', to: '/platforms/ios', }, { from: '^/zh/web-mcp(?:\\.html)?/?$', to: '/zh/skills', }, { from: '^/zh/mcp-android(?:\\.html)?/?$', to: '/zh/skills', }, { from: '^/zh/integrate-with-android(?:\\.html)?/?$', to: '/zh/sdk/android', }, { from: '^/zh/integrate-with-ios(?:\\.html)?/?$', to: '/zh/sdk/ios', }, { from: '^/zh/integrate-with-harmony(?:\\.html)?/?$', to: '/zh/sdk/harmonyos', }, { from: '^/zh/blog-support-android-automation(?:\\.html)?/?$', to: '/zh/platforms/android', }, { from: '^/zh/blog-support-ios-automation(?:\\.html)?/?$', to: '/zh/platforms/ios', }, { from: '^/zh/quick-experience(?:\\.html)?/?$', to: '/zh/get-started?scene=playground&platform=web', }, { from: '^/zh/batch-yaml(?:\\.html)?/?$', to: '/zh/yaml-script-runner', }, { from: '^/zh/quick-experience-with-android(?:\\.html)?/?$', to: '/zh/platforms/android', }, { from: '^/zh/quick-experience-with-ios(?:\\.html)?/?$', to: '/zh/platforms/ios', }, { from: '^/zh/choose-a-model(?:\\.html)?/?$', to: '/zh/model-selection', }, { from: '^/zh/model-provider(?:\\.html)?/?$', to: '/zh/model-api-setup', }, { from: '^/zh/blog-use-javascript-to-optimize-ai-automation-code(?:\\.html)?/?$', to: '/zh/basics#javascript-orchestration', }, { from: '^/zh/use-javascript-to-optimize-ai-automation-code(?:\\.html)?/?$', to: '/zh/basics#javascript-orchestration', }, { from: '^/zh/bridge-mode-by-chrome-extension(?:\\.html)?/?$', to: '/zh/bridge-mode', }, { from: '^/zh/android-playground(?:\\.html)?/?$', to: '/zh/platforms/android', }, { from: '^/zh/ios-playground(?:\\.html)?/?$', to: '/zh/platforms/ios', }, { from: '^/command-line-tools(?:\\.html)?/?$', to: '/yaml-script-runner', }, { from: '^/zh/command-line-tools(?:\\.html)?/?$', to: '/zh/yaml-script-runner', }, ], }), ], }; });