增加新项目
This commit is contained in:
70
项目合集/最新写真app/backend/router/search.js
Normal file
70
项目合集/最新写真app/backend/router/search.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import express from "express";
|
||||
import Util from '../utils/index.js'
|
||||
import Config from '../config/config.js'
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// 搜索页面的 热门关键词 & 推荐
|
||||
// http://192.168.31.101:9940/v1/api/search/hot
|
||||
router.get('/hot', async (req, res) => {
|
||||
let $ = await Util.get(`${Config.baseUrl}/wp-admin/admin-ajax.php?action=search_box`)
|
||||
let result = {
|
||||
hotKeyword: [],
|
||||
recommend: []
|
||||
}
|
||||
|
||||
$(".search-input .search-keywords").eq(0).find("div a").each(function() {
|
||||
result.hotKeyword.push($(this).text())
|
||||
})
|
||||
|
||||
$(".search-input .relates-thumb .swiper-slide a").each(function() {
|
||||
result.recommend.push({
|
||||
id: Util.split($(this).attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find("img").attr("data-src"),
|
||||
title: $(this).find(".text-ellipsis").text(),
|
||||
time: $(this).find(".px12 item").eq(0).text(),
|
||||
view: $(this).find(".px12 item").eq(1).text(),
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// 搜索接口
|
||||
// http://192.168.31.101:9940/v1/api/search/key?keyword=杨晨晨&page=1
|
||||
router.get('/key', async (req, res) => {
|
||||
let { keyword, page } = req.query
|
||||
page = page || 1
|
||||
|
||||
let $ = await Util.get(`${Config.baseUrl}/page/${page}?s=${encodeURI(keyword)}&type=post`)
|
||||
let result = {
|
||||
currentPage: page,
|
||||
totalPage: Util.maxPage(".pagenav a", $),
|
||||
message: $(".search-content .badg .focus-color").text(),
|
||||
list: [],
|
||||
}
|
||||
|
||||
$(".search-content .posts-item").each(function() {
|
||||
result.list.push({
|
||||
id: Util.split($(this).find(".item-thumbnail a").attr("href")).replace(/[^\d]/g, ""),
|
||||
thumbnail: $(this).find(".item-thumbnail a img").attr("data-src"),
|
||||
title: $(this).find(".item-body .item-heading a").text(),
|
||||
time: $(this).find(".item-body .item-meta .icon-circle").text(),
|
||||
view: $(this).find(".item-body .item-meta .meta-right .meta-view").text()
|
||||
})
|
||||
})
|
||||
|
||||
res.json({
|
||||
status: 200,
|
||||
copyright: `bmy ${new Date()}`,
|
||||
data: result
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user