-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
112 changed files
with
23,372 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
dist | ||
.vitepress/dist | ||
.cache | ||
auto-imports.d.ts | ||
components.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: ["airbnb-base", "plugin:vue/vue3-essential"], | ||
overrides: [ | ||
{ | ||
env: { | ||
node: true, | ||
}, | ||
files: [".eslintrc.{js,cjs}"], | ||
parserOptions: { | ||
sourceType: "script", | ||
}, | ||
}, | ||
], | ||
parserOptions: { | ||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
}, | ||
plugins: ["vue"], | ||
rules: { | ||
// 使用双引号 | ||
quotes: ["warn", "double"], | ||
// 导入后缀名 | ||
"import/extensions": "off", | ||
// 禁用 console | ||
"no-console": "off", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules/ | ||
.DS_Store | ||
dist | ||
dist-ssr | ||
coverage | ||
*.local | ||
test.html | ||
.env | ||
.vitepress/dist | ||
.vitepress/cache | ||
.vitepress/components.d.ts | ||
.vitepress/auto-imports.d.ts | ||
themeConfig.mjs | ||
!.vitepress/theme/assets/themeConfig.mjs | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
.vscode | ||
!.vscode/extensions.json | ||
.idea | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
registry=https://registry.npmmirror.com | ||
disturl=https://registry.npmmirror.com/-/binary/node | ||
shamefully-hoist=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
dist | ||
node_modules | ||
pnpm-lock.yaml | ||
LICENSE.md | ||
tsconfig.json | ||
tsconfig.*.json | ||
auto-imports.d.ts | ||
components.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/prettierrc", | ||
"singleQuote": false, | ||
"trailingComma": "all", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"printWidth": 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
import { defineConfig } from "vitepress"; | ||
import { createRssFile } from "./theme/utils/generateRSS.mjs"; | ||
import { withPwa } from "@vite-pwa/vitepress"; | ||
import { | ||
getAllPosts, | ||
getAllType, | ||
getAllCategories, | ||
getAllArchives, | ||
} from "./theme/utils/getPostData.mjs"; | ||
import { jumpRedirect } from "./theme/utils/commonTools.mjs"; | ||
import { getThemeConfig } from "./init.mjs"; | ||
import markdownConfig from "./theme/utils/markdownConfig.mjs"; | ||
import AutoImport from "unplugin-auto-import/vite"; | ||
import Components from "unplugin-vue-components/vite"; | ||
import path from "path"; | ||
|
||
// 获取全局数据 | ||
const postData = await getAllPosts(); | ||
|
||
// 获取主题配置 | ||
const themeConfig = await getThemeConfig(); | ||
|
||
// https://vitepress.dev/reference/site-config | ||
export default withPwa( | ||
defineConfig({ | ||
title: themeConfig.siteMeta.title, | ||
description: themeConfig.siteMeta.description, | ||
lang: themeConfig.siteMeta.lang, | ||
// 简洁的 URL | ||
cleanUrls: true, | ||
// 最后更新时间戳 | ||
lastUpdated: true, | ||
// 主题 | ||
appearance: "dark", | ||
// Head | ||
head: themeConfig.inject.header, | ||
// sitemap | ||
sitemap: { | ||
hostname: themeConfig.siteMeta.site, | ||
}, | ||
// 主题配置 | ||
themeConfig: { | ||
...themeConfig, | ||
// 必要数据 | ||
postData: postData, | ||
tagsData: getAllType(postData), | ||
categoriesData: getAllCategories(postData), | ||
archivesData: getAllArchives(postData), | ||
}, | ||
// markdown | ||
markdown: { | ||
math: true, | ||
lineNumbers: true, | ||
toc: { level: [1, 2, 3] }, | ||
image: { | ||
lazyLoading: true, | ||
}, | ||
config: (md) => markdownConfig(md, themeConfig), | ||
}, | ||
// 构建排除 | ||
srcExclude: ["**/README.md", "**/TODO.md"], | ||
// transformHead | ||
transformPageData: async (pageData) => { | ||
// canonical URL | ||
const canonicalUrl = `${themeConfig.siteMeta.site}/${pageData.relativePath}` | ||
.replace(/index\.md$/, "") | ||
.replace(/\.md$/, ""); | ||
pageData.frontmatter.head ??= []; | ||
pageData.frontmatter.head.push(["link", { rel: "canonical", href: canonicalUrl }]); | ||
}, | ||
// transformHtml | ||
transformHtml: (html) => { | ||
return jumpRedirect(html, themeConfig); | ||
}, | ||
// buildEnd | ||
buildEnd: async (config) => { | ||
await createRssFile(config, themeConfig); | ||
}, | ||
// vite | ||
vite: { | ||
plugins: [ | ||
AutoImport({ | ||
imports: ["vue", "vitepress"], | ||
dts: ".vitepress/auto-imports.d.ts", | ||
}), | ||
Components({ | ||
dirs: [".vitepress/theme/components", ".vitepress/theme/views"], | ||
extensions: ["vue", "md"], | ||
include: [/\.vue$/, /\.vue\?vue/, /\.md$/], | ||
dts: ".vitepress/components.d.ts", | ||
}), | ||
], | ||
resolve: { | ||
// 配置路径别名 | ||
alias: { | ||
// eslint-disable-next-line no-undef | ||
"@": path.resolve(__dirname, "./theme"), | ||
}, | ||
}, | ||
css: { | ||
preprocessorOptions: { | ||
scss: { | ||
silenceDeprecations: ["legacy-js-api"], | ||
}, | ||
}, | ||
}, | ||
// 服务器 | ||
server: { | ||
port: 9877, | ||
}, | ||
// 构建 | ||
build: { | ||
minify: "terser", | ||
terserOptions: { | ||
compress: { | ||
pure_funcs: ["console.log"], | ||
}, | ||
}, | ||
}, | ||
}, | ||
// PWA | ||
pwa: { | ||
registerType: "autoUpdate", | ||
selfDestroying: true, | ||
workbox: { | ||
clientsClaim: true, | ||
skipWaiting: true, | ||
cleanupOutdatedCaches: true, | ||
// 资源缓存 | ||
runtimeCaching: [ | ||
{ | ||
urlPattern: /(.*?)\.(woff2|woff|ttf|css)/, | ||
handler: "CacheFirst", | ||
options: { | ||
cacheName: "file-cache", | ||
}, | ||
}, | ||
{ | ||
urlPattern: /(.*?)\.(ico|webp|png|jpe?g|svg|gif|bmp|psd|tiff|tga|eps)/, | ||
handler: "CacheFirst", | ||
options: { | ||
cacheName: "image-cache", | ||
}, | ||
}, | ||
{ | ||
urlPattern: /^https:\/\/cdn2\.codesign\.qq\.com\/.*/i, | ||
handler: "CacheFirst", | ||
options: { | ||
cacheName: "iconfont-cache", | ||
expiration: { | ||
maxEntries: 10, | ||
maxAgeSeconds: 60 * 60 * 24 * 2, | ||
}, | ||
cacheableResponse: { | ||
statuses: [0, 200], | ||
}, | ||
}, | ||
}, | ||
], | ||
// 缓存文件 | ||
globPatterns: ["**/*.{js,css,html,ico,png,jpg,jpeg,gif,svg,woff2,ttf}"], | ||
// 排除路径 | ||
navigateFallbackDenylist: [/^\/sitemap.xml$/, /^\/rss.xml$/, /^\/robots.txt$/], | ||
}, | ||
manifest: { | ||
name: themeConfig.siteMeta.title, | ||
short_name: themeConfig.siteMeta.title, | ||
description: themeConfig.siteMeta.description, | ||
display: "standalone", | ||
start_url: "/", | ||
theme_color: "#fff", | ||
background_color: "#efefef", | ||
icons: [ | ||
{ | ||
src: "/images/logo/favicon-32x32.webp", | ||
sizes: "32x32", | ||
type: "image/webp", | ||
}, | ||
{ | ||
src: "/images/logo/favicon-96x96.webp", | ||
sizes: "96x96", | ||
type: "image/webp", | ||
}, | ||
{ | ||
src: "/images/logo/favicon-256x256.webp", | ||
sizes: "256x256", | ||
type: "image/webp", | ||
}, | ||
{ | ||
src: "/images/logo/favicon-512x512.webp", | ||
sizes: "512x512", | ||
type: "image/webp", | ||
}, | ||
], | ||
}, | ||
}, | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { themeConfig } from "./theme/assets/themeConfig.mjs"; | ||
import { existsSync } from "fs"; | ||
import path from "path"; | ||
|
||
/** | ||
* 获取并合并配置文件 | ||
*/ | ||
export const getThemeConfig = async () => { | ||
try { | ||
// 配置文件绝对路径 | ||
const configPath = path.resolve(__dirname, "../themeConfig.mjs"); | ||
if (existsSync(configPath)) { | ||
// 文件存在时进行动态导入 | ||
const userConfig = await import("../themeConfig.mjs"); | ||
return Object.assign(themeConfig, userConfig?.themeConfig || {}); | ||
} else { | ||
// 文件不存在时返回默认配置 | ||
console.warn("User configuration file not found, using default themeConfig."); | ||
return themeConfig; | ||
} | ||
} catch (error) { | ||
console.error("An error occurred while loading the configuration:", error); | ||
return themeConfig; | ||
} | ||
}; |
Oops, something went wrong.