From eb0a6c328faae05d2cdedd0124bb19671f4d6468 Mon Sep 17 00:00:00 2001
From: Patrick Marsceill <patrick.marsceill@gmail.com>
Date: Sun, 16 Dec 2018 14:47:41 -0500
Subject: [PATCH] Allow pages to be excluded from search

---
 assets/js/search-data.json |  6 +++---
 docs/search.md             | 28 ++++++++++++++++++++++++++--
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/assets/js/search-data.json b/assets/js/search-data.json
index 50a4b9f4..1eca96c1 100644
--- a/assets/js/search-data.json
+++ b/assets/js/search-data.json
@@ -1,12 +1,12 @@
 ---
 ---
 {
-  {% for page in site.html_pages %}"{{ forloop.index0 }}": {
+  {% for page in site.html_pages %}{% if page.exclude_search != true %}"{{ forloop.index0 }}": {
     "id": "{{ forloop.index0 }}",
     "title": "{{ page.title | xml_escape }}",
-    "content": "{{ page.content | markdownify | strip_html | xml_escape | remove: 'Table of contents' | strip_newlines | replace: '\', ' ' }}",
+    "content": "{{ page.content | markdownify | strip_html | json_escape | xml_escape | remove: 'Table of contents' | strip_newlines | replace: '\', ' ' | replace: '```', '' | replace: '    ', ' ' }}",
     "url": "{{ page.url | absolute_url | xml_escape }}",
     "relUrl": "{{ page.url | xml_escape }}"
-  }{% if forloop.last %}{% else %},
+  }{% if forloop.last %}{% else %},{% endif %}
   {% endif %}{% endfor %}
 }
diff --git a/docs/search.md b/docs/search.md
index 0c9543fd..e1b18a45 100644
--- a/docs/search.md
+++ b/docs/search.md
@@ -5,6 +5,15 @@ nav_order: 7
 ---
 
 # Search
+{:.no_toc}
+
+## Table of contents
+{: .no_toc .text-delta }
+
+1. TOC
+{:toc}
+
+---
 
 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:
 
@@ -14,7 +23,7 @@ Just the docs uses [lunr.js](http://lunrjs.com) to add a client-side search inte
 
 ## Set up search
 
-### 1. Generate search index
+### Generate search index
 
 Before you can use search, you must initialize the feature by running this
 rake command that comes with the `just-the-docs`
@@ -44,7 +53,7 @@ your search index. Alternatively, you can create the file manually in the
 
 _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)._
 
-### 2. Enable search in configuration
+### Enable search in configuration
 
 In your site's `_config.yml` enable search:
 
@@ -52,3 +61,18 @@ In your site's `_config.yml` enable search:
 # Enable or disable the site search
 search_enabled: true
 ```
+
+## 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 }
+```yaml
+---
+layout: default
+title: Page not found
+nav_exclude: true
+search_exclude: true
+---
+```
-- 
GitLab