1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-09 07:17:31 -05:00
notes/docs/search.md

77 lines
2.1 KiB
Markdown
Raw Normal View History

2017-04-08 18:51:14 -04:00
---
layout: default
title: Search
2018-11-16 11:47:14 -05:00
nav_order: 7
2017-04-08 18:51:14 -04:00
---
# Search
2019-01-14 14:18:09 -05:00
{: .no_toc }
2018-12-16 14:47:41 -05:00
## Table of contents
{: .no_toc .text-delta }
1. TOC
{:toc}
---
2017-04-08 18:51:14 -04:00
Just the docs uses [lunr.js](http://lunrjs.com) to add a client-side search interface powered by a JSON index that Jekyll generates. All search results are shown in an auto-complete style interface (there is no search results page). By default, all generated html pages are indexed using the following data points:
- Page title
- Page content
- Page URL
2018-11-16 11:47:30 -05:00
## Set up search
2018-12-16 14:47:41 -05:00
### Generate search index
2017-11-08 11:23:05 -05:00
2019-01-14 14:18:09 -05:00
Before you can use search, you must initialize the feature by running this `rake` command that comes with `just-the-docs`:
2017-11-08 11:23:05 -05:00
```bash
$ bundle exec just-the-docs rake search:init
```
2019-01-14 14:18:09 -05:00
This command creates the `search-data.json` file that Jekyll uses to create your search index. Alternatively, you can create the file manually in the `assets/js/` directory of your Jekyll site with this content:
2017-11-08 11:23:05 -05:00
```{% raw %}
---
---
{
{% for page in site.html_pages %}"{{ forloop.index0 }}": {
"id": "{{ forloop.index0 }}",
"title": "{{ page.title | xml_escape }}",
"content": "{{ page.content | markdownify | strip_html | xml_escape | remove: 'Table of contents' | remove: page.title | strip_newlines | replace: '\', ' '}}",
"url": "{{ page.url | absolute_url | xml_escape }}",
"relUrl": "{{ page.url | xml_escape }}"
2017-11-08 11:23:05 -05:00
}{% if forloop.last %}{% else %},
{% endif %}{% endfor %}
}{% endraw %}
```
2018-10-24 14:06:41 -04:00
_Note: If you don't run this rake command or create this file manually, search will not work (or it will use the search index data from this docs site, not your site's content)._
2018-11-16 11:47:30 -05:00
2018-12-16 14:47:41 -05:00
### Enable search in configuration
2018-11-16 11:47:30 -05:00
In your site's `_config.yml` enable search:
```yml
# Enable or disable the site search
search_enabled: true
```
2018-12-16 14:47:41 -05:00
## Hiding pages from search
Sometimes you might have a page that you don't want indexed in the search and you don't want it to show up in search results, e.g, a 404 page. To exclude a page from search, add the `search_exclude: true` parameter to the page's YAML front matter:
#### Example
{: .no_toc }
2019-01-14 14:18:09 -05:00
2018-12-16 14:47:41 -05:00
```yaml
---
layout: default
title: Page not found
nav_exclude: true
search_exclude: true
---
```