feat(website): implement SPA route handling and remove 404.html
This commit is contained in:
@@ -46,15 +46,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script>
|
||||
// Restore SPA path from 404.html redirect (GitHub Pages)
|
||||
;(function () {
|
||||
var p = new URLSearchParams(window.location.search).get('p')
|
||||
if (p) {
|
||||
window.history.replaceState(null, '', window.location.pathname + p + window.location.hash)
|
||||
}
|
||||
})()
|
||||
</script>
|
||||
<script type="module" src="./src/main.tsx"></script>
|
||||
<script>
|
||||
// Dynamically update html lang attribute based on i18n detection
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Redirecting...</title>
|
||||
<script>
|
||||
// SPA fallback for GitHub Pages
|
||||
// Preserves the path so the SPA router can handle it after redirect
|
||||
var seg = 1 // number of path segments to keep (repo name = /page-agent)
|
||||
var loc = window.location
|
||||
loc.replace(
|
||||
loc.protocol +
|
||||
'//' +
|
||||
loc.hostname +
|
||||
(loc.port ? ':' + loc.port : '') +
|
||||
loc.pathname
|
||||
.split('/')
|
||||
.slice(0, 1 + seg)
|
||||
.join('/') +
|
||||
'/?p=' +
|
||||
encodeURIComponent(
|
||||
loc.pathname
|
||||
.slice(1)
|
||||
.split('/')
|
||||
.slice(seg)
|
||||
.join('/') +
|
||||
loc.search +
|
||||
loc.hash
|
||||
)
|
||||
)
|
||||
</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
@@ -1,9 +1,9 @@
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
import react from '@vitejs/plugin-react-swc'
|
||||
import { config as dotenvConfig } from 'dotenv'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { copyFileSync, mkdirSync, readFileSync } from 'node:fs'
|
||||
import process from 'node:process'
|
||||
import { dirname, resolve } from 'path'
|
||||
import { dirname, join, resolve } from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import { defineConfig } from 'vite'
|
||||
|
||||
@@ -15,11 +15,47 @@ const pageAgentPkg = JSON.parse(
|
||||
// Load .env from repo root
|
||||
dotenvConfig({ path: resolve(__dirname, '../../.env') })
|
||||
|
||||
// All SPA routes that need index.html copies for direct access on static hosts
|
||||
const SPA_ROUTES = [
|
||||
'docs',
|
||||
'docs/introduction/overview',
|
||||
'docs/introduction/quick-start',
|
||||
'docs/introduction/limitations',
|
||||
'docs/introduction/troubleshooting',
|
||||
'docs/features/custom-tools',
|
||||
'docs/features/data-masking',
|
||||
'docs/features/custom-instructions',
|
||||
'docs/features/models',
|
||||
'docs/features/chrome-extension',
|
||||
'docs/advanced/page-agent',
|
||||
'docs/advanced/page-agent-core',
|
||||
'docs/advanced/custom-ui',
|
||||
'docs/integration/security-permissions',
|
||||
'docs/integration/best-practices',
|
||||
'docs/integration/third-party-agent',
|
||||
]
|
||||
|
||||
function spaRoutes() {
|
||||
return {
|
||||
name: 'spa-routes',
|
||||
closeBundle() {
|
||||
const dist = resolve(__dirname, 'dist')
|
||||
const src = join(dist, 'index.html')
|
||||
for (const route of SPA_ROUTES) {
|
||||
const dir = join(dist, route)
|
||||
mkdirSync(dir, { recursive: true })
|
||||
copyFileSync(src, join(dir, 'index.html'))
|
||||
}
|
||||
console.log(` ✓ Copied index.html to ${SPA_ROUTES.length} SPA routes`)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Website Config (React Documentation Site)
|
||||
export default defineConfig(({ mode }) => ({
|
||||
base: '/page-agent/',
|
||||
clearScreen: false,
|
||||
plugins: [react(), tailwindcss()],
|
||||
plugins: [react(), tailwindcss(), spaRoutes()],
|
||||
build: {
|
||||
chunkSizeWarningLimit: 2000,
|
||||
cssCodeSplit: true,
|
||||
|
||||
Reference in New Issue
Block a user