2020-12-18 15:00:51 -04:00
|
|
|
{% extends "!search.html" %}
|
|
|
|
{% block extrahead %}
|
|
|
|
{{ super() }}
|
2023-07-16 04:26:26 -03:00
|
|
|
<meta name="robots" content="noindex">
|
2020-12-18 15:00:51 -04:00
|
|
|
<script type="text/javascript">
|
2023-07-16 04:26:26 -03:00
|
|
|
const GLOSSARY_PAGE = 'glossary.html';
|
2020-12-18 15:00:51 -04:00
|
|
|
|
2023-07-16 04:26:26 -03:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
fetch('_static/glossary.json')
|
|
|
|
.then(function(response) {
|
|
|
|
if (response.ok) {
|
|
|
|
return response.json();
|
|
|
|
} else {
|
|
|
|
throw new Error('Failed to fetch glossary.json');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(function(glossary) {
|
|
|
|
const RESULT_TEMPLATE = '<div style="display: none" class="admonition seealso" id="glossary-result">' +
|
2020-12-18 15:00:51 -04:00
|
|
|
' <p class="topic-title">' +
|
|
|
|
' <a class="glossary-title" href="#"></a>' +
|
|
|
|
' </p>' +
|
|
|
|
' <div class="glossary-body"></div>' +
|
|
|
|
'</div>';
|
2023-07-16 04:26:26 -03:00
|
|
|
let searchResults = document.getElementById('search-results');
|
|
|
|
searchResults.insertAdjacentHTML('afterbegin', RESULT_TEMPLATE);
|
2020-12-18 15:00:51 -04:00
|
|
|
|
2023-07-16 04:26:26 -03:00
|
|
|
const params = new URLSearchParams(document.location.search).get("q");
|
|
|
|
if (params) {
|
|
|
|
const searchParam = params.toLowerCase();
|
|
|
|
const glossaryItem = glossary[searchParam];
|
|
|
|
if (glossaryItem) {
|
|
|
|
let resultDiv = document.getElementById('glossary-result');
|
2021-08-09 15:32:54 -03:00
|
|
|
|
2023-07-16 04:26:26 -03:00
|
|
|
// set up the title text with a link to the glossary page
|
|
|
|
let glossaryTitle = resultDiv.querySelector('.glossary-title');
|
|
|
|
glossaryTitle.textContent = 'Glossary: ' + glossaryItem.title;
|
|
|
|
const linkTarget = searchParam.replace(/ /g, '-');
|
|
|
|
glossaryTitle.href = GLOSSARY_PAGE + '#term-' + linkTarget;
|
2020-12-18 15:00:51 -04:00
|
|
|
|
2023-07-16 04:26:26 -03:00
|
|
|
// rewrite any anchor links (to other glossary terms)
|
|
|
|
// to have a full reference to the glossary page
|
|
|
|
let body = document.createElement('div');
|
|
|
|
body.innerHTML = glossaryItem.body;
|
|
|
|
const anchorLinks = body.querySelectorAll('a[href^="#"]');
|
|
|
|
anchorLinks.forEach(function(link) {
|
|
|
|
const currentUrl = link.getAttribute('href');
|
|
|
|
link.href = GLOSSARY_PAGE + currentUrl;
|
|
|
|
});
|
|
|
|
resultDiv.querySelector('.glossary-body').appendChild(body);
|
2020-12-18 15:00:51 -04:00
|
|
|
|
2023-07-16 04:26:26 -03:00
|
|
|
resultDiv.style.display = '';
|
|
|
|
} else {
|
|
|
|
document.getElementById('glossary-result').style.display = 'none';
|
2020-12-18 15:00:51 -04:00
|
|
|
}
|
2023-07-16 04:26:26 -03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function(error) {
|
|
|
|
console.error(error);
|
2020-12-18 15:00:51 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
2023-07-16 04:26:26 -03:00
|
|
|
{% endblock %}
|