mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-06 01:57:34 +08:00
opt: 优化仅支持文章标题搜索
This commit is contained in:
@@ -1,17 +1,7 @@
|
|||||||
import { authState, getToken } from '~/utils/auth'
|
import { authState, getToken } from '~/utils/auth'
|
||||||
|
|
||||||
async function getPost(apiBaseUrl, id) {
|
|
||||||
return await fetch(`${apiBaseUrl}/api/posts/${id}`, {
|
|
||||||
method: 'GET',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
Authorization: `Bearer ${getToken()}`,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function searchPost(apiBaseUrl, keyword) {
|
async function searchPost(apiBaseUrl, keyword) {
|
||||||
return await fetch(`${apiBaseUrl}/api/search/global?keyword=${keyword}`, {
|
return await fetch(`${apiBaseUrl}/api/search/posts/title?keyword=${keyword}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@@ -31,15 +21,10 @@ export default (apiBaseUrl) => {
|
|||||||
const body = await response.json()
|
const body = await response.json()
|
||||||
let value = ''
|
let value = ''
|
||||||
return (
|
return (
|
||||||
body
|
body.map((item) => ({
|
||||||
?.filter((item) => item.type === 'comment' || item.type === 'post')
|
value: `[${item.title}](/posts/${item.id})`,
|
||||||
.map((item) => ({
|
html: `<div>${item.title}</div>`,
|
||||||
value:
|
})) ?? []
|
||||||
item.type === 'comment'
|
|
||||||
? `[${item.text}](posts/${item.postId}#comment-${item.id})`
|
|
||||||
: `[${item.text}](posts/${item.id})`,
|
|
||||||
html: `<div>${item.text}</div>`,
|
|
||||||
})) ?? []
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return []
|
return []
|
||||||
|
|||||||
Reference in New Issue
Block a user