Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algolia search #48

Merged
merged 9 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions layouts/GlobalLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
tm-sidebar(:visible="sidebarVisible" @visible="sidebarVisible = $event").sheet__sidebar
tm-sidebar-content(:value="tree" :tree="directoryTree" :compact="true")
tm-sidebar(:visible="searchPanel" @visible="searchPanel = $event" max-width="100vw" width="480px" side="right" box-shadow="0 0 50px 10px rgba(0,0,0,.1)" background-color="rgba(0,0,0,0)").sheet__sidebar
section-search(@visible="searchPanel = $event" :query="searchQuery" @query="searchQuery = $event")
section-search(@visible="searchPanel = $event" :base="$site.base" @cancel="searchPanel = false" :algoliaConfig="algoliaConfig" @select="searchSelect($event)" :query="searchQuery" @query="searchQuery = $event" :site="$site")
tm-sidebar(:visible="rsidebarVisible" @visible="rsidebarVisible = $event" side="right").sheet__sidebar.sheet__sidebar__toc
tm-toc-menu(@visible="rsidebarVisible = $event")
</template>
Expand Down Expand Up @@ -278,12 +278,16 @@ import {
import hotkeys from "hotkeys-js";
import { CookieBanner } from "@cosmos-ui/vue";
import axios from "axios";
import { SectionSearch } from "@cosmos-ui/vue";

const endingSlashRE = /\/$/;
const outboundRE = /^[a-z]+:/i;

export default {
components: { CookieBanner },
components: {
CookieBanner,
SectionSearch
},
data: function() {
return {
sidebarVisible: null,
Expand Down Expand Up @@ -347,6 +351,11 @@ export default {
document.documentElement.style.setProperty("--vh", `${vh}px`);
},
computed: {
algoliaConfig() {
const localhost = window.location.hostname === "localhost";
const algolia = this.$themeConfig.algolia;
return localhost ? {} : algolia;
},
editLink() {
if (this.$page.frontmatter.editLink === false) {
return;
Expand Down Expand Up @@ -432,6 +441,19 @@ export default {
}
},
methods: {
searchSelect(e) {
if (e.id) {
const page = find(this.$site.pages, ["key", e.id]);
if (page && page.regularPath) {
if (this.$page.regularPath != page.regularPath) {
this.$router.push(page.regularPath);
this.searchPanel = false;
}
}
} else if (e.url) {
window.location.assign(e.url);
}
},
createEditLink(repo, docsRepo, docsDir, docsBranch, path) {
const bitbucket = /bitbucket.org/;
if (bitbucket.test(repo)) {
Expand All @@ -456,19 +478,13 @@ export default {
path
);
},
log(e) {
console.log(e);
},
searchVisible(bool) {
this.searchPanel = bool;
},
overlayClick(e) {
this.sidebarVisible = false;
this.rsidebarVisible = false;
this.searchPanel = false;
// this.$nextTick(() => {
// document.elementFromPoint(e.clientX, e.clientY).click();
// });
},
selectHeader(elements) {
if (elements.length > 0) {
Expand Down
Loading