Sha256: e448810003d7daf88067466cea19fdca651ee0ae50c6c1f0557549806e8cd209

Contents?: true

Size: 853 Bytes

Versions: 4

Compression:

Stored size: 853 Bytes

Contents

namespace :search do
  desc 'Generate the files needed for search functionality'
  task :init 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: '\\', ' ' }}]
    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 }}": {
    "id": "{{ forloop.index0 }}",
    "title": "{{ page.title | xml_escape }}",
    "content": "'+content+'",
    "url": "{{ page.url | absolute_url | xml_escape }}",
    "relUrl": "{{ page.url | xml_escape }}"
  }{% if forloop.last %}{% else %},
  {% endif %}{% endfor %}
}'
    end
    puts 'Done.'
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
just-the-docs-0.2.1 lib/tasks/search.rake
just-the-docs-0.2.0 lib/tasks/search.rake
just-the-docs-0.1.6 lib/tasks/search.rake
just-the-docs-0.1.5 lib/tasks/search.rake