Skip to content

Commit

Permalink
Docs Updates: CLI Tools / misc (#11691)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulOsinski authored Jan 31, 2025
1 parent d789823 commit bd2b3f1
Show file tree
Hide file tree
Showing 5 changed files with 984 additions and 220 deletions.
Binary file added docs/assets/images/epic_name_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 145 additions & 0 deletions docs/assets/js/flexsearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/*!
* FlexSearch for Bootstrap based Thulite sites
* Copyright 2021-2024 Thulite
* Licensed under the MIT License
* Based on https://github.com/frjo/hugo-theme-zen/blob/main/assets/js/search.js
*/

/* eslint-disable no-undef, guard-for-in */

/**
* @file
* A JavaScript file for flexsearch.
*/

// import * as FlexSearch from 'flexsearch';
import Index from 'flexsearch';

(function () {

'use strict';

// const index = new FlexSearch.Document({
const index = new Index.Document({
tokenize: 'forward',
document: {
id: 'id',
index: [
{
field: 'title'
},
{
field: 'tags'
},
{
field: {{ if site.Params.doks.indexSummary }}'summary'{{ else }}'content'{{ end }}
},
{
field: 'date',
tokenize: 'strict',
encode: false
}
],
store: ['title','summary','date','permalink']
}
});

function showResults(items, order) {
const template = document.querySelector('template').content;
const fragment = document.createDocumentFragment();

const results = document.querySelector('.search-results');
results.textContent = '';

const itemsLength = Object.keys(items).length;

// Show/hide "No recent searches" and "No search results" messages
if ((itemsLength === 0) && (query.value === '')) {
// Hide "No search results" message
document.querySelector('.search-no-results').classList.add('d-none');
// Show "No recent searches" message
document.querySelector('.search-no-recent').classList.remove('d-none');
} else if ((itemsLength === 0) && (query.value !== '')) {
// Hide "No recent searches" message
document.querySelector('.search-no-recent').classList.add('d-none');
// Show "No search results" message
const queryNoResults = document.querySelector('.query-no-results');
queryNoResults.innerText = query.value;
document.querySelector('.search-no-results').classList.remove('d-none');
} else {
// Hide both "No recent searches" and "No search results" messages
document.querySelector('.search-no-recent').classList.add('d-none');
document.querySelector('.search-no-results').classList.add('d-none');
}

order.forEach((id) => {
const item = items[id];
const result = template.cloneNode(true);
const a = result.querySelector('a');
const time = result.querySelector('time');
const content = result.querySelector('.content');
a.innerHTML = item.title;
a.href = item.permalink;
time.innerText = "";
content.innerHTML = item.summary;
fragment.appendChild(result);
});

results.appendChild(fragment);
}

function doSearch() {
const query = document.querySelector('.search-text').value.trim();
const limit = {{ .searchLimit }};
const results = index.search({
query: query,
enrich: true,
limit: limit,
});
const items = {};
const order = [];

results.forEach(function (result) {

result.result.forEach(function (r) {
if(!order.includes(r.id)) {
order.push(r.id);
}

items[r.id] = r.doc;
});
});

showResults(items, order);
}

function enableUI() {
const searchform = document.querySelector('.search-form');
searchform.addEventListener('submit', function (e) {
e.preventDefault();
doSearch();
});
searchform.addEventListener('input', function () {
doSearch();
});
document.querySelector('.search-loading').classList.add('d-none');
document.querySelector('.search-input').classList.remove('d-none');
document.querySelector('.search-text').focus();
}

function buildIndex() {
document.querySelector('.search-loading').classList.remove('d-none');
fetch("{{ site.LanguagePrefix }}/search-index.json")
.then(function (response) {
return response.json();
})
.then(function (data) {
data.forEach(function (item) {
index.add(item);
});
});
}

buildIndex();
enableUI();
})();
Loading

0 comments on commit bd2b3f1

Please sign in to comment.