You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

28 lines
1.2 KiB

  1. namespace :search do
  2. desc 'Generate the files needed for search functionality'
  3. task :init do
  4. puts 'Creating search data json file...'
  5. mkdir_p 'assets/js'
  6. touch 'assets/js/search-data.json'
  7. content = %Q[{{ page.content | markdownify | replace: '</h', ' . </h' | replace: '<hr', ' . <hr' | replace: '</p', ' . </p' | replace: '</ul', ' . </ul' | replace: '</tr', ' . </tr' | replace: '</li', ' | </li' | replace: '</td', ' | </td' | strip_html | escape_once | remove: 'Table of contents' | remove: '```' | remove: '---' | replace: '\', ' ' | replace: ' . . . ', ' . ' | replace: ' . . ', ' . ' | normalize_whitespace }}]
  8. puts 'Done.'
  9. puts 'Generating content...'
  10. File.open('assets/js/search-data.json', 'w') do |f|
  11. f.puts '---
  12. ---
  13. {
  14. {% assign comma = false %}
  15. {% for page in site.html_pages %}{% if page.search_exclude != true %}{% if comma == true%},{% endif %}"{{ forloop.index0 }}": {
  16. "title": "{{ page.title | replace: '&amp;', '&' }}",
  17. "content": "'+content+'",
  18. "url": "{{ page.url | absolute_url }}",
  19. "relUrl": "{{ page.url }}"
  20. }{% assign comma = true %}
  21. {% endif %}{% endfor %}
  22. }'
  23. end
  24. puts 'Done.'
  25. end
  26. end