Skip to content

Commit 33a2410

Browse files
committed
goto ask
1 parent 3313b4c commit 33a2410

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

docs/.vitepress/theme/components/AIAssistant.vue

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const texts = computed(() => {
3232
description: '输入您的问题,复制提示词后可在任何 AI 助手(如 ChatGPT、Claude、Cursor、GitHub Copilot 等)中使用',
3333
placeholder: '例如:如何配置一个使用 C++20 模块的目标?',
3434
button: '复制提示词',
35+
jumpButton: '在 Perplexity 提问',
3536
submitting: '复制中...',
3637
hint: '提示:按',
3738
hintKey: 'Ctrl/Cmd + Enter',
@@ -50,6 +51,7 @@ const texts = computed(() => {
5051
description: 'Enter your question, copy the prompt and use it in any AI assistant (such as ChatGPT, Claude, Cursor, GitHub Copilot, etc.)',
5152
placeholder: 'For example: How do I configure a target that uses C++20 modules?',
5253
button: 'Copy Prompt',
54+
jumpButton: 'Ask on Perplexity',
5355
submitting: 'Copying...',
5456
hint: 'Tip: Press',
5557
hintKey: 'Ctrl/Cmd + Enter',
@@ -84,6 +86,23 @@ function copyPrompt() {
8486
})
8587
}
8688
89+
function jumpToPerplexity() {
90+
if (!question.value.trim()) {
91+
alert(texts.value.alertEmpty)
92+
return
93+
}
94+
95+
// 构建完整的提示词(包含模板和用户问题)
96+
const fullPrompt = texts.value.promptTemplate + question.value.trim()
97+
98+
// URL 编码整个提示词
99+
const encodedPrompt = encodeURIComponent(fullPrompt)
100+
101+
// 跳转到 Perplexity AI
102+
const url = `https://www.perplexity.ai/search/?q=${encodedPrompt}`
103+
window.open(url, '_blank')
104+
}
105+
87106
function handleKeyPress(event: KeyboardEvent) {
88107
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
89108
event.preventDefault()
@@ -106,13 +125,22 @@ function handleKeyPress(event: KeyboardEvent) {
106125
rows="4"
107126
@keydown="handleKeyPress"
108127
></textarea>
109-
<button
110-
class="ai-assistant-button"
111-
:disabled="isSubmitting || !question.trim()"
112-
@click="copyPrompt"
113-
>
114-
{{ isSubmitting ? texts.submitting : texts.button }}
115-
</button>
128+
<div class="ai-assistant-actions">
129+
<button
130+
class="ai-assistant-button"
131+
:disabled="isSubmitting || !question.trim()"
132+
@click="copyPrompt"
133+
>
134+
{{ isSubmitting ? texts.submitting : texts.button }}
135+
</button>
136+
<button
137+
class="ai-assistant-button ai-assistant-button-secondary"
138+
:disabled="!question.trim()"
139+
@click="jumpToPerplexity"
140+
>
141+
{{ texts.jumpButton }}
142+
</button>
143+
</div>
116144
<p class="ai-assistant-hint">
117145
{{ texts.hint }} <kbd>{{ texts.hintKey }}</kbd> {{ texts.hintSuffix }}
118146
</p>
@@ -168,6 +196,12 @@ function handleKeyPress(event: KeyboardEvent) {
168196
box-shadow: 0 0 0 3px var(--vp-c-brand-soft);
169197
}
170198
199+
.ai-assistant-actions {
200+
display: flex;
201+
gap: 0.75rem;
202+
flex-wrap: wrap;
203+
}
204+
171205
.ai-assistant-button {
172206
padding: 0.75rem 1.5rem;
173207
font-size: 0.95rem;
@@ -178,7 +212,17 @@ function handleKeyPress(event: KeyboardEvent) {
178212
border-radius: 6px;
179213
cursor: pointer;
180214
transition: background-color 0.2s, transform 0.1s;
181-
align-self: flex-start;
215+
}
216+
217+
.ai-assistant-button-secondary {
218+
color: var(--vp-c-text-1);
219+
background: var(--vp-c-bg-alt);
220+
border: 1px solid var(--vp-c-divider);
221+
}
222+
223+
.ai-assistant-button-secondary:hover:not(:disabled) {
224+
background: var(--vp-c-bg-soft);
225+
border-color: var(--vp-c-brand);
182226
}
183227
184228
.ai-assistant-button:hover:not(:disabled) {

0 commit comments

Comments
 (0)