Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/okkur/syna.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Grosser <development@stp-ip.net>2022-09-24 12:33:49 +0300
committerGitHub <noreply@github.com>2022-09-24 12:33:49 +0300
commit64304f6ecc50333391ee8d9f81eb70c0382eae57 (patch)
tree191fba0a7123fcb5363c929b931561a8f121e22e
parent7fcac1f8f5a49707409b79a28406e156afe04888 (diff)
parent624acabb227c947336371f80ed24c1638e73faf3 (diff)
Merge pull request #883 from xai/issues/882HEADmaster
Fix search for websites using subpaths in baseURL
-rw-r--r--assets/js/search.js2
-rw-r--r--assets/scripts/syna-search.js2
2 files changed, 2 insertions, 2 deletions
diff --git a/assets/js/search.js b/assets/js/search.js
index 8fa27ce7..c78dec35 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -48,7 +48,7 @@ class SynaSearch {
return callback(this.indexCache);
}
- $.ajax({ method: 'get', url: '/index.json' }).then((data) => {
+ $.ajax({ method: 'get', url: (window.location.origin + window.location.pathname).replace(/[\/]search[\/]$/, '') + 'index.json' }).then((data) => {
this.indexCache = data;
callback(data);
});
diff --git a/assets/scripts/syna-search.js b/assets/scripts/syna-search.js
index 6037fae1..2a0c93ae 100644
--- a/assets/scripts/syna-search.js
+++ b/assets/scripts/syna-search.js
@@ -118,7 +118,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) *
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
-eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var fuse_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fuse.js */ \"./node_modules/fuse.js/dist/fuse.esm.js\");\n/* harmony import */ var _helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers/jq-helpers */ \"./assets/js/helpers/jq-helpers.js\");\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\n\nvar SynaSearch = /*#__PURE__*/function () {\n function SynaSearch(_ref) {\n var _this = this;\n\n var queryParam = _ref.queryParam,\n searchInput = _ref.searchInput,\n resultsContainer = _ref.resultsContainer,\n template = _ref.template,\n noResults = _ref.noResults,\n empty = _ref.empty;\n\n _classCallCheck(this, SynaSearch);\n\n this.searchInput = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(searchInput);\n this.resultsContainer = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(resultsContainer);\n this.template = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(template);\n this.noResults = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(noResults);\n this.empty = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(empty);\n this.fuseOptions = {\n shouldSort: true,\n matchAllTokens: true,\n includeMatches: true,\n tokenize: true,\n threshold: 0.2,\n location: 0,\n distance: 100,\n maxPatternLength: 32,\n minMatchCharLength: 4,\n keys: [{\n name: 'title',\n weight: 0.8\n }, {\n name: 'contents',\n weight: 0.5\n }, {\n name: 'tags',\n weight: 0.3\n }, {\n name: 'categories',\n weight: 0.3\n }]\n };\n this.summaryInclude = 60;\n this.indexCache = null;\n var searchQuery = this.param(queryParam) || '';\n this.searchInput.val(searchQuery.trim());\n this.searchInput.on('input', function (e) {\n return _this.search(e.target.value.trim());\n });\n this.search(searchQuery);\n }\n\n _createClass(SynaSearch, [{\n key: \"getIndex\",\n value: function getIndex(callback) {\n var _this2 = this;\n\n if (this.indexCache) {\n return callback(this.indexCache);\n }\n\n _helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"].ajax({\n method: 'get',\n url: '/index.json'\n }).then(function (data) {\n _this2.indexCache = data;\n callback(data);\n });\n }\n }, {\n key: \"search\",\n value: function search(query) {\n var _this3 = this;\n\n if (!query) {\n return this.resultsContainer.html(window.syna.api.renderTemplate(this.empty.html(), {}));\n }\n\n this.getIndex(function (data) {\n var pages = data;\n var fuse = new fuse_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"](pages, _this3.fuseOptions);\n var matches = fuse.search(query);\n\n if (matches.length > 0) {\n _this3.populateResults(matches, query);\n } else {\n _this3.resultsContainer.html(window.syna.api.renderTemplate(_this3.noResults.html(), {}));\n }\n });\n }\n }, {\n key: \"populateResults\",\n value: function populateResults(result, query) {\n var _this4 = this;\n\n var finalHTML = '';\n result.forEach(function (value, key) {\n var contents = value.contents || value.item.contents;\n if (!contents) return;\n var snippet = '';\n var snippetHighlights = [];\n\n if (_this4.fuseOptions.tokenize) {\n snippetHighlights.push(query);\n } else {\n value.matches.forEach(function (mvalue) {\n if (mvalue.key === 'tags' || mvalue.key === 'categories') {\n snippetHighlights.push(mvalue.value);\n } else if (mvalue.key === 'contents') {\n var start = mvalue.indices[0][0] - _this4.summaryInclude > 0 ? mvalue.indices[0][0] - _this4.summaryInclude : 0;\n var end = mvalue.indices[0][1] + _this4.summaryInclude < contents.length ? mvalue.indices[0][1] + _this4.summaryInclude : contents.length;\n snippet += contents.substring(start, end);\n snippetHighlights.push(mvalue.value.substring(mvalue.indices[0][0], mvalue.indices[0][1] - mvalue.indices[0][0] + 1));\n }\n });\n }\n\n if (snippet.length < 1) {\n snippet += contents.substring(0, _this4.summaryInclude * 2);\n } //pull template from hugo templarte definition\n\n\n var templateDefinition = _this4.template.html(); //replace values\n\n\n var output = window.syna.api.renderTemplate(templateDefinition, {\n key: key,\n title: _this4.highlight(snippetHighlights, value.item.title),\n link: value.item.permalink,\n tags: value.item.tags,\n categories: value.item.categories,\n snippet: _this4.highlight(snippetHighlights, snippet)\n });\n finalHTML += output;\n });\n this.resultsContainer.html(finalHTML);\n }\n }, {\n key: \"highlight\",\n value: function highlight(highlights, text) {\n return highlights.reduce(function (tmp, snipvalue) {\n return tmp.replace(new RegExp(snipvalue, 'im'), \"<mark>\".concat(snipvalue, \"</mark>\"));\n }, text);\n }\n }, {\n key: \"param\",\n value: function param(name) {\n return decodeURIComponent((location.search.split(name + '=')[1] || '').split('&')[0]).replace(/\\+/g, ' ');\n }\n }]);\n\n return SynaSearch;\n}();\n\nwindow.syna.api.toArray('search').forEach(function (search) {\n new SynaSearch({\n queryParam: 's',\n searchInput: search.searchInput,\n resultsContainer: search.resultsContainer,\n template: search.template,\n noResults: search.noResults,\n empty: search.empty\n });\n});\n\n//# sourceURL=webpack:///./assets/js/search.js?");
+eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var fuse_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! fuse.js */ \"./node_modules/fuse.js/dist/fuse.esm.js\");\n/* harmony import */ var _helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./helpers/jq-helpers */ \"./assets/js/helpers/jq-helpers.js\");\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\n\n\n\nvar SynaSearch = /*#__PURE__*/function () {\n function SynaSearch(_ref) {\n var _this = this;\n\n var queryParam = _ref.queryParam,\n searchInput = _ref.searchInput,\n resultsContainer = _ref.resultsContainer,\n template = _ref.template,\n noResults = _ref.noResults,\n empty = _ref.empty;\n\n _classCallCheck(this, SynaSearch);\n\n this.searchInput = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(searchInput);\n this.resultsContainer = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(resultsContainer);\n this.template = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(template);\n this.noResults = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(noResults);\n this.empty = Object(_helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"])(empty);\n this.fuseOptions = {\n shouldSort: true,\n matchAllTokens: true,\n includeMatches: true,\n tokenize: true,\n threshold: 0.2,\n location: 0,\n distance: 100,\n maxPatternLength: 32,\n minMatchCharLength: 4,\n keys: [{\n name: 'title',\n weight: 0.8\n }, {\n name: 'contents',\n weight: 0.5\n }, {\n name: 'tags',\n weight: 0.3\n }, {\n name: 'categories',\n weight: 0.3\n }]\n };\n this.summaryInclude = 60;\n this.indexCache = null;\n var searchQuery = this.param(queryParam) || '';\n this.searchInput.val(searchQuery.trim());\n this.searchInput.on('input', function (e) {\n return _this.search(e.target.value.trim());\n });\n this.search(searchQuery);\n }\n\n _createClass(SynaSearch, [{\n key: \"getIndex\",\n value: function getIndex(callback) {\n var _this2 = this;\n\n if (this.indexCache) {\n return callback(this.indexCache);\n }\n\n _helpers_jq_helpers__WEBPACK_IMPORTED_MODULE_1__[\"default\"].ajax({\n method: 'get',\n url: (window.location.origin + window.location.pathname).replace(/[\\/]search[\\/]$/, '') + 'index.json'\n }).then(function (data) {\n _this2.indexCache = data;\n callback(data);\n });\n }\n }, {\n key: \"search\",\n value: function search(query) {\n var _this3 = this;\n\n if (!query) {\n return this.resultsContainer.html(window.syna.api.renderTemplate(this.empty.html(), {}));\n }\n\n this.getIndex(function (data) {\n var pages = data;\n var fuse = new fuse_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"](pages, _this3.fuseOptions);\n var matches = fuse.search(query);\n\n if (matches.length > 0) {\n _this3.populateResults(matches, query);\n } else {\n _this3.resultsContainer.html(window.syna.api.renderTemplate(_this3.noResults.html(), {}));\n }\n });\n }\n }, {\n key: \"populateResults\",\n value: function populateResults(result, query) {\n var _this4 = this;\n\n var finalHTML = '';\n result.forEach(function (value, key) {\n var contents = value.contents || value.item.contents;\n if (!contents) return;\n var snippet = '';\n var snippetHighlights = [];\n\n if (_this4.fuseOptions.tokenize) {\n snippetHighlights.push(query);\n } else {\n value.matches.forEach(function (mvalue) {\n if (mvalue.key === 'tags' || mvalue.key === 'categories') {\n snippetHighlights.push(mvalue.value);\n } else if (mvalue.key === 'contents') {\n var start = mvalue.indices[0][0] - _this4.summaryInclude > 0 ? mvalue.indices[0][0] - _this4.summaryInclude : 0;\n var end = mvalue.indices[0][1] + _this4.summaryInclude < contents.length ? mvalue.indices[0][1] + _this4.summaryInclude : contents.length;\n snippet += contents.substring(start, end);\n snippetHighlights.push(mvalue.value.substring(mvalue.indices[0][0], mvalue.indices[0][1] - mvalue.indices[0][0] + 1));\n }\n });\n }\n\n if (snippet.length < 1) {\n snippet += contents.substring(0, _this4.summaryInclude * 2);\n } //pull template from hugo templarte definition\n\n\n var templateDefinition = _this4.template.html(); //replace values\n\n\n var output = window.syna.api.renderTemplate(templateDefinition, {\n key: key,\n title: _this4.highlight(snippetHighlights, value.item.title),\n link: value.item.permalink,\n tags: value.item.tags,\n categories: value.item.categories,\n snippet: _this4.highlight(snippetHighlights, snippet)\n });\n finalHTML += output;\n });\n this.resultsContainer.html(finalHTML);\n }\n }, {\n key: \"highlight\",\n value: function highlight(highlights, text) {\n return highlights.reduce(function (tmp, snipvalue) {\n return tmp.replace(new RegExp(snipvalue, 'im'), \"<mark>\".concat(snipvalue, \"</mark>\"));\n }, text);\n }\n }, {\n key: \"param\",\n value: function param(name) {\n return decodeURIComponent((location.search.split(name + '=')[1] || '').split('&')[0]).replace(/\\+/g, ' ');\n }\n }]);\n\n return SynaSearch;\n}();\n\nwindow.syna.api.toArray('search').forEach(function (search) {\n new SynaSearch({\n queryParam: 's',\n searchInput: search.searchInput,\n resultsContainer: search.resultsContainer,\n template: search.template,\n noResults: search.noResults,\n empty: search.empty\n });\n});\n\n//# sourceURL=webpack:///./assets/js/search.js?");
/***/ }),