添加 @unhead/vue 和 vite-plugin-sitemap 依赖,更新路由元信息以包含描述标签,配置 sitemap 插件,添加 robots.txt 文件

This commit is contained in:
2025-03-15 22:17:09 +08:00
parent b496fc142f
commit 2494169c61
7 changed files with 123 additions and 14 deletions

54
package-lock.json generated
View File

@ -10,6 +10,7 @@
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.3.1", "@element-plus/icons-vue": "^2.3.1",
"@fortawesome/fontawesome-free": "^6.7.2", "@fortawesome/fontawesome-free": "^6.7.2",
"@unhead/vue": "^0.7.0",
"element-plus": "^2.9.5", "element-plus": "^2.9.5",
"github-calendar": "^2.3.4", "github-calendar": "^2.3.4",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
@ -22,7 +23,8 @@
"@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue": "^5.2.1",
"path": "^0.12.7", "path": "^0.12.7",
"unplugin-vue-components": "^28.4.1", "unplugin-vue-components": "^28.4.1",
"vite": "^6.2.0" "vite": "^6.2.0",
"vite-plugin-sitemap": "^0.7.1"
} }
}, },
"node_modules/@babel/helper-string-parser": { "node_modules/@babel/helper-string-parser": {
@ -799,6 +801,35 @@
"resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.16.tgz", "resolved": "https://registry.npmjs.org/@types/web-bluetooth/-/web-bluetooth-0.0.16.tgz",
"integrity": "sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ==" "integrity": "sha512-oh8q2Zc32S6gd/j50GowEjKLoOVOwHP/bWVjKJInBwQqdOYMdPrf1oVlelTlyfFK3CKxL1uahMDAr+vy8T7yMQ=="
}, },
"node_modules/@unhead/schema": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@unhead/schema/-/schema-0.7.0.tgz",
"integrity": "sha512-AcfB3vbY7v5GxZOBNHjNiseRjtS40N+lXyuxr0Ee42/BBmPNcKa8SuAlSX4iSht7ptdSaxIjrzzTsQDOrDllYA==",
"license": "MIT",
"dependencies": {
"@zhead/schema": "1.0.1",
"hookable": "^5.4.1"
},
"funding": {
"url": "https://github.com/sponsors/harlan-zw"
}
},
"node_modules/@unhead/vue": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/@unhead/vue/-/vue-0.7.0.tgz",
"integrity": "sha512-OoJk+zoLObUaetm9yRJXmxoS8PiZgxSnr1oS6VziWm1ImBQ7/kzvOAMiaKVg63JmjOB6Knr3rKSCL7Y+VITOiw==",
"license": "MIT",
"dependencies": {
"@unhead/schema": "0.7.0",
"hookable": "^5.4.1"
},
"funding": {
"url": "https://github.com/sponsors/harlan-zw"
},
"peerDependencies": {
"vue": ">=2.7 || >=3"
}
},
"node_modules/@vitejs/plugin-vue": { "node_modules/@vitejs/plugin-vue": {
"version": "5.2.1", "version": "5.2.1",
"resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.2.1.tgz", "resolved": "https://registry.npmjs.org/@vitejs/plugin-vue/-/plugin-vue-5.2.1.tgz",
@ -991,6 +1022,15 @@
} }
} }
}, },
"node_modules/@zhead/schema": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@zhead/schema/-/schema-1.0.1.tgz",
"integrity": "sha512-n6BDs+MjSOesuv6krG2QGyCPfdndxWX0M/G2wEGu1SPHc5jLHHi3EY1+vQvudFVXRVXquZHKsDPE7pSyeyGgHg==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/harlan-zw"
}
},
"node_modules/acorn": { "node_modules/acorn": {
"version": "8.14.0", "version": "8.14.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
@ -1308,6 +1348,12 @@
"node": ">= 6" "node": ">= 6"
} }
}, },
"node_modules/hookable": {
"version": "5.5.3",
"resolved": "https://registry.npmjs.org/hookable/-/hookable-5.5.3.tgz",
"integrity": "sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==",
"license": "MIT"
},
"node_modules/inherits": { "node_modules/inherits": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
@ -1890,6 +1936,12 @@
} }
} }
}, },
"node_modules/vite-plugin-sitemap": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/vite-plugin-sitemap/-/vite-plugin-sitemap-0.7.1.tgz",
"integrity": "sha512-4NRTkiWytLuAmcikckrLcLl9iYA20+5v6l8XshcOrzxH1WR8H0O3S6sTQYfjMrE8su/LG6Y0cTodvOdcOIxaLw==",
"dev": true
},
"node_modules/vue": { "node_modules/vue": {
"version": "3.5.13", "version": "3.5.13",
"resolved": "https://registry.npmjs.org/vue/-/vue-3.5.13.tgz", "resolved": "https://registry.npmjs.org/vue/-/vue-3.5.13.tgz",

View File

@ -11,6 +11,7 @@
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.3.1", "@element-plus/icons-vue": "^2.3.1",
"@fortawesome/fontawesome-free": "^6.7.2", "@fortawesome/fontawesome-free": "^6.7.2",
"@unhead/vue": "^0.7.0",
"element-plus": "^2.9.5", "element-plus": "^2.9.5",
"github-calendar": "^2.3.4", "github-calendar": "^2.3.4",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
@ -23,6 +24,7 @@
"@vitejs/plugin-vue": "^5.2.1", "@vitejs/plugin-vue": "^5.2.1",
"path": "^0.12.7", "path": "^0.12.7",
"unplugin-vue-components": "^28.4.1", "unplugin-vue-components": "^28.4.1",
"vite": "^6.2.0" "vite": "^6.2.0",
"vite-plugin-sitemap": "^0.7.1"
} }
} }

3
public/robots.txt Normal file
View File

@ -0,0 +1,3 @@
User-agent: *
Allow: /
Sitemap: https://www.kisechan.space/sitemap.xml

View File

@ -1,9 +1,22 @@
<script setup> <script setup>
import NavBar from "./components/NavBar.vue"; import NavBar from "./components/NavBar.vue";
import AppFooter from "./components/AppFooter.vue"; import AppFooter from "./components/AppFooter.vue";
import { useRouter } from 'vue-router'
import { watch } from 'vue'
import { useHead } from '@unhead/vue'
const openGitHubRepo = () => { const openGitHubRepo = () => {
window.open("https://github.com/Kisechan/Mainpage", "_self"); window.open("https://github.com/Kisechan/Mainpage", "_self");
}; };
const router = useRouter()
watch(() => router.currentRoute.value, (route) => {
useHead({
title: route.meta.title,
meta: route.meta.metaTags || [],
})
})
</script> </script>
<template> <template>

View File

@ -8,14 +8,17 @@ import './assets/styles/global.css'
import '@fortawesome/fontawesome-free/css/all.css'; import '@fortawesome/fontawesome-free/css/all.css';
import 'github-calendar/dist/github-calendar-responsive.css'; import 'github-calendar/dist/github-calendar-responsive.css';
import 'element-plus/theme-chalk/dark/css-vars.css' import 'element-plus/theme-chalk/dark/css-vars.css'
import { createHead } from '@unhead/vue'
const app = createApp(App) const app = createApp(App)
const head = createHead()
// 注册所有图标 // 注册所有图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) { for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component) app.component(key, component)
} }
app.use(head)
app.use(router) app.use(router)
app.use(ElementPlus) app.use(ElementPlus)
app.mount('#app') app.mount('#app')

View File

@ -5,19 +5,44 @@ const routes = [
path: "/", path: "/",
name: "home", name: "home",
component: () => import("@/views/HomeView.vue"), component: () => import("@/views/HomeView.vue"),
meta: { hideFooter: true, title: "主页" }, meta: {
hideFooter: true,
title: "主页",
metaTags: [
{
name: "description",
content: "Kisechan的个人主页。",
},
],
},
}, },
{ {
path: "/links", path: "/links",
name: "links", name: "links",
component: () => import("@/views/LinksView.vue"), component: () => import("@/views/LinksView.vue"),
meta: { title: "友链" }, meta: {
title: "友链",
metaTags: [
{
name: "description",
content: "Kisechan的个人主页 - 友链部分。",
},
],
},
}, },
{ {
path: "/tools", path: "/tools",
name: "tools", name: "tools",
component: () => import("@/views/ToolsView.vue"), component: () => import("@/views/ToolsView.vue"),
meta: { title: "工具" }, meta: {
title: "工具",
metaTags: [
{
name: "description",
content: "Kisechan的个人主页 - 工具部分。",
},
],
},
}, },
{ {
path: "/404", path: "/404",

View File

@ -1,12 +1,23 @@
import { defineConfig } from 'vite' import { defineConfig } from "vite";
import vue from '@vitejs/plugin-vue' import vue from "@vitejs/plugin-vue";
import path from 'path' import path from "path";
import sitemap from "vite-plugin-sitemap";
export default defineConfig({ export default defineConfig({
plugins: [vue()], plugins: [
vue(),
sitemap({
hostname: "https://www.kisechan.space",
routes: [
{ path: "/", name: "主页" },
{ path: "/links", name: "友链" },
{ path: "/tools", name: "工具" },
],
}),
],
resolve: { resolve: {
alias: { alias: {
'@': path.resolve(__dirname, './src') "@": path.resolve(__dirname, "./src"),
} },
} },
}) });