go-micro.dev/v5@v5.12.0/internal/website/docs/search.md (about)

     1  ---
     2  layout: default
     3  ---
     4  
     5  # Search Documentation
     6  
     7  Type below to search page titles and content.
     8  
     9  <input id="gm-search" type="text" placeholder="Search docs..." style="width:100%; padding:.6rem .75rem; border:1px solid #d0d7de; border-radius:6px; margin: .5rem 0 1.25rem;" />
    10  <div id="gm-results"></div>
    11  
    12  <script src="https://cdn.jsdelivr.net/npm/fuse.js@6.6.2"></script>
    13  <script>
    14  (function(){
    15    const pages = [
    16      {% assign docs = site.pages | where_exp: "p", "p.url contains '/docs/'" %}
    17      {% for p in docs %}
    18        {
    19          url: '{{ p.url }}',
    20          title: {{ p.title | default: p.url | jsonify }},
    21          content: {{ p.content | strip_html | replace: '\n',' ' | truncate: 400 | jsonify }}
    22        }{% unless forloop.last %},{% endunless %}
    23      {% endfor %}
    24    ];
    25    const fuse = new Fuse(pages, { keys: ['title','content'], threshold: 0.4 });
    26    const input = document.getElementById('gm-search');
    27    const out = document.getElementById('gm-results');
    28    input.addEventListener('input', function(){
    29      const q = this.value.trim();
    30      if(!q){ out.innerHTML=''; return; }
    31      const results = fuse.search(q, { limit: 12 });
    32      out.innerHTML = '<ul style="list-style:none; padding:0; margin:0;">' +
    33        results.map(r => '<li style="margin:.6rem 0;">'+
    34          '<a href="'+r.item.url+'" style="font-weight:600">'+r.item.title+'</a><br />'+
    35          '<span style="font-size:.75rem; color:#555;">'+(r.item.content.substring(0,160))+'...</span>'+
    36        '</li>').join('') + '</ul>';
    37    });
    38  })();
    39  </script>