Files
2026-07-13 12:38:36 +08:00

177 lines
6.5 KiB
JavaScript

// @ts-check
import { defineConfig } from 'astro/config';
import starlight from '@astrojs/starlight';
import netlify from '@astrojs/netlify';
import react from '@astrojs/react';
import markdoc from '@astrojs/markdoc';
import tailwindcss from '@tailwindcss/vite';
import sitemap from '@astrojs/sitemap';
import { sidebar } from './sidebar.mts';
import rehypeTableOptionLinks from './src/plugins/utils/rehype-table-option-links.ts';
import { resolveNxDevUrl } from './src/utils/resolve-nx-dev-url.ts';
// Always resolve NX_DEV_URL so downstream consumers (Footer, Header) pick it up.
// For deploy previews this overrides any site-level env var to point to the matching preview.
process.env.NX_DEV_URL = resolveNxDevUrl();
const BASE = '/docs';
// This is exposed as window.__CONFIG
const PUBLIC_CONFIG = {
gtmMeasurementId: 'GTM-KW8423B6',
isProd: process.env.NODE_ENV === 'production',
};
// https://astro.build/config
export default defineConfig({
base: BASE,
vite: { plugins: [tailwindcss()] },
// Allow this to be configured per environment for robots.txt detection
// Note: this happens during build time so we don't use `import.meta.env`
site: process.env.NX_DEV_URL ?? 'https://nx.dev',
image: {
service: {
entrypoint: 'astro/assets/services/sharp',
config: {
limitInputPixels: false, // Disable pixel limit
},
},
},
markdown: {
rehypePlugins: [rehypeTableOptionLinks],
},
trailingSlash: 'never',
redirects: {
'/knowledge-base/installation':
'/docs/knowledge-base/installation-and-updates',
'/guides/nx-cloud/ci-resource-usage':
'/docs/features/ci-features/resource-usage',
'/reference/remote-cache-plugins':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/s3-cache':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/s3-cache/overview':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/gcs-cache':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/gcs-cache/overview':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/azure-cache':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/azure-cache/overview':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/shared-fs-cache':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/shared-fs-cache/overview':
'/docs/reference/deprecated/self-hosted-cache-packages',
'/reference/remote-cache-plugins/shared-fs-cache/generators':
'/docs/reference/deprecated/self-hosted-cache-packages',
},
// This adapter doesn't support local previews, so only load it on Netlify.
adapter: process.env['NETLIFY'] ? netlify() : undefined,
integrations: [
markdoc(),
// https://starlight.astro.build/reference/configuration/
starlight({
title: 'Nx',
tagline:
'Get to green PRs in half the time. Nx optimizes your builds, scales your CI, and fixes failed PRs. Built for developers and AI agents.',
customCss: ['./src/styles/global.css'],
favicon: '/favicon.svg',
logo: {
light: './src/assets/nx/Nx-dark.png',
dark: './src/assets/nx/Nx-light.png',
replacesTitle: true,
},
disable404Route: true,
lastUpdated: true,
head: [
{
tag: 'script',
content: `window.__CONFIG = ${JSON.stringify(PUBLIC_CONFIG)};`,
},
{
tag: 'script',
attrs: {
src: `${BASE}/global-scripts.js`,
defer: true,
},
},
],
plugins: [],
routeMiddleware: [
// NOTE: this is responsibile for populating the Reference section
// with generated routes from the nx-reference-packages content collection
// since the sidebar doesn't auto generate w/ dynamic routes from src/pages/reference
// only the src/content/docs/reference files
'./src/plugins/sidebar-reference-updater.middleware.ts',
'./src/plugins/og.middleware.ts',
'./src/plugins/github-stars.middleware.ts',
'./src/plugins/raw-content.middleware.ts',
'./src/plugins/canonical.middleware.ts',
'./src/plugins/schema.middleware.ts',
],
markdown: {
headingLinks: true,
},
social: [
{ icon: 'github', label: 'GitHub', href: 'https://github.com/nrwl/nx' },
{
icon: 'youtube',
label: 'YouTube',
href: 'https://www.youtube.com/@NxDevtools?utm_source=nx.dev',
},
{
icon: 'x.com',
label: 'X',
href: 'https://x.com/NxDevTools?utm_source=nx.dev',
},
{
icon: 'discord',
label: 'Discord',
href: 'https://go.nx.dev/community',
},
],
editLink: {
baseUrl: 'https://github.com/nrwl/nx/tree/main/',
},
sidebar,
components: {
Header: './src/components/layout/Header.astro',
Footer: './src/components/layout/Footer.astro',
PageFrame: './src/components/layout/PageFrame.astro',
Sidebar: './src/components/layout/Sidebar.astro',
TwoColumnContent: './src/components/layout/TwoColumnContent.astro',
PageTitle: './src/components/layout/PageTitle.astro',
TableOfContents: './src/components/layout/TableOfContents.astro',
},
pagefind: {
ranking: {
// termFrequency changes the ranking balance between
// frequency of the term relative to document length
// versus weighted term count.
// default is 1.0
termFrequency: 0.65,
// pageLength changes the way ranking compares page lengths with the average page lengths on your site.
// default 0.75
pageLength: 0.3,
// termSaturation controls how quickly a term “saturates” on a page.
// Once a term has appeared on a page many times,
// further appearances have a reduced impact on the page rank.
// default: 1.4
termSaturation: 1.2,
// termSimilarity changes the ranking based on
// similarity of terms to the search query.
// Currently this only takes the length of the term into account.
// default is 1.0
// termSimilarity: 1.0,
},
},
}),
react(),
sitemap({
lastmod: new Date(),
}),
],
});