|
- import { fileURLToPath } from 'node:url'
-
- // https://nuxt.com/docs/api/configuration/nuxt-config
- export default defineNuxtConfig({
- compatibilityDate: '2025-07-15',
- devtools: { enabled: true },
-
- devServer: { port: 6888, host: '0.0.0.0' },
-
- modules: ['@nuxt/ui'],
-
- css: ['~/assets/css/main.css'],
-
- /**
- * 暗色模式:@nuxtjs/color-mode 由 @nuxt/ui 自带(classSuffix 已被置空,即 <html class="dark">)。
- * 默认保持亮色,不跟随系统;用户在页头手动切换后写入 cookie 持久化。
- */
- colorMode: {
- preference: 'light',
- fallback: 'light',
- classSuffix: '',
- storage: 'cookie',
- storageKey: 'ai-color-mode',
- },
-
- // 禁用 @nuxt/fonts 远程字体提供商(内网环境无法访问 Google Fonts)
- ui: {
- fonts: false,
- },
-
- // 运行时公开配置(客户端可访问)
- runtimeConfig: {
- public: {
- // ThinkJS ai_api 地址,按环境覆盖
- apiBase: process.env.API_BASE || 'http://192.168.31.168:16888',
- // 邀请链接正式域名;未配置时自动使用当前访问域名。
- siteUrl: process.env.NUXT_PUBLIC_SITE_URL || '',
- },
- },
-
- // SSR / SEO
- ssr: true,
-
- /**
- * 兼容原 PC 站的自定义路由(SEO 不断链)
- * 原站分页形式:/info2、/info/new2、/info/course2、/info/what2。
- * 已迁移工具继续以旧站已收录路径作为主入口。
- */
- hooks: {
- 'pages:extend'(pages) {
- /*
- Windows 下长时间运行的 dev 进程偶尔会漏掉新增页面文件的 add 事件,
- 表现为:SSR 已命中页面并吐出内容,客户端水合后 vue-router 匹配不到而进入 404。
- 这里对所有新增页面显式兜底;已被自动扫描到的路径会跳过,不会重复注册。
- 新增 app/pages 下的页面时,记得同步加到这个清单里。
- */
- const fallbackPages = [
- { name: 'invite', path: '/invite', file: './app/pages/invite/index.vue' },
- { name: 'invite-landing', path: '/invite/landing', file: './app/pages/invite/landing.vue' },
- { name: 'invite-records', path: '/invite/records', file: './app/pages/invite/records.vue' },
- { name: 'terms', path: '/terms', file: './app/pages/terms.vue' },
- { name: 'privacy', path: '/privacy', file: './app/pages/privacy.vue' },
- { name: 'earn-points', path: '/earn-points', file: './app/pages/earn-points.vue' },
- { name: 'portrait-photo', path: '/portrait-photo', file: './app/pages/portrait-photo.vue' },
- { name: 'old-photo', path: '/old-photo', file: './app/pages/old-photo.vue' },
- { name: 'id-photo', path: '/id-photo', file: './app/pages/id-photo.vue' },
- { name: 'recharge', path: '/recharge', file: './app/pages/recharge.vue' },
- { name: 'bill', path: '/bill', file: './app/pages/bill.vue' },
- { name: 'works', path: '/works', file: './app/pages/works.vue' },
- ]
- for (const page of fallbackPages) {
- if (pages.some(item => item.path === page.path)) continue
- pages.push({
- ...page,
- file: fileURLToPath(new URL(page.file, import.meta.url)),
- })
- }
-
- // 复用已有页面组件,追加原站的分页路径(/info2 = 第 2 页)
- const legacy = [
- { base: '/info', name: 'legacy-info-page' },
- { base: '/info/new', name: 'legacy-info-new-page' },
- { base: '/info/course', name: 'legacy-info-course-page' },
- { base: '/info/what', name: 'legacy-info-what-page' },
- ]
- for (const item of legacy) {
- const origin = pages.find(p => p.path === item.base)
- if (!origin) continue
- pages.push({
- name: item.name,
- path: `${item.base}:page(\\d+)`,
- file: origin.file,
- children: [],
- })
- pages.push({
- name: `${item.name}-html`,
- path: `${item.base}:page(\\d+).html`,
- file: origin.file,
- children: [],
- })
- }
- },
- },
-
- // 旧 ThinkJS 自动 controller 地址及重构早期地址统一 301 到已收录主路径。
- routeRules: {
- '/ai-name': { redirect: { to: '/writing/naming/', statusCode: 301 } },
- '/anime-avatar': { redirect: { to: '/draw/anime/', statusCode: 301 } },
- '/writing/naming.html': { redirect: { to: '/writing/naming/', statusCode: 301 } },
- '/draw/anime.html': { redirect: { to: '/draw/anime/', statusCode: 301 } },
- '/index.html': { redirect: { to: '/', statusCode: 301 } },
- '/anime/index.html': { redirect: { to: '/draw/anime/', statusCode: 301 } },
- '/pic/index.html': { redirect: { to: '/pic/', statusCode: 301 } },
- '/news/index.html': { redirect: { to: '/info', statusCode: 301 } },
- '/news/list.html': { redirect: { to: '/info/new', statusCode: 301 } },
- '/news/course.html': { redirect: { to: '/info/course', statusCode: 301 } },
- '/news/ask.html': { redirect: { to: '/info/what', statusCode: 301 } },
- '/my/invite.html': { redirect: { to: '/invite', statusCode: 301 } },
- },
-
- app: {
- head: {
- titleTemplate: '%s',
- title: 'AI在线网站-你的AI伙伴让创作更简单',
- meta: [
- { charset: 'utf-8' },
- { name: 'viewport', content: 'width=device-width, initial-scale=1' },
- { name: 'description', content: 'AI在线是一个 AI 工具的集合地,可以找到各种各样的 AI 工具,满足你的不同需求。无论你是想翻译一段文字,还是想生成一篇文章,或者是想制作一张图片,AI在线都能为你提供帮助, AI 工具大全宝库!' },
- { name: 'keywords', content: 'AI,AI在线,AI伙伴,免费AI网站' },
- ],
- link: [{ rel: 'icon', type: 'image/png', href: '/logo.png' }],
- },
- },
- })
|