tipuesearch_content.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. ---
  2. # Content index for Tipue Search
  3. # https://github.com/jekylltools/jekyll-tipue-search
  4. # v1.4
  5. layout: null
  6. ---
  7. {%- assign index = "" | split: "" -%}
  8. {%- assign excluded_files = site.tipue_search.exclude.files -%}
  9. {%- assign excluded_tags = site.tipue_search.exclude.tags | uniq -%}
  10. {%- assign excluded_categories = site.tipue_search.exclude.categories | uniq -%}
  11. {%- assign excluded_taxonomies = excluded_tags | concat: excluded_categories | uniq -%}
  12. {%- for post in site.posts -%}
  13. {%- unless post.exclude_from_search == true or excluded_files contains post.path -%}
  14. {%- assign has_excluded_taxonomy = false -%}
  15. {%- for tag in post.tags -%}
  16. {%- if excluded_taxonomies contains tag -%}
  17. {%- assign has_excluded_taxonomy = true -%}
  18. {%- endif -%}
  19. {%- endfor -%}
  20. {%- for category in post.categories -%}
  21. {%- if excluded_taxonomies contains category -%}
  22. {%- assign has_excluded_taxonomy = true -%}
  23. {%- endif -%}
  24. {%- endfor -%}
  25. {%- unless has_excluded_taxonomy == true -%}
  26. {%- assign index = index | push: post | uniq -%}
  27. {%- endunless -%}
  28. {%- endunless -%}
  29. {%- endfor -%}
  30. {%- if site.tipue_search.include.pages == true -%}
  31. {%- for page in site.html_pages -%}
  32. {%- unless page.exclude_from_search == true or excluded_files contains page.path -%}
  33. {%- assign has_excluded_taxonomy = false -%}
  34. {%- for tag in page.tags -%}
  35. {%- if excluded_taxonomies contains tag -%}
  36. {%- assign has_excluded_taxonomy = true -%}
  37. {%- endif -%}
  38. {%- endfor -%}
  39. {%- for category in page.categories -%}
  40. {%- if excluded_taxonomies contains category -%}
  41. {%- assign has_excluded_taxonomy = true -%}
  42. {%- endif -%}
  43. {%- endfor -%}
  44. {%- unless has_excluded_taxonomy == true -%}
  45. {%- assign index = index | push: page | uniq -%}
  46. {%- endunless -%}
  47. {%- endunless -%}
  48. {%- endfor -%}
  49. {%- endif -%}
  50. {%- for collection in site.tipue_search.include.collections -%}
  51. {%- assign documents = site.documents | where:"collection",collection -%}
  52. {%- for document in documents -%}
  53. {%- unless document.exclude_from_search == true or excluded_files contains document.path -%}
  54. {%- assign has_excluded_taxonomy = false -%}
  55. {%- for tag in document.tags -%}
  56. {%- if excluded_taxonomies contains tag -%}
  57. {%- assign has_excluded_taxonomy = true -%}
  58. {%- endif -%}
  59. {%- endfor -%}
  60. {%- for category in document.categories -%}
  61. {%- if excluded_taxonomies contains category -%}
  62. {%- assign has_excluded_taxonomy = true -%}
  63. {%- endif -%}
  64. {%- endfor -%}
  65. {%- unless has_excluded_taxonomy == true -%}
  66. {%- assign index = index | push: document | uniq -%}
  67. {%- endunless -%}
  68. {%- endunless -%}
  69. {%- endfor -%}
  70. {%- endfor -%}
  71. var tipuesearch = {"pages": [
  72. {%- for document in index -%}
  73. {%- assign tags = document.tags | uniq -%}
  74. {%- assign categories = document.categories | uniq -%}
  75. {%- assign taxonomies = tags | concat: categories | uniq -%}
  76. {
  77. "title": {{ document.title | smartify | strip_html | normalize_whitespace | jsonify }},
  78. "text": {{ document.content | strip_html | normalize_whitespace | jsonify }},
  79. "tags": {{ taxonomies | join: " " | normalize_whitespace | jsonify }},
  80. "url": {{ document.url | relative_url | jsonify }}
  81. }{%- unless forloop.last -%},{%- endunless -%}
  82. {%- endfor -%}
  83. ]};