`__,
- author description and social media (including Github!) links,
- links to download the source code,
- links to individual files, both in their raw form or in HTML with
diff --git a/ford/output.py b/ford/output.py
index 13c0ba21..e4529d5b 100644
--- a/ford/output.py
+++ b/ford/output.py
@@ -108,6 +108,8 @@ def relative_url(entity: Union[FortranBase, str], page_url: pathlib.Path) -> str
USER_WRITABLE_ONLY = 0o755
+def create_node_wrapper(page_data, node_gen = None):
+ return node_gen.create_node(page_data[0], page_data[1], page_data[2])
class Documentation:
"""
@@ -237,20 +239,25 @@ def __init__(self, settings: ProjectSettings, proj_docs: str, project, pagetree)
if settings.search:
url = "" if settings.relative else settings.project_url
- self.tipue = ford.tipue_search.Tipue_Search_JSON_Generator(
- settings.output_dir, url
- )
- self.tipue.create_node(
+ node_generator = ford.tipue_search.Search_Soup_Parser(url)
+ nodes = [node_generator.create_node(
self.index.html, "index.html", EntitySettings(category="home")
+ )]
+
+ tasks = self.docs + self.pagetree
+ from functools import partial
+ create_node_wrapper_partial = partial(create_node_wrapper,
+ node_gen = node_generator)
+ from tqdm.contrib.concurrent import process_map as parallel_map
+ extra_nodes = parallel_map(create_node_wrapper_partial,
+ [(x.html, x.loc, x.meta) for x in tasks],
+ desc = "Creating search index",
+ chunksize = 1,
+ )
+ nodes.extend(extra_nodes)
+ self.tipue = ford.tipue_search.Search_JSON_Generator(
+ settings.output_dir, nodes
)
- jobs = len(self.docs) + len(self.pagetree)
- for page in (
- bar := ProgressBar(
- "Creating search index", chain(self.docs, self.pagetree), total=jobs
- )
- ):
- bar.set_current(page.loc)
- self.tipue.create_node(page.html, page.loc, page.meta)
def writeout(self) -> None:
out_dir: pathlib.Path = self.data["output_dir"]
@@ -286,7 +293,7 @@ def writeout(self) -> None:
if self.data["graph"]:
self.graphs.output_graphs(self.njobs)
if self.data["search"]:
- copytree(loc / "tipuesearch", out_dir / "tipuesearch")
+ copytree(loc / "search", out_dir / "search")
self.tipue.print_output()
try:
diff --git a/ford/search/load_search.js b/ford/search/load_search.js
new file mode 100644
index 00000000..3b6e61c3
--- /dev/null
+++ b/ford/search/load_search.js
@@ -0,0 +1,62 @@
+ var items = tipuesearch['pages'];
+ var documents = tipuesearch["pages"]
+ var counter = 0
+
+ for (item in documents){
+ documents[item]['id'] = counter;
+ counter = counter +1;
+ }
+
+ var idx = lunr(function () {
+ this.ref('id')
+ this.field('title')
+ this.field('url')
+ this.field('text', { boost: 10 })
+ this.field('tags')
+
+ items.forEach(function (doc) {
+ this.add(doc)
+ }, this)
+})
+
+function lunr_search(term) {
+ document.getElementById('lunrsearchresults').innerHTML = '';
+ if(term) {
+ document.getElementById('lunrsearchresults').innerHTML = "Search results for '" + term + "'
" + document.getElementById('lunrsearchresults').innerHTML;
+ //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]['text'].substring(0,160)+'...';
+ document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML + "" + title + " "+ body +" "+ url +" ";
+ }
+ } else {
+ document.querySelectorAll('#lunrsearchresults ul')[0].innerHTML = "No results found... ";
+ }
+ }
+ return false;
+}
+
+function getQueryVariable(variable) {
+ var query = window.location.search.substring(1);
+ var vars = query.split('&');
+
+ for (var i = 0; i < vars.length; i++) {
+ var pair = vars[i].split('=');
+
+ if (pair[0] === variable) {
+ return decodeURIComponent(pair[1].replace(/\+/g, '%20'));
+ }
+ }
+}
+
+var searchTerm = getQueryVariable('q');
+if (searchTerm) {
+ lunr_search(searchTerm)
+}
diff --git a/ford/templates/base.html b/ford/templates/base.html
index 012bd830..6e14a542 100644
--- a/ford/templates/base.html
+++ b/ford/templates/base.html
@@ -19,14 +19,9 @@
- {% if search|lower == 'true' %}
-
- {% endif %}
{% if css %}
{% endif %}
-
-
@@ -171,12 +166,5 @@
{% endif %}
-
- {% if search|lower == 'true' %}
-
-
-
- {% endif %}
-