Skip to content

Commit

Permalink
Merge pull request barryclark#70 from EricFromCanada/improve-search
Browse files Browse the repository at this point in the history
Improve search data generation
  • Loading branch information
pmarsceill authored Jan 23, 2019
2 parents ce947ae + 60c82cb commit 2de780b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
10 changes: 5 additions & 5 deletions assets/js/search-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
{
{% for page in site.html_pages %}{% if page.search_exclude != true %}"{{ forloop.index0 }}": {
"id": "{{ forloop.index0 }}",
"title": "{{ page.title | xml_escape }}",
"content": "{{ page.content | newline_to_br | replace: '<br />', ' ' | replace: '</h1>', ' ' | strip_newlines | markdownify | strip_html | remove: 'Table of contents' | xml_excape | escape | replace: '\', ' ' | replace: '```', '' | replace: ' ', ' ' | replace: ' ', ' ' | remove: '---' | remove: '#####' | remove: '####' | remove: '###' | remove: '##' | strip_newlines }}",
"url": "{{ page.url | absolute_url | xml_escape }}",
"relUrl": "{{ page.url | xml_escape }}"
}{% if forloop.last %}{% else %},{% endif %}
"title": "{{ page.title | replace: '&amp;', '&' }}",
"content": "{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\', ' ' | normalize_whitespace }}",
"url": "{{ page.url | absolute_url }}",
"relUrl": "{{ page.url }}"
}{% unless forloop.last %},{% endunless %}
{% endif %}{% endfor %}
}
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ nav_order: 2

# Configuration

Just the Docs has some specific configuration parameters that can be definied in your Jekyll site's `_config.yml` file.
Just the Docs has some specific configuration parameters that can be defined in your Jekyll site's `_config.yml` file.

## Search enabled

```yml
```yaml
# Enable or disable the site search
search_enabled: true
```
## Aux links
```yml
```yaml
# Aux links for the upper right navigation
aux_links:
"Just the Docs on GitHub":
Expand All @@ -26,7 +26,7 @@ aux_links:
## Color scheme
```yml
```yaml
# Color scheme currently only supports "dark" or nil (default)
color_scheme: "dark"
```
Expand Down
4 changes: 2 additions & 2 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To enable a color scheme, set the `color_scheme` parameter in your site's `_conf
#### Example
{: .no_toc }

```yml
```yaml
# Color scheme currently only supports "dark" or nil (default)
color_scheme: "dark"
```
Expand Down Expand Up @@ -68,6 +68,6 @@ $link-color: $blue-000;
// ...
```

_Note:_ Editing the variables directly in `_sass/support/variables.scss` is not recommended and can cause other dependancies to fail.
_Note:_ Editing the variables directly in `_sass/support/variables.scss` is not recommended and can cause other dependencies to fail.

---
2 changes: 1 addition & 1 deletion docs/navigation-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ To add a auxiliary navigation item to your site (in the upper right on all pages
#### Example
{: .no_toc }

```yml
```yaml
# Aux links for the upper right navigation
aux_links:
"Just the Docs on GitHub":
Expand Down
18 changes: 9 additions & 9 deletions docs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ $ bundle exec just-the-docs rake search:init

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:

```{% raw %}
---
```liquid
{% raw %}---
---
{
{% for page in site.html_pages %}"{{ forloop.index0 }}": {
{% for page in site.html_pages %}{% if page.search_exclude != true %}"{{ 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 }}"
}{% if forloop.last %}{% else %},
"title": "{{ page.title | replace: '&amp;', '&' }}",
"content": "{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\', ' ' | normalize_whitespace }}",
"url": "{{ page.url | absolute_url }}",
"relUrl": "{{ page.url }}"
}{% unless forloop.last %},{% endunless %}
{% endif %}{% endfor %}
}{% endraw %}
```
Expand All @@ -54,7 +54,7 @@ _Note: If you don't run this rake command or create this file manually, search w

In your site's `_config.yml`, enable search:

```yml
```yaml
# Enable or disable the site search
search_enabled: true
```
Expand Down
2 changes: 1 addition & 1 deletion just-the-docs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gem::Specification.new do |spec|
spec.authors = ["Patrick Marsceill"]
spec.email = ["[email protected]"]

spec.summary = %q{A nice looking, high customizable, responsive Jekyll theme for documention with built-in search.}
spec.summary = %q{A nice looking, highly customizable, responsive Jekyll theme for documentation with built-in search.}
spec.homepage = "https://github.com/pmarsceill/just-the-docs"
spec.license = "MIT"

Expand Down
12 changes: 6 additions & 6 deletions lib/tasks/search.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ namespace :search do
puts 'Creating search data json file...'
mkdir_p 'assets/js'
touch 'assets/js/search-data.json'
content = %Q[{{ page.content | markdownify | strip_html | xml_escape | remove: 'Table of contents' | strip_newlines | replace: '\\', ' ' }}]
content = %Q[{{ page.content | markdownify | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\\', ' ' | normalize_whitespace }}]
puts 'Done.'
puts 'Generating content...'

File.open('assets/js/search-data.json', 'w') do |f|
f.puts '---
---
{
{% for page in site.html_pages %}"{{ forloop.index0 }}": {
{% for page in site.html_pages %}{% if page.search_exclude != true %}"{{ forloop.index0 }}": {
"id": "{{ forloop.index0 }}",
"title": "{{ page.title | xml_escape }}",
"title": "{{ page.title | replace: '&amp;', '&' }}",
"content": "'+content+'",
"url": "{{ page.url | absolute_url | xml_escape }}",
"relUrl": "{{ page.url | xml_escape }}"
}{% if forloop.last %}{% else %},
"url": "{{ page.url | absolute_url }}",
"relUrl": "{{ page.url }}"
}{% unless forloop.last %},{% endunless %}
{% endif %}{% endfor %}
}'
end
Expand Down

0 comments on commit 2de780b

Please sign in to comment.