33</template >
44
55<script >
6+ import docsearch from ' @docsearch/js' ;
7+
68function isSpecialClick (event ) {
79 return event .button === 1 || event .altKey || event .ctrlKey || event .metaKey || event .shiftKey ;
810}
@@ -22,71 +24,68 @@ export default {
2224 },
2325 getRelativePath (absoluteUrl ) {
2426 const { pathname , hash } = new URL (absoluteUrl);
25- const url = pathname .replace (' /v4/' , ' /' ) + hash;
27+ const url = pathname + hash;
28+
2629 return this .stripTrailingSlash (url);
2730 },
28- initialize (userOptions , lang ) {
29- Promise .all ([
30- import (/* webpackChunkName: "docsearch" */ ' @docsearch/js' ),
31- import (/* webpackChunkName: "docsearch" */ ' @docsearch/css' ),
32- ]).then (([docsearch ]) => {
33- docsearch = docsearch .default ;
34- const { algoliaOptions = {} } = userOptions;
35- docsearch (
36- Object .assign ({}, userOptions, {
37- container: ' #docsearch' ,
38- debug: process .env .NODE_ENV !== ' production' ,
39- navigator : {
40- navigate : ({ suggestionUrl }) => {
41- const { pathname: hitPathname } = new URL (window .location .origin + suggestionUrl);
42- // Vue Router doesn't handle same-page navigation so we use
43- // the native browser location API for anchor navigation.
44- if (this .$router .history .current .path === hitPathname) {
45- window .location .assign (window .location .origin + suggestionUrl);
46- } else {
47- this .$router .push (suggestionUrl);
31+ initialize (userOptions ) {
32+ docsearch ({
33+ ... userOptions,
34+ container: ' #docsearch' ,
35+ debug: process .env .NODE_ENV !== ' production' ,
36+ navigator : {
37+ navigate : ({ suggestionUrl }) => {
38+ const { pathname: hitPathname } = new URL (window .location .origin + suggestionUrl);
39+ // Vue Router doesn't handle same-page navigation so we use
40+ // the native browser location API for anchor navigation.
41+ if (this .$router .history .current .path === hitPathname) {
42+ window .location .assign (window .location .origin + suggestionUrl);
43+ return ;
44+ }
45+
46+ this .$router .push (suggestionUrl);
47+ },
48+ },
49+ transformItems : items => {
50+ return items .map (item => {
51+ return {
52+ ... item,
53+ url: this .getRelativePath (item .url ),
54+ };
55+ });
56+ },
57+ hitComponent : ({ hit, children }) => {
58+ return {
59+ type: ' a' ,
60+ ref: undefined ,
61+ constructor : undefined,
62+ key: undefined,
63+ props: {
64+ href: hit.url,
65+ onClick: event => {
66+ if (isSpecialClick (event )) {
67+ return ;
4868 }
69+ // We rely on the native link scrolling when user is
70+ // already on the right anchor because Vue Router doesn't
71+ // support duplicated history entries.
72+ if (this .$router .history .current .fullPath === hit .url ) {
73+ return ;
74+ }
75+
76+ const { pathname: hitPathname } = new URL (window .location .origin + hit .url );
77+ // If the hits goes to another page, we prevent the native link behavior
78+ // to leverage the Vue Router loading feature.
79+ if (this .$router .history .current .path !== hitPathname) {
80+ event .preventDefault ();
81+ }
82+ this .$router .push (hit .url );
4983 },
84+ children,
5085 },
51- transformItems : items => {
52- return items .map (item => {
53- return Object .assign ({}, item, {
54- url: this .getRelativePath (item .url ),
55- });
56- });
57- },
58- hitComponent : ({ hit, children }) => {
59- return {
60- type: ' a' ,
61- ref: undefined ,
62- constructor : undefined,
63- key: undefined,
64- props: {
65- href: hit.url,
66- onClick: event => {
67- if (isSpecialClick (event )) {
68- return ;
69- }
70- // We rely on the native link scrolling when user is
71- // already on the right anchor because Vue Router doesn't
72- // support duplicated history entries.
73- if (this .$router .history .current .fullPath === hit .url ) {
74- return ;
75- }
76- const { pathname: hitPathname } = new URL (window .location .origin + hit .url );
77- // If the hits goes to another page, we prevent the native link behavior
78- // to leverage the Vue Router loading feature.
79- if (this .$router .history .current .path !== hitPathname) {
80- event .preventDefault ();
81- }
82- this .$router .push (hit .url );
83- },
84- children,
85- },
86- };
87- },
88- })
89- );
86+ __v: null ,
87+ };
88+ },
9089 });
9190 },
9291 update (options , lang ) {
@@ -106,6 +105,8 @@ export default {
106105 </script >
107106
108107<style lang="postcss">
108+ @import '@docsearch/css' ;
109+
109110.DocSearch {
110111 font-family : Arial, Helvetica, sans-serif;
111112 --accent : #9580ff ;
0 commit comments