Commit f5d1bae8 authored by Henk Verlinde's avatar Henk Verlinde
Browse files

Merge branch 'master' of github.com:h-enk/doks

parents 42e6cd13 1b90fe74
Loading
Loading
Loading
Loading
+34 −28
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ Source:
        {{ else -}}
          description: {{ .Summary | plainify | jsonify }},
        {{ end -}}
        content: {{ .Content | jsonify }}
        content: {{ .Plain | jsonify }}
      })
      {{ if ne (add $index 1) $len -}}
        .add(
@@ -117,47 +117,53 @@ Source:
  ;

  search.addEventListener('input', show_results, true);
  suggestions.addEventListener('click', accept_suggestion, true);

  function show_results(){
    const maxResult = 5;
    var searchQuery = this.value;
    var results = index.search(searchQuery, {limit: maxResult, enrich: true});

    var value = this.value;
    var results = index.search(value, {limit: maxResult, enrich: true});
    // flatten results since index.search() returns results for each indexed field
    const flatResults = new Map(); // keyed by href to dedupe results
    for (const result of results.flatMap(r => r.result)) {
      if (flatResults.has(result.doc.href)) continue;
      flatResults.set(result.doc.href, result.doc);
    }

    suggestions.classList.remove('d-none');
    suggestions.innerHTML = "";
    suggestions.classList.remove('d-none');

    //flatSearch now returns results for each index field. create a single list
    const flatResults = {}; //keyed by href to dedupe results
    for (const result of results.flatMap(r => r.result)) {
      flatResults[result.doc.href] = result.doc;
    // inform user that no results were found
    if (flatResults.size === 0 && searchQuery) {
      const noResultsMessage = document.createElement('div')
      noResultsMessage.innerHTML = `No results for "<strong>${searchQuery}</strong>"`
      noResultsMessage.classList.add("suggestion__no-results");
      suggestions.appendChild(noResultsMessage);
      return;
    }

    //construct a list of suggestions list
    for(const href in flatResults) {
        const doc = flatResults[href];

    // construct a list of suggestions
    for(const [href, doc] of flatResults) {
        const entry = document.createElement('div');
        entry.innerHTML = '<a href><span></span><span></span></a>';
        suggestions.appendChild(entry);

        entry.querySelector('a').href = href;
        entry.querySelector('span:first-child').textContent = doc.title;
        entry.querySelector('span:nth-child(2)').textContent = doc.description;
        const a = document.createElement('a');
        a.href = href;
        entry.appendChild(a);

        suggestions.appendChild(entry);
        if(suggestions.childElementCount == maxResult) break;
    }
  }
        const title = document.createElement('span');
        title.textContent = doc.title;
        title.classList.add("suggestion__title");
        a.appendChild(title);

  function accept_suggestion(){
        const description = document.createElement('span');
        description.textContent = doc.description;
        description.classList.add("suggestion__description");
        a.appendChild(description);

      while(suggestions.lastChild){
        suggestions.appendChild(entry);

          suggestions.removeChild(suggestions.lastChild);
        if(suggestions.childElementCount == maxResult) break;
    }

      return false;
  }

}());
+11 −6
Original line number Diff line number Diff line
@@ -10,11 +10,15 @@
  z-index: $zindex-dropdown;
}

#suggestions a,
.suggestion__no-results {
  padding: 0.75rem;
  margin: 0 0.5rem;
}

#suggestions a {
  display: block;
  text-decoration: none;
  padding: 0.75rem;
  margin: 0 0.5rem;
}

#suggestions a:focus {
@@ -43,12 +47,13 @@
  font-size: $font-size-base;
}

#suggestions span:first-child {
.suggestion__title {
  font-weight: $headings-font-weight;
  color: $black;
}

#suggestions span:nth-child(2) {
.suggestion__description,
.suggestion__no-results {
  color: $gray-700;
}

@@ -61,7 +66,7 @@
    display: flex;
  }

  #suggestions span:first-child {
  .suggestion__title {
    width: 9rem;
    padding-right: 1rem;
    border-right: 1px solid $gray-200;
@@ -69,7 +74,7 @@
    text-align: right;
  }

  #suggestions span:nth-child(2) {
  .suggestion__description {
    width: 19rem;
    padding-left: 1rem;
  }

layouts/_default/_markup/.gitkeep

deleted100644 → 0
+0 −0

Empty file deleted.

+1 −0
Original line number Diff line number Diff line
<h{{ .Level }} id="{{ .Anchor | safeURL }}">{{ .Text | safeHTML }} <a href="#{{ .Anchor | safeURL }}" class="anchor" aria-hidden="true">#</a></h{{ .Level }}>
+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
				{{ partial "sidebar/docs-toc.html" . }}
			</nav>
			{{ end -}}
			{{ partial "main/headline-hash.html" .Content }}
			{{ .Content }}
			{{ if .Site.Params.editPage -}}
				{{ partial "main/edit-page.html" . }}
			{{ end -}}
Loading