77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import { defineConfig } from 'vite'
|
|
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
import vue from '@vitejs/plugin-vue'
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
|
|
const publicRoutes = [
|
|
'/',
|
|
'/encyclopedia',
|
|
'/encyclopedia/1',
|
|
'/encyclopedia/2',
|
|
'/encyclopedia/3',
|
|
'/encyclopedia/4',
|
|
'/encyclopedia/5',
|
|
'/encyclopedia/6',
|
|
'/encyclopedia/7',
|
|
'/encyclopedia/8',
|
|
'/encyclopedia/9',
|
|
'/encyclopedia/10',
|
|
'/gallery',
|
|
'/community',
|
|
]
|
|
|
|
function getSiteUrl() {
|
|
const explicitUrl = process.env.VITE_SITE_URL
|
|
const vercelUrl = process.env.VERCEL_PROJECT_PRODUCTION_URL
|
|
const siteUrl = explicitUrl || (vercelUrl ? `https://${vercelUrl}` : 'https://cloud.catpl.dev')
|
|
return siteUrl.replace(/\/$/, '')
|
|
}
|
|
|
|
function seoFilesPlugin() {
|
|
return {
|
|
name: 'opencloud-seo-files',
|
|
closeBundle() {
|
|
const siteUrl = getSiteUrl()
|
|
mkdirSync('dist/.well-known', { recursive: true })
|
|
|
|
const robots = [
|
|
'User-agent: *',
|
|
'Allow: /',
|
|
'Disallow: /admin',
|
|
'Disallow: /auth/',
|
|
'Disallow: /login',
|
|
'Disallow: /register',
|
|
'Disallow: /upload',
|
|
'Disallow: /profile/settings',
|
|
`Sitemap: ${siteUrl}/sitemap.xml`,
|
|
'',
|
|
].join('\n')
|
|
|
|
const sitemapUrls = publicRoutes
|
|
.map(route => ` <url>\n <loc>${siteUrl}${route}</loc>\n </url>`)
|
|
.join('\n')
|
|
|
|
const sitemap = [
|
|
'<?xml version="1.0" encoding="UTF-8"?>',
|
|
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
|
|
sitemapUrls,
|
|
'</urlset>',
|
|
'',
|
|
].join('\n')
|
|
|
|
writeFileSync('dist/robots.txt', robots)
|
|
writeFileSync('dist/sitemap.xml', sitemap)
|
|
},
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [vue(), tailwindcss(), seoFilesPlugin()],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
})
|