import { defineConfig, type HeadConfig } from "vitepress"; import llmstxt from "vitepress-plugin-llms"; import { teekConfig } from "./teekConfig"; import { createRewrites } from "vitepress-theme-teek/config"; // 动态判断环境 // Cloudflare Pages 默认提供 CF_PAGES 环境变量 // GitHub Actions 默认提供 GITHUB_ACTIONS 环境变量 // 本地开发:两者都为 false,不触发跳转 const isCF = process.env.CF_PAGES === '1' || process.env.PLATFORM === 'cloudflare' const isGitHub = process.env.GITHUB_ACTIONS === 'true' const PIXIVSOURCE = isCF ? 'https://pixivsource.pages.dev' : 'https://downeyrem.github.io/PixivSource' // 规范网址始终指向 CF Pages(主站) const CANONICAL_BASE = 'https://downeyrem.pages.dev' // VitePress 配置 // https://vitepress.dev/reference/site-config export default defineConfig({ extends: teekConfig, title: "DowneyRem's Blog", description: "唐尼瑞姆的博客", lang: "zh-CN", cleanUrls: true, // 简洁URL ignoreDeadLinks: true, // 忽略死链 appearance: true, // 默认主题由用户配色方案决定 lastUpdated: true, // 获取页面最后更新的时间戳 head: [ ['link', { rel: 'icon', type: 'image/png', href: "/favicon.png" }], ["meta", { name: "google-site-verification", content: "Mce6VS2aBjfn1zAt9rSsrEKeNj2ZO9lNqYLroPbBY6s" }], ["meta", { property: "og:type", content: "website" }], ["meta", { property: "og:locale", content: "zh-CN" }], ["meta", { property: "og:image", content: "/favicon.png" }], ["link", { rel: "preconnect", href: "https://www.googletagmanager.com" }], ["link", { rel: "preconnect", href: "https://www.google-analytics.com", crossorigin: "" }], ["script", { async: "", src: "https://www.googletagmanager.com/gtag/js?id=G-X0J76E1E8Y" }], ["script", {}, `window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag("js", new Date()); gtag("config", "G-X0J76E1E8Y");` ], ["noscript", {}, ''], ], // 每页动态注入 canonical,GitHub Pages 构建时额外注入跳转 transformHead({ pageData }) { const path = pageData.relativePath .replace(/index\.md$/, '') .replace(/\.md$/, '') const canonicalUrl = `${CANONICAL_BASE}/${path}` const heads: HeadConfig[] = [ ['link', { rel: 'canonical', href: canonicalUrl }] ] // 只有 GitHub Pages 构建时才注入跳转,本地开发不跳转 if (isGitHub && !isCF) { heads.push( ['meta', { 'http-equiv': 'refresh', content: `0; url=${canonicalUrl}` }], ['script', {}, `window.location.replace("${canonicalUrl}")`] ) } return heads }, markdown: { lineNumbers: true, image: { lazyLoading: true, }, container: { tipLabel: "提示", warningLabel: "警告", dangerLabel: "危险", infoLabel: "信息", detailsLabel: "详细信息", }, }, sitemap: { hostname: isCF ? 'https://downeyrem.pages.dev' : 'https://downeyrem.github.io', transformItems: (items) => { const permalinkItemBak: typeof items = []; // 使用永久链接生成 sitemap const permalinks = (globalThis as any).VITEPRESS_CONFIG.site.themeConfig .permalinks; items.forEach((item) => { const permalink = permalinks?.map[item.url]; if (permalink) permalinkItemBak.push({ url: permalink, lastmod: item.lastmod }); }); return [...items, ...permalinkItemBak]; }, }, // https://vitepress.dev/reference/default-theme-config themeConfig: { logo: "/favicon.png", siteTitle: "DowneyRem", lightModeSwitchTitle: "浅色模式", darkModeSwitchLabel: '深色模式', sidebarMenuLabel: "菜单", returnToTopLabel: "返回顶部", lastUpdated: { text: '上次更新'}, outline: { level: [2, 4], label: '本页目录' }, editLink: { pattern: "https://github.com/DowneyRem/downeyrem.github.io/blob/main/docs/:path", text: "在 GitHub 上编辑本文" }, docFooter: { prev: '上一页', next: '下一页' }, nav: [ { text: "🏠 首页", link: "/" }, { text: "💎 龙的宝藏", items: [ { text: "🅿️ Pixiv 书源", link: PIXIVSOURCE }, { text: "🐺 兽人阅读", link: "/FurryReading" }, { text: "📖 龙的小说", link: "/Novel" }, { text: "✅ 龙的教程", link: "/Guild" }, ], }, { text: "📜 龙的话语", items: [ { text: "📅 龙的日常", link: "/Daily" }, { text: "㊙️ 龙的秘密", link: "/Encrypt" }, { text: "📚 龙在读书", link: "/Books" }, { text: "🐺 龙和兽人", link: "/Furry" }, ], }, { text: "🐾 龙的足迹", items: [ { text: "📚 文章归档", link: "/archives" }, { text: "📃 文章清单", link: "/articleOverview" }, { text: "📂 文章分类", link: "/categories" }, { text: "#️⃣ 文章标签", link: "/tags" }, // { text: "🔐 登录页面", link: "/login" }, ], }, { text: "🐲 关于本龙", items: [ { text: "🐲 龙的档案", link: "/About" }, { text: "🤝 龙的盟友", link: "/FriendLink" }, { text: "🍖 投喂本龙", link: "/Sponsor" }, ], }, ], socialLinks: [ // { icon: "telegram", link: "https://t.me/DowneyRem" }, { icon: "github", link: "https://github.com/DowneyRem" }, { icon: "pixiv", link: "https://www.pixiv.net/users/119908520" }, // { icon: "twitter", link: "https://x.com/DowneyRemDragon" }, ], search: { provider: "local", options: { translations: { button: { buttonText: "搜索文档", buttonAriaLabel: "搜索文档" }, modal: { noResultsText: "无法找到相关结果", resetButtonTitle: "清除查询条件", footer: { selectText: "选择", navigateText: "切换", closeText: "Esc 键", } } } } }, vite: { build: { assetsInlineLimit: 2048, }, plugins: [llmstxt() as any], }, }, })