aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/html/mkdocs/js/search.js
diff options
context:
space:
mode:
authornodiscc <nodiscc@gmail.com>2017-01-26 18:52:54 +0100
committernodiscc <nodiscc@gmail.com>2017-06-18 00:19:49 +0200
commit53ed6d7d1e678d7486337ce67a2f17b30bac21ac (patch)
treef8bef0164a70bd03d2b9781951c01bdd018f1842 /doc/html/mkdocs/js/search.js
parentd5d22a6d07917865c44148ad76f43c65a929a890 (diff)
downloadShaarli-53ed6d7d1e678d7486337ce67a2f17b30bac21ac.tar.gz
Shaarli-53ed6d7d1e678d7486337ce67a2f17b30bac21ac.tar.zst
Shaarli-53ed6d7d1e678d7486337ce67a2f17b30bac21ac.zip
Generate HTML documentation using MkDocs (WIP)
MkDocs is a static site generator geared towards building project documentation. Documentation source files are written in Markdown, and configured with a single YAML file. * http://www.mkdocs.org/ * http://www.mkdocs.org/user-guide/configuration/ Ref. #312 * remove pandoc-generated HTML documentation * move markdown doc to doc/md/, * mkdocs.yml: * generate HTML doc in doc/html * add pages TOC/ordering * use index.md as index page * Makefile: remove execute permissions from generated files * Makefile: rewrite htmlpages GFM to markdown conversion using sed: awk expression aslo matched '][' which causes invalid output on complex links with images or code blocks * Add mkdocs.yml to .gitattributes, exclude this file from release archives * Makefile: rename: htmldoc -> doc_html target * run make doc: pull latest markdown documentation from wiki * run make htmlpages: update html documentation
Diffstat (limited to 'doc/html/mkdocs/js/search.js')
-rw-r--r--doc/html/mkdocs/js/search.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/doc/html/mkdocs/js/search.js b/doc/html/mkdocs/js/search.js
new file mode 100644
index 00000000..d5c86616
--- /dev/null
+++ b/doc/html/mkdocs/js/search.js
@@ -0,0 +1,88 @@
1require([
2 base_url + '/mkdocs/js/mustache.min.js',
3 base_url + '/mkdocs/js/lunr.min.js',
4 'text!search-results-template.mustache',
5 'text!../search_index.json',
6], function (Mustache, lunr, results_template, data) {
7 "use strict";
8
9 function getSearchTerm()
10 {
11 var sPageURL = window.location.search.substring(1);
12 var sURLVariables = sPageURL.split('&');
13 for (var i = 0; i < sURLVariables.length; i++)
14 {
15 var sParameterName = sURLVariables[i].split('=');
16 if (sParameterName[0] == 'q')
17 {
18 return decodeURIComponent(sParameterName[1].replace(/\+/g, '%20'));
19 }
20 }
21 }
22
23 var index = lunr(function () {
24 this.field('title', {boost: 10});
25 this.field('text');
26 this.ref('location');
27 });
28
29 data = JSON.parse(data);
30 var documents = {};
31
32 for (var i=0; i < data.docs.length; i++){
33 var doc = data.docs[i];
34 doc.location = base_url + doc.location;
35 index.add(doc);
36 documents[doc.location] = doc;
37 }
38
39 var search = function(){
40
41 var query = document.getElementById('mkdocs-search-query').value;
42 var search_results = document.getElementById("mkdocs-search-results");
43 while (search_results.firstChild) {
44 search_results.removeChild(search_results.firstChild);
45 }
46
47 if(query === ''){
48 return;
49 }
50
51 var results = index.search(query);
52
53 if (results.length > 0){
54 for (var i=0; i < results.length; i++){
55 var result = results[i];
56 doc = documents[result.ref];
57 doc.base_url = base_url;
58 doc.summary = doc.text.substring(0, 200);
59 var html = Mustache.to_html(results_template, doc);
60 search_results.insertAdjacentHTML('beforeend', html);
61 }
62 } else {
63 search_results.insertAdjacentHTML('beforeend', "<p>No results found</p>");
64 }
65
66 if(jQuery){
67 /*
68 * We currently only automatically hide bootstrap models. This
69 * requires jQuery to work.
70 */
71 jQuery('#mkdocs_search_modal a').click(function(){
72 jQuery('#mkdocs_search_modal').modal('hide');
73 });
74 }
75
76 };
77
78 var search_input = document.getElementById('mkdocs-search-query');
79
80 var term = getSearchTerm();
81 if (term){
82 search_input.value = term;
83 search();
84 }
85
86 search_input.addEventListener("keyup", search);
87
88});