зеркало из https://github.com/github/mlops.git
102 строки
5.3 KiB
HTML
102 строки
5.3 KiB
HTML
<script src="/js/lunr.js"></script>
|
|
|
|
<script>
|
|
{% assign counter = 0 %}
|
|
var documents = [{% for page in site.pages %}{% if page.url contains '.xml' or page.url contains 'assets' %}{% else %}{
|
|
"id": {{ counter }},
|
|
"url": "{{ site.url }}{{ page.url }}",
|
|
"title": "{{ page.title }}",
|
|
"body": "{{ page.content | markdownify | replace: '.', '. ' | replace: '</h2>', ': ' | replace: '</h3>', ': ' | replace: '</h4>', ': ' | replace: '</p>', ' ' | strip_html | strip_newlines | replace: ' ', ' ' | replace: '"', ' ' }}"{% assign counter = counter | plus: 1 %}
|
|
}, {% endif %}{% endfor %}
|
|
{% for page in site.without-plugin %}{
|
|
"id": {{ counter }},
|
|
"url": "{{ site.url }}{{ page.url }}",
|
|
"title": "{{ page.title }}",
|
|
"body": "{{ page.content | markdownify | replace: '.', '. ' | replace: '</h2>', ': ' | replace: '</h3>', ': ' | replace: '</h4>', ': ' | replace: '</p>', ' ' | strip_html | strip_newlines | replace: ' ', ' ' | replace: '"', ' ' }}"{% assign counter = counter | plus: 1 %}
|
|
}, {% endfor %}
|
|
{% for page in site.html_pages %}{
|
|
"id": {{ counter }},
|
|
"url": "{{ site.url }}{{ page.url }}",
|
|
"title": "{{ page.title }}",
|
|
"body": "{{ page.content | markdownify | replace: '.', '. ' | replace: '</h2>', ': ' | replace: '</h3>', ': ' | replace: '</h4>', ': ' | replace: '</p>', ' ' | strip_html | strip_newlines | replace: ' ', ' ' | replace: '"', ' ' }}"{% assign counter = counter | plus: 1 %}
|
|
}, {% endfor %}
|
|
{% for page in site.team %}{
|
|
"id": {{ counter }},
|
|
"url": "{{ site.url }}{{ page.url }}",
|
|
"title": "{{ page.title }}",
|
|
"body": "{{ page.content | markdownify | replace: '.', '. ' | replace: '</h2>', ': ' | replace: '</h3>', ': ' | replace: '</h4>', ': ' | replace: '</p>', ' ' | strip_html | strip_newlines | replace: ' ', ' ' | replace: '"', ' ' }}"{% assign counter = counter | plus: 1 %}
|
|
}, {% endfor %}
|
|
{% for page in site.docs %}{
|
|
"id": {{ counter }},
|
|
"url": "{{ site.url }}{{ page.url }}",
|
|
"title": "{{ page.title }}",
|
|
"body": "{{ page.content | markdownify | replace: '.', '. ' | replace: '</h2>', ': ' | replace: '</h3>', ': ' | replace: '</h4>', ': ' | replace: '</p>', ' ' | strip_html | strip_newlines | replace: ' ', ' ' | replace: '"', ' ' }}"{% assign counter = counter | plus: 1 %}
|
|
}, {% endfor %}
|
|
{% for page in site.posts %}{
|
|
"id": {{ counter }},
|
|
"url": "{{ site.url }}{{ page.url }}",
|
|
"title": "{{ page.title }}",
|
|
"body": "{{ page.date | date: "%Y/%m/%d" }} - {{ page.content | markdownify | replace: '.', '. ' | replace: '</h2>', ': ' | replace: '</h3>', ': ' | replace: '</h4>', ': ' | replace: '</p>', ' ' | strip_html | strip_newlines | replace: ' ', ' ' | replace: '"', ' ' }}"{% assign counter = counter | plus: 1 %}
|
|
}{% if forloop.last %}{% else %}, {% endif %}{% endfor %}];
|
|
|
|
var idx = lunr(function () {
|
|
this.ref('id')
|
|
this.field('title')
|
|
this.field('body')
|
|
|
|
documents.forEach(function (doc) {
|
|
this.add(doc)
|
|
}, this)
|
|
});
|
|
function lunr_search(term) {
|
|
document.getElementById('lunrsearchresults').innerHTML = '<ul></ul>';
|
|
if(term) {
|
|
document.getElementById('lunrsearchresults').innerHTML = "<h3 class='search_title'>Search results for '" + term + "'</h3>" +
|
|
"<div id='search_closer' onclick='search_close()'>\
|
|
<img src='/assets/images/times.png' alt='closer'>\
|
|
</div>"
|
|
+ document.getElementById('lunrsearchresults').innerHTML;
|
|
/* document.getElemenstById('lunrsearchresults').element.classList.remove("hidden"); */
|
|
$('#lunrsearchresults').removeClass("hidden");
|
|
//put results on the screen.
|
|
var results = idx.search(term);
|
|
if(results.length>0){
|
|
//console.log(idx.search(term));
|
|
//if results
|
|
for (var i = 0; i < results.length; i++) {
|
|
// more statements
|
|
var ref = results[i]['ref'];
|
|
var url = documents[ref]['url'];
|
|
var title = documents[ref]['title'];
|
|
var body = documents[ref]['body'].substring(0,160)+'...';
|
|
document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML +
|
|
"<li class='lunrsearchresult'>\
|
|
<a href='" + url + "'>\
|
|
<div class='page_title'>\
|
|
<h3 class='title'>" + title + "</h3>\
|
|
<span class='url'>"+ url +"</span>\
|
|
</div>\
|
|
<span class='body'>"+ body +"</span>\
|
|
</a>\
|
|
</li>";
|
|
}
|
|
} else {
|
|
document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = "<li class='lunrsearchresult'>No results found...</li>";
|
|
}
|
|
|
|
}
|
|
return false;
|
|
}
|
|
function search_close() {
|
|
$('#lunrsearchresults').empty().addClass("hidden");
|
|
/* document.getElementById('lunrsearchresults').element.classList.add("hidden"); */
|
|
};
|
|
</script>
|
|
|
|
<form onSubmit="return lunr_search(document.getElementById('lunrsearch').value);">
|
|
<h3><input type="text" class="form-control" id="lunrsearch" name="q" maxlength="255" value="" placeholder="Search" /></h3>
|
|
</form>
|
|
<div id="lunrsearchresults" class="lunrsearchresults hidden">
|
|
<ul></ul>
|
|
</div>
|