Sha256: 61ee4a7468fedfdc461da9aca748f0af72c346a3e3240c8f5afe3da04bcd5fa0

Contents?: true

Size: 927 Bytes

Versions: 5

Compression:

Stored size: 927 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 | 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 %}{% if page.search_exclude != true %}"{{ forloop.index0 }}": {
    "id": "{{ forloop.index0 }}",
    "title": "{{ page.title | replace: \'&\', \'&\' }}",
    "content": "'+content+'",
    "url": "{{ page.url | absolute_url }}",
    "relUrl": "{{ page.url }}"
  }{% unless forloop.last %},{% endunless %}
  {% endif %}{% endfor %}
}'
    end
    puts 'Done.'
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
just-the-docs-0.2.6 lib/tasks/search.rake
just-the-docs-0.2.5 lib/tasks/search.rake
just-the-docs-0.2.4 lib/tasks/search.rake
just-the-docs-altair-0.2.3 lib/tasks/search.rake
just-the-docs-0.2.3 lib/tasks/search.rake