Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion web2/ur.xyz/astro/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PROJECT_ROOT = path.resolve(__dirname, '..');
const REACT_SRC = path.resolve(PROJECT_ROOT, 'react/src');
const DOCS_DIR = path.join(PROJECT_ROOT, 'docs');
const RESPONSIVE_PREVIEW = path.join(__dirname, 'dev', 'responsive-preview.html');

/** Walk a directory and return absolute paths of every file matching `ext`. */
function walk(dir, ext) {
Expand Down Expand Up @@ -51,6 +52,33 @@ function urXyzContent() {
};
}

/** Development-only routes for the Build clean URL and responsive preview tool. */
function urXyzDevRoutes() {
return {
name: 'ur-xyz-dev-routes',
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (!req.url) return next();
const queryIndex = req.url.indexOf('?');
const pathname = queryIndex === -1 ? req.url : req.url.slice(0, queryIndex);
const query = queryIndex === -1 ? '' : req.url.slice(queryIndex);
if (pathname === '/responsive-preview' || pathname === '/responsive-preview/') {
if (!fs.existsSync(RESPONSIVE_PREVIEW)) return next();
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.setHeader('Cache-Control', 'no-store');
res.end(fs.readFileSync(RESPONSIVE_PREVIEW, 'utf8'));
return;
}
if (pathname === '/build' || pathname === '/build/') {
req.url = `/build.html${query}`;
}
return next();
});
},
};
}

// ── real <lastmod> values (the sitemap carried none at all) ──
import { execFileSync } from 'node:child_process';
import { slugFor, HIDDEN_DOC_SLUGS } from '../react/src/lib/docs-shared.js';
Expand Down Expand Up @@ -189,7 +217,7 @@ export default defineConfig({
build: { format: 'file' },
outDir: path.resolve(__dirname, 'build', ENV),
vite: {
plugins: [urXyzContent()],
plugins: [urXyzContent(), urXyzDevRoutes()],
resolve: {
alias: {
'@react': REACT_SRC
Expand Down
Loading
Loading