Skip to content

Commit 636757c

Browse files
committed
尝试部署AI文章内容摘要功能
1 parent 481880b commit 636757c

File tree

10 files changed

+673
-248
lines changed

10 files changed

+673
-248
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_DEEPSEEK_API_KEY=sk-2099e2b9181340209c8e2ca4cd99a937

docs/.vitepress/config.mts

Lines changed: 73 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
1-
import { defineConfig } from 'vitepress'
2-
import { groupIconMdPlugin, groupIconVitePlugin } from 'vitepress-plugin-group-icons' // 实现自定义图标的插件
1+
import { defineConfig } from "vitepress";
2+
import {
3+
groupIconMdPlugin,
4+
groupIconVitePlugin,
5+
} from "vitepress-plugin-group-icons"; // 实现自定义图标的插件
36

4-
import nav from './nav.mts'; // 导航栏配置
5-
import sidebar from './sidebar.mts'; // 侧边栏配置
7+
import nav from "./nav.mts"; // 导航栏配置
8+
import sidebar from "./sidebar.mts"; // 侧边栏配置
69

7-
import { RSSOptions, RssPlugin } from 'vitepress-plugin-rss' // 实现自动为 VitePress 网站添加 RSS 订阅的插件
8-
const baseUrl = 'https://vite.xingji.fun'
10+
import { RSSOptions, RssPlugin } from "vitepress-plugin-rss"; // 实现自动为 VitePress 网站添加 RSS 订阅的插件
11+
const baseUrl = "https://vite.xingji.fun";
912
const RSS: RSSOptions = {
10-
title: 'XINGJI',
13+
title: "XINGJI",
1114
baseUrl,
12-
copyright: 'Copyright (c) 2024-present, XINGJI ',
13-
}
15+
copyright: "Copyright (c) 2024-present, XINGJI ",
16+
};
1417

15-
import { GitChangelog, GitChangelogMarkdownSection, } from '@nolebase/vitepress-plugin-git-changelog/vite' // 实现自动生成 CHANGELOG 的插件
18+
import {
19+
GitChangelog,
20+
GitChangelogMarkdownSection,
21+
} from "@nolebase/vitepress-plugin-git-changelog/vite"; // 实现自动生成 CHANGELOG 的插件
1622

1723
// https://vitepress.dev/reference/site-config
1824
export default defineConfig({
19-
lang: 'zh-CN', //语言,可选 en-US
25+
lang: "zh-CN", //语言,可选 en-US
2026
title: "XINGJI", //站点名
2127
description: "我的vitpress文档教程", //站点描述
22-
appearance: 'dark',
28+
appearance: "dark",
2329
lastUpdated: true, //首次配置不会立即生效,需git提交后爬取时间戳
2430
head: [
25-
['link',{ rel: 'icon', href: '/my-logo.png'}], //fav图标
31+
["link", { rel: "icon", href: "/my-logo.png" }], //fav图标
2632
],
2733
// 站点地图
2834
sitemap: {
29-
hostname: 'https://vite.xingji.fun',
35+
hostname: "https://vite.xingji.fun",
3036
},
3137

3238
//多语言
3339
locales: {
3440
root: {
35-
label: '简体中文',
36-
lang: 'Zh_CN',
41+
label: "简体中文",
42+
lang: "Zh_CN",
3743
},
3844
en: {
39-
label: 'English',
40-
lang: 'en',
41-
link: '/en/',
45+
label: "English",
46+
lang: "en",
47+
link: "/en/",
4248
},
4349
},
4450

@@ -50,93 +56,101 @@ export default defineConfig({
5056
// 组件插入h1标题下
5157
config: (md) => {
5258
md.renderer.rules.heading_close = (tokens, idx, options, env, slf) => {
53-
let htmlResult = slf.renderToken(tokens, idx, options);
54-
if (tokens[idx].tag === 'h1') htmlResult += `<ArticleMetadata />`;
59+
let htmlResult = slf.renderToken(tokens, idx, options);
60+
if (tokens[idx].tag === "h1") htmlResult += `<ArticleMetadata />`;
5561
return htmlResult;
56-
}
57-
md.use(groupIconMdPlugin) //代码组图标
58-
}
62+
};
63+
md.use(groupIconMdPlugin); //代码组图标
64+
},
5965
},
6066
// 实现自动为 VitePress 网站添加 RSS 订阅的插件
6167
vite: {
6268
// ↓↓↓↓↓
69+
resolve: {
70+
alias: {
71+
"./VPContent.vue": "./theme/components/VPContent.vue",
72+
},
73+
},
74+
// 确保环境变量能够正常工作
75+
envPrefix: "VITE_",
6376
plugins: [
6477
RssPlugin(RSS),
6578
groupIconVitePlugin(), //代码组图标
6679
GitChangelog({
6780
// 填写在此处填写您的仓库链接
68-
repoURL: () => 'https://github.com/XingJi-love/Blog-VitePress',
81+
repoURL: () => "https://github.com/XingJi-love/Blog-VitePress",
6982
}),
7083
GitChangelogMarkdownSection(),
7184
],
7285
optimizeDeps: {
7386
exclude: [
74-
'@nolebase/vitepress-plugin-enhanced-readabilities/client',
75-
'vitepress',
76-
'@nolebase/ui',
87+
"@nolebase/vitepress-plugin-enhanced-readabilities/client",
88+
"vitepress",
89+
"@nolebase/ui",
7790
],
7891
},
7992
ssr: {
8093
noExternal: [
81-
'@nolebase/vitepress-plugin-enhanced-readabilities',
82-
'@nolebase/vitepress-plugin-highlight-targeted-heading',
83-
'@nolebase/ui'
94+
"@nolebase/vitepress-plugin-enhanced-readabilities",
95+
"@nolebase/vitepress-plugin-highlight-targeted-heading",
96+
"@nolebase/ui",
8497
],
8598
},
8699
},
87100

88101
themeConfig: {
89102
//左上角logo
90-
logo: '/my-logo.png',
91-
darkModeSwitchLabel: '深浅模式',//手机端深浅模式文字修改
92-
sidebarMenuLabel: '目录', //侧边栏文字更改(移动端)
93-
returnToTopLabel: '返回顶部', //返回顶部文字修改
94-
outline: {
95-
level: [2,4], // 显示2-4级标题
103+
logo: "/my-logo.png",
104+
darkModeSwitchLabel: "深浅模式", //手机端深浅模式文字修改
105+
sidebarMenuLabel: "目录", //侧边栏文字更改(移动端)
106+
returnToTopLabel: "返回顶部", //返回顶部文字修改
107+
outline: {
108+
level: [2, 4], // 显示2-4级标题
96109
// level: 'deep', // 显示2-6级标题
97-
label: '页面导航' // 文字显示
110+
label: "页面导航", // 文字显示
98111
},
99112
//上次更新时间
100113
lastUpdated: {
101-
text: '上次更新时间',
114+
text: "上次更新时间",
102115
formatOptions: {
103-
dateStyle: 'short', // 可选值full、long、medium、short
104-
timeStyle: 'medium' // 可选值full、long、medium、short
116+
dateStyle: "short", // 可选值full、long、medium、short
117+
timeStyle: "medium", // 可选值full、long、medium、short
105118
},
106119
},
107120
//自定义上下页名
108-
docFooter: {
109-
prev: '上一页',
110-
next: '下一页',
121+
docFooter: {
122+
prev: "上一页",
123+
next: "下一页",
111124
},
112125
// https://vitepress.dev/reference/default-theme-config
113126
//导航栏
114127
nav: nav, // 导航栏配置
115128
sidebar: sidebar, // 侧边栏配置
116129

117130
//编辑本页
118-
editLink: {
119-
pattern: 'https://github.com/XingJi-love/Blog-VitePress', // 改成自己的仓库
120-
text: '在GitHub编辑本页'
131+
editLink: {
132+
pattern: "https://github.com/XingJi-love/Blog-VitePress", // 改成自己的仓库
133+
text: "在GitHub编辑本页",
121134
},
122135

123136
socialLinks: [
124-
{ icon: 'github', link: 'https://github.com/XingJi-love' },
137+
{ icon: "github", link: "https://github.com/XingJi-love" },
125138
{
126-
icon: {
127-
svg: '<svg t="1728183147842" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2076" data-darkreader-inline-fill="" width="200" height="200"><path d="M512 0c282.784 0 512 229.216 512 512s-229.216 512-512 512S0 794.784 0 512 229.216 0 512 0z m189.952 752l11.2-108.224c-31.904 9.536-100.928 16.128-147.712 16.128-134.464 0-205.728-47.296-195.328-146.304 11.584-110.688 113.152-145.696 232.64-145.696 54.784 0 122.432 8.8 151.296 18.336L768 272.704C724.544 262.24 678.272 256 599.584 256c-203.2 0-388.704 94.88-406.4 263.488C178.336 660.96 303.584 768 535.616 768c80.672 0 138.464-6.432 166.336-16z" fill="#1296db" p-id="2077" data-darkreader-inline-fill="" style="--darkreader-inline-fill:#0e78af;"></path></svg>',
128-
},
129-
link: 'https://blog.csdn.net/AcsdnHZB?spm=1011.2648.3001.5343',
139+
icon: {
140+
svg: '<svg t="1728183147842" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2076" data-darkreader-inline-fill="" width="200" height="200"><path d="M512 0c282.784 0 512 229.216 512 512s-229.216 512-512 512S0 794.784 0 512 229.216 0 512 0z m189.952 752l11.2-108.224c-31.904 9.536-100.928 16.128-147.712 16.128-134.464 0-205.728-47.296-195.328-146.304 11.584-110.688 113.152-145.696 232.64-145.696 54.784 0 122.432 8.8 151.296 18.336L768 272.704C724.544 262.24 678.272 256 599.584 256c-203.2 0-388.704 94.88-406.4 263.488C178.336 660.96 303.584 768 535.616 768c80.672 0 138.464-6.432 166.336-16z" fill="#1296db" p-id="2077" data-darkreader-inline-fill="" style="--darkreader-inline-fill:#0e78af;"></path></svg>',
141+
},
142+
link: "https://blog.csdn.net/AcsdnHZB?spm=1011.2648.3001.5343",
130143
},
131144
{
132-
icon: {
133-
svg: '<svg t="1728183344877" class="icon" viewBox="0 0 1129 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1673" data-darkreader-inline-fill="" width="200" height="200"><path d="M234.909 9.656a80.468 80.468 0 0 1 68.398 0 167.374 167.374 0 0 1 41.843 30.578l160.937 140.82h115.07l160.936-140.82a168.983 168.983 0 0 1 41.843-30.578A80.468 80.468 0 0 1 930.96 76.445a80.468 80.468 0 0 1-17.703 53.914 449.818 449.818 0 0 1-35.406 32.187 232.553 232.553 0 0 1-22.531 18.508h100.585a170.593 170.593 0 0 1 118.289 53.109 171.397 171.397 0 0 1 53.914 118.288v462.693a325.897 325.897 0 0 1-4.024 70.007 178.64 178.64 0 0 1-80.468 112.656 173.007 173.007 0 0 1-92.539 25.75h-738.7a341.186 341.186 0 0 1-72.421-4.024A177.835 177.835 0 0 1 28.91 939.065a172.202 172.202 0 0 1-27.36-92.539V388.662a360.498 360.498 0 0 1 0-66.789A177.03 177.03 0 0 1 162.487 178.64h105.414c-16.899-12.07-31.383-26.555-46.672-39.43a80.468 80.468 0 0 1-25.75-65.984 80.468 80.468 0 0 1 39.43-63.57M216.4 321.873a80.468 80.468 0 0 0-63.57 57.937 108.632 108.632 0 0 0 0 30.578v380.615a80.468 80.468 0 0 0 55.523 80.469 106.218 106.218 0 0 0 34.601 5.632h654.208a80.468 80.468 0 0 0 76.444-47.476 112.656 112.656 0 0 0 8.047-53.109v-354.06a135.187 135.187 0 0 0 0-38.625 80.468 80.468 0 0 0-52.304-54.719 129.554 129.554 0 0 0-49.89-7.242H254.22a268.764 268.764 0 0 0-37.82 0z m0 0" fill="#20B0E3" p-id="1674" data-darkreader-inline-fill="" style="--darkreader-inline-fill:#168ab3;"></path><path d="M348.369 447.404a80.468 80.468 0 0 1 55.523 18.507 80.468 80.468 0 0 1 28.164 59.547v80.468a80.468 80.468 0 0 1-16.094 51.5 80.468 80.468 0 0 1-131.968-9.656 104.609 104.609 0 0 1-10.46-54.719v-80.468a80.468 80.468 0 0 1 70.007-67.593z m416.02 0a80.468 80.468 0 0 1 86.102 75.64v80.468a94.148 94.148 0 0 1-12.07 53.11 80.468 80.468 0 0 1-132.773 0 95.757 95.757 0 0 1-12.875-57.133V519.02a80.468 80.468 0 0 1 70.007-70.812z m0 0" fill="#20B0E3" p-id="1675" data-darkreader-inline-fill="" style="--darkreader-inline-fill:#168ab3;"></path></svg>',
134-
},
135-
link: 'https://space.bilibili.com/1289480756?spm_id_from=333.1007.0.0',
136-
},
145+
icon: {
146+
svg: '<svg t="1728183344877" class="icon" viewBox="0 0 1129 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1673" data-darkreader-inline-fill="" width="200" height="200"><path d="M234.909 9.656a80.468 80.468 0 0 1 68.398 0 167.374 167.374 0 0 1 41.843 30.578l160.937 140.82h115.07l160.936-140.82a168.983 168.983 0 0 1 41.843-30.578A80.468 80.468 0 0 1 930.96 76.445a80.468 80.468 0 0 1-17.703 53.914 449.818 449.818 0 0 1-35.406 32.187 232.553 232.553 0 0 1-22.531 18.508h100.585a170.593 170.593 0 0 1 118.289 53.109 171.397 171.397 0 0 1 53.914 118.288v462.693a325.897 325.897 0 0 1-4.024 70.007 178.64 178.64 0 0 1-80.468 112.656 173.007 173.007 0 0 1-92.539 25.75h-738.7a341.186 341.186 0 0 1-72.421-4.024A177.835 177.835 0 0 1 28.91 939.065a172.202 172.202 0 0 1-27.36-92.539V388.662a360.498 360.498 0 0 1 0-66.789A177.03 177.03 0 0 1 162.487 178.64h105.414c-16.899-12.07-31.383-26.555-46.672-39.43a80.468 80.468 0 0 1-25.75-65.984 80.468 80.468 0 0 1 39.43-63.57M216.4 321.873a80.468 80.468 0 0 0-63.57 57.937 108.632 108.632 0 0 0 0 30.578v380.615a80.468 80.468 0 0 0 55.523 80.469 106.218 106.218 0 0 0 34.601 5.632h654.208a80.468 80.468 0 0 0 76.444-47.476 112.656 112.656 0 0 0 8.047-53.109v-354.06a135.187 135.187 0 0 0 0-38.625 80.468 80.468 0 0 0-52.304-54.719 129.554 129.554 0 0 0-49.89-7.242H254.22a268.764 268.764 0 0 0-37.82 0z m0 0" fill="#20B0E3" p-id="1674" data-darkreader-inline-fill="" style="--darkreader-inline-fill:#168ab3;"></path><path d="M348.369 447.404a80.468 80.468 0 0 1 55.523 18.507 80.468 80.468 0 0 1 28.164 59.547v80.468a80.468 80.468 0 0 1-16.094 51.5 80.468 80.468 0 0 1-131.968-9.656 104.609 104.609 0 0 1-10.46-54.719v-80.468a80.468 80.468 0 0 1 70.007-67.593z m416.02 0a80.468 80.468 0 0 1 86.102 75.64v80.468a94.148 94.148 0 0 1-12.07 53.11 80.468 80.468 0 0 1-132.773 0 95.757 95.757 0 0 1-12.875-57.133V519.02a80.468 80.468 0 0 1 70.007-70.812z m0 0" fill="#20B0E3" p-id="1675" data-darkreader-inline-fill="" style="--darkreader-inline-fill:#168ab3;"></path></svg>',
147+
},
148+
link: "https://space.bilibili.com/1289480756?spm_id_from=333.1007.0.0",
149+
},
137150
],
138151
footer: {
139-
copyright: 'Copyright © 2024 XINGJI <a href="https://icp.gov.moe/?keyword=20250322" target="_blank">萌ICP备20250322号</a>'
152+
copyright:
153+
'Copyright © 2024 XINGJI <a href="https://icp.gov.moe/?keyword=20250322" target="_blank">萌ICP备20250322号</a>',
140154
},
141155
// 设置搜索框的样式
142156
search: {
@@ -159,4 +173,4 @@ export default defineConfig({
159173
},
160174
},
161175
},
162-
})
176+
});
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<template>
2+
<ClientOnly>
3+
<div class="max-w-3xl mx-auto p-4">
4+
<div class="bg-[#1C1C1E] rounded-lg shadow-xl overflow-hidden">
5+
<!-- Header -->
6+
<div class="p-4 flex items-center justify-between">
7+
<div class="flex items-center space-x-2">
8+
<div class="w-8 h-8 bg-[#E6A53F] rounded-lg flex items-center justify-center">
9+
<RobotIcon class="w-5 h-5 text-black" />
10+
</div>
11+
<h2 class="text-white text-lg font-medium flex items-center">
12+
文章摘要
13+
<ChevronRightIcon class="w-5 h-5 ml-1 text-gray-400" />
14+
</h2>
15+
</div>
16+
<div class="px-3 py-1 bg-[#E6A53F] rounded-full">
17+
<span class="text-black text-sm font-medium">XINGJIGPT</span>
18+
</div>
19+
</div>
20+
21+
<!-- Content -->
22+
<div class="p-6">
23+
<div v-if="loading" class="text-gray-400 flex items-center">
24+
<Loader2Icon class="w-5 h-5 animate-spin" />
25+
<span class="ml-2">正在生成摘要...</span>
26+
</div>
27+
28+
<div v-else-if="error" class="text-red-400">
29+
{{ error }}
30+
</div>
31+
32+
<div v-else-if="summary" class="text-white text-base leading-relaxed">
33+
{{ summary }}
34+
</div>
35+
36+
<button
37+
@click="generateSummary"
38+
:disabled="loading"
39+
class="mt-4 bg-[#E6A53F] text-black px-4 py-2 rounded-lg hover:bg-[#D49530] disabled:opacity-50"
40+
>
41+
生成摘要
42+
</button>
43+
</div>
44+
45+
<!-- Footer -->
46+
<div class="px-6 py-3 border-t border-gray-800">
47+
<p class="text-gray-500 text-sm">
48+
此内容根据文章生成,并经过人工审核,仅用于文章内容的解释与总结
49+
</p>
50+
</div>
51+
</div>
52+
</div>
53+
</ClientOnly>
54+
</template>
55+
56+
<script setup>
57+
import { ref, onMounted } from 'vue'
58+
import { RobotIcon, ChevronRightIcon, Loader2Icon } from 'lucide-vue-next'
59+
60+
const summary = ref('')
61+
const loading = ref(false)
62+
const error = ref(null)
63+
const articleContent = ref('')
64+
65+
onMounted(() => {
66+
// 获取当前页面的主要内容
67+
const mainContent = document.querySelector('.vp-doc')?.textContent || ''
68+
articleContent.value = mainContent
69+
})
70+
71+
const generateSummary = async () => {
72+
if (!articleContent.value) return
73+
74+
loading.value = true
75+
error.value = null
76+
77+
try {
78+
const response = await fetch('https://api.deepseek.com/v1/summarize', {
79+
method: 'POST',
80+
headers: {
81+
'Content-Type': 'application/json',
82+
'Authorization': `Bearer ${import.meta.env.VITE_DEEPSEEK_API_KEY}`
83+
},
84+
body: JSON.stringify({
85+
model: 'deepseek-chat',
86+
messages: [
87+
{
88+
role: 'user',
89+
content: `请对以下文章内容进行摘要总结:\n\n${articleContent.value}`
90+
}
91+
]
92+
})
93+
})
94+
95+
if (!response.ok) {
96+
throw new Error('API 请求失败')
97+
}
98+
99+
const data = await response.json()
100+
summary.value = data.choices[0].message.content
101+
} catch (err) {
102+
error.value = '生成摘要时出错,请稍后重试'
103+
console.error('Error:', err)
104+
} finally {
105+
loading.value = false
106+
}
107+
}
108+
</script>

0 commit comments

Comments
 (0)