You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zr...@apache.org on 2020/03/04 13:02:00 UTC
[camel-website] 11/13: fix: load algolia search from vendor dir
This is an automated email from the ASF dual-hosted git repository.
zregvart pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-website.git
commit 16dd98a21823ba4011725489a6b38e88bcd7988d
Author: Nayananga Muhandiram <na...@wso2.com>
AuthorDate: Tue Mar 3 22:24:41 2020 +0530
fix: load algolia search from vendor dir
---
antora-ui-camel/src/js/06-search.js | 89 --------------------
antora-ui-camel/src/js/vendor/algoliasearch.js | 4 -
.../src/js/vendor/alogliasearch.bundle.js | 95 ++++++++++++++++++++++
antora-ui-camel/src/partials/footer-scripts.hbs | 4 +-
layouts/partials/footer.html | 4 +-
5 files changed, 99 insertions(+), 97 deletions(-)
diff --git a/antora-ui-camel/src/js/06-search.js b/antora-ui-camel/src/js/06-search.js
deleted file mode 100644
index 803cf5a..0000000
--- a/antora-ui-camel/src/js/06-search.js
+++ /dev/null
@@ -1,89 +0,0 @@
-window.addEventListener('load', () => {
- const client = window.algoliasearch('BH4D9OD16A', '16e3a9155a136e4962dc4c206f8278bd')
- const index = client.initIndex('apache_camel')
- const search = document.querySelector('#search')
- const container = search.parentNode
- const results = document.querySelector('#search_results')
-
- function debounce (fn, wait) {
- var timeout
- return function () {
- var context = this
- var args = arguments
- var later = () => {
- timeout = null
- fn.apply(context, args)
- }
- clearTimeout(timeout)
- timeout = setTimeout(later, wait)
- }
- }
-
- search.addEventListener('keyup', debounce((key) => {
- if (search.value.trim() === '') {
- container.className = 'navbar-search results-hidden'
- results.innerHTML = ''
- return
- }
- if (key.which === 27) {
- container.className = 'navbar-search results-hidden'
- results.innerHTML = ''
- return
- }
- index.search(search.value)
- .then((results) => {
- const hits = results.hits
- const data = hits.reduce((data, hit) => {
- const d = {}
- d.url = hit.url
- d.breadcrumbs = Object.values(hit.hierarchy).slice(1).filter((lvl) => lvl !== null).join(' » ')
- if (hit._snippetResult !== undefined) {
- d.snippet = hit._snippetResult.content.value
- } else {
- d.snippet = ''
- }
-
- const section = hit.hierarchy.lvl0
- data[section] = data[section] || []
- data[section].push(d)
-
- return data
- }, {})
-
- return data
- })
- .then((data) => {
- if (Object.entries(data).length === 0 && data.constructor === Object) {
- return `
- <header>Nothing Found</header>
- `
- } else {
- return `
- <dl>
- ${Object.keys(data).map((section) => `
- <dt>${section}</dt>
- ${data[section].map((hit) => `
- <a href="${hit.url}">
- <dd>
- <header class="result_header">${hit.breadcrumbs}</header>
- <summary class="result_summary">${hit.snippet}</summary>
- </dd>
- </a>
- `).join('')}
- `).join('')}
- </dl>
- `
- }
- })
- .then((markup) => {
- results.innerHTML = markup
- container.className = 'navbar-search'
- })
- }, 150))
- window.addEventListener('mouseup', debounce((element) => {
- if (element.target !== container && element.target.parentNode !== container) {
- container.className = 'navbar-search results-hidden'
- results.innerHTML = ''
- }
- }), 150)
-})
diff --git a/antora-ui-camel/src/js/vendor/algoliasearch.js b/antora-ui-camel/src/js/vendor/algoliasearch.js
deleted file mode 100644
index cf1b6c9..0000000
--- a/antora-ui-camel/src/js/vendor/algoliasearch.js
+++ /dev/null
@@ -1,4 +0,0 @@
-;(function () {
- var algoliasearch = require('algoliasearch')
- return algoliasearch()
-})()
diff --git a/antora-ui-camel/src/js/vendor/alogliasearch.bundle.js b/antora-ui-camel/src/js/vendor/alogliasearch.bundle.js
new file mode 100644
index 0000000..99cc411
--- /dev/null
+++ b/antora-ui-camel/src/js/vendor/alogliasearch.bundle.js
@@ -0,0 +1,95 @@
+;(function () {
+ 'use strict'
+
+ const algoliasearch = require('algoliasearch')
+
+ window.addEventListener('load', () => {
+ const client = algoliasearch('BH4D9OD16A', '16e3a9155a136e4962dc4c206f8278bd')
+ const index = client.initIndex('apache_camel')
+ const search = document.querySelector('#search')
+ const container = search.parentNode
+ const results = document.querySelector('#search_results')
+
+ function debounce (fn, wait) {
+ var timeout
+ return function () {
+ var context = this
+ var args = arguments
+ var later = () => {
+ timeout = null
+ fn.apply(context, args)
+ }
+ clearTimeout(timeout)
+ timeout = setTimeout(later, wait)
+ }
+ }
+
+ search.addEventListener('keyup', debounce((key) => {
+ if (search.value.trim() === '') {
+ container.className = 'navbar-search results-hidden'
+ results.innerHTML = ''
+ return
+ }
+ if (key.which === 27) {
+ container.className = 'navbar-search results-hidden'
+ results.innerHTML = ''
+ return
+ }
+ index.search(search.value)
+ .then((results) => {
+ const hits = results.hits
+ const data = hits.reduce((data, hit) => {
+ const d = {}
+ d.url = hit.url
+ d.breadcrumbs = Object.values(hit.hierarchy).slice(1).filter((lvl) => lvl !== null).join(' » ')
+ if (hit._snippetResult !== undefined) {
+ d.snippet = hit._snippetResult.content.value
+ } else {
+ d.snippet = ''
+ }
+
+ const section = hit.hierarchy.lvl0
+ data[section] = data[section] || []
+ data[section].push(d)
+
+ return data
+ }, {})
+
+ return data
+ })
+ .then((data) => {
+ if (Object.entries(data).length === 0 && data.constructor === Object) {
+ return `
+ <header>Nothing Found</header>
+ `
+ } else {
+ return `
+ <dl>
+ ${Object.keys(data).map((section) => `
+ <dt>${section}</dt>
+ ${data[section].map((hit) => `
+ <a href="${hit.url}">
+ <dd>
+ <header class="result_header">${hit.breadcrumbs}</header>
+ <summary class="result_summary">${hit.snippet}</summary>
+ </dd>
+ </a>
+ `).join('')}
+ `).join('')}
+ </dl>
+ `
+ }
+ })
+ .then((markup) => {
+ results.innerHTML = markup
+ container.className = 'navbar-search'
+ })
+ }, 150))
+ window.addEventListener('mouseup', debounce((element) => {
+ if (element.target !== container && element.target.parentNode !== container) {
+ container.className = 'navbar-search results-hidden'
+ results.innerHTML = ''
+ }
+ }), 150)
+ })
+})()
diff --git a/antora-ui-camel/src/partials/footer-scripts.hbs b/antora-ui-camel/src/partials/footer-scripts.hbs
index bf8ea5d..7a0eed2 100644
--- a/antora-ui-camel/src/partials/footer-scripts.hbs
+++ b/antora-ui-camel/src/partials/footer-scripts.hbs
@@ -1,6 +1,6 @@
+<script src="{{uiRootPath}}{{asset 'js/vendor/alogliasearch.js'}}"></script>
+<script src="{{uiRootPath}}{{asset 'js/site.js'}}"></script>
<script async src="{{uiRootPath}}{{asset 'js/vendor/highlight.js'}}"></script>
<script async src="{{uiRootPath}}{{asset 'js/vendor/svg4everybody.js'}}"></script>
-<script src="{{uiRootPath}}{{asset 'js/vendor/algoliasearch.js'}}"></script>
-<script src="{{uiRootPath}}{{asset 'js/site.js'}}"></script>
{{> seo-main}}
diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html
index 3e8f305..0b28390 100644
--- a/layouts/partials/footer.html
+++ b/layouts/partials/footer.html
@@ -38,10 +38,10 @@
</p>
</div>
</footer>
+ <script src="{{ path.Join "_" (index .Site.Data "rev-manifest" "js/vendor/alogliasearch.js") | relURL }}"></script>
+ <script src="{{ path.Join "_" (index .Site.Data "rev-manifest" "js/site.js") | relURL }}"></script>
<script async src="{{ path.Join "_" (index .Site.Data "rev-manifest" "js/vendor/highlight.js") | relURL }}"></script>
<script async src="{{ path.Join "_" (index .Site.Data "rev-manifest" "js/vendor/svg4everybody.js") | relURL }}"></script>
- <script src="{{ path.Join "_" (index .Site.Data "rev-manifest" "js/vendor/algoliasearch.js") | relURL }}"></script>
- <script src="{{ path.Join "_" (index .Site.Data "rev-manifest" "js/site.js") | relURL }}"></script>
{{ partial "seo/main" . }}
</body>