提交 833166d5 编写于 作者: D DCloud_LXH

chore: search folder structure

上级 d73e8a27
<template>
<li :class="li_class">
<a :href="item.url" @click="onSearchClose">
<a :href="item.url">
<div class="DocSearch-Hit-Container">
<div
class="DocSearch-Hit-content-wrapper"
......@@ -44,7 +44,6 @@
data() {
return {};
},
inject: ['onSearchClose'],
props: {
item: {
type: Object,
......@@ -76,51 +75,51 @@
};
</script>
<style lang="stylus">
.DocSearch-Hit
border-radius 0px
display flex
padding-bottom 0px
position relative
.DocSearch-Hit
border-radius 0px
display flex
padding-bottom 0px
position relative
&:not(:first-child)
border-top 1px solid #f5f6f7
&:not(:first-child)
border-top 1px solid #f5f6f7
a
background var(--docsearch-hit-background)
border-radius 0px
// box-shadow var(--docsearch-hit-shadow)
box-shadow none
display block
padding-left var(--docsearch-spacing)
width 100%
a
background var(--docsearch-hit-background)
border-radius 0px
// box-shadow var(--docsearch-hit-shadow)
box-shadow none
display block
padding-left var(--docsearch-spacing)
width 100%
.DocSearch-Hit-Container
align-items center
color #444950
display flex
flex-direction row
height 56px
padding 0 12px 0 0
.DocSearch-Hit-Container
align-items center
color #444950
display flex
flex-direction row
height 56px
padding 0 12px 0 0
.DocSearch-Hit-content-wrapper
overflow hidden
display flex
flex 1 1 auto
flex-direction column
font-weight 500
justify-content center
line-height 1.2em
margin 0 8px
overflow-x hidden
position relative
text-overflow ellipsis
white-space nowrap
width 80%
.DocSearch-Hit-content-wrapper
overflow hidden
display flex
flex 1 1 auto
flex-direction column
font-weight 500
justify-content center
line-height 1.2em
margin 0 8px
overflow-x hidden
position relative
text-overflow ellipsis
white-space nowrap
width 80%
.DocSearch-Hit-title
font-size 0.9em
.DocSearch-Hit-title
font-size 0.9em
.DocSearch-Hit-path
// color $accentColor
font-size 0.75em
.DocSearch-Hit-path
// color $accentColor
font-size 0.75em
</style>
......@@ -9,7 +9,12 @@
<ul id="docsearch-list">
<template v-for="(item, index) in results">
<Result :key="[title, item.objectID].join(':')" :item="item" :index="index" />
<Result
:key="[title, item.objectID].join(':')"
:item="item"
:index="index"
@click.native="event => onSelect({ item, event })"
/>
</template>
</ul>
</section>
......@@ -30,6 +35,10 @@
type: Array,
default: [],
},
onSelect: {
type: Function,
default: () => {},
},
},
computed: {
tag() {
......
......@@ -85,7 +85,12 @@
<div class="result-wrap">
<template v-if="isAlgolia">
<template v-for="item in resultList">
<Results :key="item.id" :title="item.title" :results="item.items" />
<Results
:key="item.sourceId"
:title="item.title"
:results="item.items"
:onSelect="item.onSelect"
/>
</template>
</template>
......@@ -139,9 +144,10 @@
import Results from './components/Results.vue';
import pagination from './components/pagination.vue';
import MainNavbarLink from '../MainNavbarLink.vue';
import { search as searchClient } from './searchClient';
import { postExt, postAsk } from './postDcloudServer';
import { forbidScroll, removeHighlightTags, debounce, isEditingContent } from '../../util';
import { search as searchClient } from './utils/searchClient';
import { postExt, postAsk } from './utils/postDcloudServer';
import { forbidScroll, debounce } from '../../util';
import { removeHighlightTags, isEditingContent } from './utils/searchUtils';
const resolveRoutePathFromUrl = (url, base = '/') =>
url
......@@ -157,12 +163,6 @@
components: { NavbarLogo, Results, pagination, MainNavbarLink },
provide() {
return {
onSearchClose: this.onSearchClose,
};
},
data() {
return {
openSearch: false,
......@@ -314,7 +314,7 @@
this.resultList = hits.map(item => {
const items = item.getItems();
return {
id: item.sourceId,
...item,
title: removeHighlightTags(items[0]),
items,
};
......@@ -356,6 +356,7 @@
url: resolveRoutePathFromUrl(item.url, this.$site.base),
};
}),
onClose: this.onSearchClose,
})
);
},
......
import algoliasearch from 'algoliasearch/dist/algoliasearch-lite.esm.browser';
import { removeHighlightTags, groupBy } from '../../util'
import { removeHighlightTags, groupBy } from './searchUtils'
let searchClient
function createSearchClient(appId, apiKey) {
......@@ -10,7 +10,7 @@ function createSearchClient(appId, apiKey) {
return searchClient
}
export function search({ query, indexName, appId, apiKey, searchParameters = {}, snippetLength = 0, transformItems = () => { }, ...args }) {
export function search({ query, indexName, appId, apiKey, searchParameters = {}, snippetLength = 0, transformItems = () => { }, onClose = () => { }, ...args }) {
return createSearchClient(appId, apiKey)
.search([
{
......@@ -65,9 +65,9 @@ export function search({ query, indexName, appId, apiKey, searchParameters = {},
onSelect({ item, event }) {
// saveRecentSearch(item);
// if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
// onClose();
// }
if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
onClose()
}
},
getItemUrl({ item }) {
return item.url;
......
import Vue from 'vue';
export * from './searchUtils';
export const isServer = Vue.prototype.$isServer
export const hashRE = /#.*$/
export const extRE = /\.(md|html)$/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册