選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

28 行
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